glibmm: Glib::Container_Helpers::GSListKeeper< Tr > Class Template Reference

A keeper class for GSList. More...

#include <glibmm/vectorutils.h>

Public Types

using CppType = typename Tr::CppType
 
using CType = typename Tr::CType
 

Public Member Functions

 GSListKeeper (const GSList* gslist, Glib::OwnershipType ownership)
 Constructs an GSListKeeper holding gslist. More...

 
 GSListKeeper (const GSListKeeper& keeper)
 
 ~GSListKeeper () noexcept
 
GSList* data () const
 Gets data the keeper holds. More...

 

Detailed Description

template<typename Tr>

class Glib::Container_Helpers::GSListKeeper< Tr >

A keeper class for GSList.

Primarily used by C++ wrappers like gtkmm.

Its main purpose is to free its data when they are not needed. What will be destroyed depends on passed ownership upon construction.

The most common usage of Glib::GSListKeeper is getting its data when converting std::vector to a GSList*:

void G::Temp::do_something(const std::vector<int>& v)
{
g_temp_do_something(gobj(), Glib::SListHandler<int>::vector_to_slist(v).data());
}

Variables of this class are seldom defined directly - it is mostly used as a temporary variable returned by Glib::SListHandler::vector_to_slist().

Note that the usage above is correct with regards to C++ standard point 12.2.3. That means that data returned by data() method is valid through whole g_temp_do_something function and is destroyed, when this function returns.

Member Typedef Documentation

template <typename Tr >
using Glib::Container_Helpers::GSListKeeper< Tr >::CppType = typename Tr::CppType
template <typename Tr >
using Glib::Container_Helpers::GSListKeeper< Tr >::CType = typename Tr::CType

Constructor & Destructor Documentation

template <typename Tr >
Glib::Container_Helpers::GSListKeeper< Tr >::GSListKeeper ( const GSList *  gslist,
Glib::OwnershipType  ownership 
)
inlineexplicit

Constructs an GSListKeeper holding gslist.

ownership tells what should be destroyed with keeper destruction:

Parameters
gslist- GList* to hold.
ownership- ownership definition.
template <typename Tr >
Glib::Container_Helpers::GSListKeeper< Tr >::GSListKeeper ( const GSListKeeper< Tr >&  keeper)
inline
template <typename Tr >
Glib::Container_Helpers::GSListKeeper< Tr >::~GSListKeeper ( )
noexcept

Member Function Documentation

template <typename Tr >
GSList* Glib::Container_Helpers::GSListKeeper< Tr >::data ( ) const
inline

Gets data the keeper holds.

Note that this data is owned by the keeper, so there is no need to free it.

Returns
GSList* owned by GSListKeeper.