glibmm 2.66.10

Public Types | Static Public Member Functions | List of all members
Glib::ArrayHandler< T, Tr > Class Template Reference

A utility for converting between std::vector and plain C arrays. More...

`#include <glibmm/vectorutils.h>`

## Public Types
using | CType = typename Tr::CType
using | CppType = T
using | VectorType = std::vector<CppType>
using | ArrayKeeperType = typename Glib::Container_Helpers::ArrayKeeper<Tr>
using | ArrayIteratorType = typename Glib::Container_Helpers::ArrayIterator<Tr>

## Static Public Member Functions
static VectorType | array_to_vector (const CType * array, std::size_t array_size, Glib::OwnershipType ownership)
static VectorType | array_to_vector (const CType * array, Glib::OwnershipType ownership)
static ArrayKeeperType | vector_to_array (const VectorType & vector)

## Detailed Description

template<typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>
class Glib::ArrayHandler< T, Tr >

A utility for converting between std::vector and plain C arrays.

This would normally only be used by glibmm or gtkmm itself, or similar libraries that wrap C APIs.

For instance:

std::vector<Glib::ustring> PixbufFormat::get_mime_types() const
{
return
Glib::ArrayHandler<Glib::ustring>::array_to_vector(gdk_pixbuf_format_get_mime_types(const_cast<GdkPixbufFormat*>(gobj())),
Glib::OWNERSHIP_DEEP);
}
std::vector
Glib::ArrayHandler::array_to_vector
static VectorType array_to_vector(const CType *array, std::size_t array_size, Glib::OwnershipType ownership)
Glib::OWNERSHIP_DEEP
@ OWNERSHIP_DEEP
Definition containerhandle_shared.h:53

or

void Display::store_clipboard(const Glib::RefPtr<Gdk::Window>& clipboard_window, guint32 time_,
const std::vector<Glib::ustring>& targets)
{
if (!targets.size ())
{
gdk_display_store_clipboard(gobj(),
Glib::unwrap (clipboard_window),
time_,
Glib::ArrayHandler<Glib::ustring,
AtomUstringTraits>::vector_to_array(targets).data (),
targets.size ());
}
}
std::vector::size
constexpr size_type size() const noexcept
Glib::ArrayHandler
A utility for converting between std::vector and plain C arrays.
Definition vectorutils.h:467
Glib::ArrayHandler::vector_to_array
static ArrayKeeperType vector_to_array(const VectorType &vector)
Glib::RefPtr
RefPtr<> is a reference-counting shared smartpointer.
Definition refptr.h:52
Glib::ustring
Glib::ustring has much the same interface as std::string, but contains Unicode characters encoded as ...
Definition ustring.h:327
Glib::unwrap
T::BaseObjectType * unwrap(T *ptr)
Get the underlying C instance from the C++ instance.
Definition wrap.h:124

Note that usage below is wrong - data() returns a pointer to data owned by a temporary ArrayKeeper returned by vector_to_array(), which is destroyed at the end of this instruction. For details, see Glib::ArrayKeeper.

const char** array = Glib::ArrayHandler<Glib::ustring>::vector_to_array(vec).data ();

## Member Typedef Documentation

## ◆ ArrayIteratorType

template <typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>

using Glib::ArrayHandler< T, Tr >::ArrayIteratorType = typename Glib::Container_Helpers::ArrayIterator<Tr>

## ◆ ArrayKeeperType

template <typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>

using Glib::ArrayHandler< T, Tr >::ArrayKeeperType = typename Glib::Container_Helpers::ArrayKeeper<Tr>

## ◆ CppType

template <typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>

using Glib::ArrayHandler< T, Tr >::CppType = T

## ◆ CType

template <typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>

using Glib::ArrayHandler< T, Tr >::CType = typename Tr::CType

## ◆ VectorType

template <typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>

using Glib::ArrayHandler< T, Tr >::VectorType = std::vector<CppType>

## Member Function Documentation

## ◆ array_to_vector() [1/2]

template <typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>

VectorType Glib::ArrayHandler< T, Tr >::array_to_vector | ( | const CType * | array,
|  | Glib::OwnershipType | ownership )
| static

## ◆ array_to_vector() [2/2]

template <typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>

VectorType Glib::ArrayHandler< T, Tr >::array_to_vector | ( | const CType * | array,
|  | std::size_t | array_size,
|  | Glib::OwnershipType | ownership )
| static

## ◆ vector_to_array()

template <typename T, typename Tr = Glib::Container_Helpers::TypeTraits<T>>

ArrayKeeperType Glib::ArrayHandler< T, Tr >::vector_to_array | ( | const VectorType & | vector | ) |
| static