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

glibmm 2.66.3

Public Types | Public Member Functions | List of all members
Glib::Container_Helpers::GListKeeper< Tr > Class Template Reference

A keeper class for GList. More...

`#include <glibmm/vectorutils.h>`

## Public Types
using | CppType = typename Tr::CppType
using | CType = typename Tr::CType

## Public Member Functions
| GListKeeper (const GList * glist, Glib::OwnershipType ownership)
| Constructs an GListKeeper holding glist. More...
| GListKeeper (const GListKeeper & keeper)
| ~GListKeeper () noexcept
GList * | data () const
| Gets data the keeper holds. More...

## Detailed Description

### template<typename Tr>
class Glib::Container_Helpers::GListKeeper< Tr >

A keeper class for GList.

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::GListKeeper is getting its data when converting std::vector to a GList*:

void G::Temp::do_something(const std::vector<int>& v)
{
g_temp_do_something(gobj(), Glib::ListHandler<int>::vector_to_list(v).data());
}
std::vector
Glib::Container_Helpers::GListKeeper::data
GList * data() const
Gets data the keeper holds.
Glib::ListHandler
A utility for converting between std::vector and GList.
Definition: vectorutils.h:530

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

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

## ◆ CppType

template <typename Tr >

using Glib::Container_Helpers::GListKeeper< Tr >::CppType = typename Tr::CppType

## ◆ CType

template <typename Tr >

using Glib::Container_Helpers::GListKeeper< Tr >::CType = typename Tr::CType

## Constructor & Destructor Documentation

## ◆ GListKeeper() [1/2]

template <typename Tr >

Glib::Container_Helpers::GListKeeper< Tr >::GListKeeper | ( | const GList * | glist,
|  | Glib::OwnershipType | ownership
| ) |  |
| inlineexplicit

Constructs an GListKeeper holding glist.

ownership tells what should be destroyed with keeper destruction:

- Glib::OWNERSHIP_NONE - keeper won't destroy data it holds.
- Glib::OWNERSHIP_SHALLOW - keeper will destroy only container it holds.
- Glib::OWNERSHIP_DEEP - keeper will destroy data and container it holds.

Parameters

  glist | - GList* to hold.
  ownership | - ownership definition.

## ◆ GListKeeper() [2/2]

template <typename Tr >

Glib::Container_Helpers::GListKeeper< Tr >::GListKeeper | ( | const GListKeeper< Tr > & | keeper | ) |
| inline

## ◆ ~GListKeeper()

template <typename Tr >

Glib::Container_Helpers::GListKeeper< Tr >::~GListKeeper | ( |  | ) |
| noexcept

## Member Function Documentation

## ◆ data()

template <typename Tr >

GList* Glib::Container_Helpers::GListKeeper< 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
  GList* owned by GListKeeper.