glibmm: Glib::VariantDict Class Reference

VariantDict is a mutable interface to Variant dictionaries. More...

#include <glibmm/variantdict.h>

Public Member Functions

void reference () const
 Increment the reference count for this object. More...

 
void unreference () const
 Decrement the reference count for this object. More...

 
GVariantDict* gobj ()
 Provides access to the underlying C instance. More...

 
const GVariantDict* gobj () const
 Provides access to the underlying C instance. More...

 
GVariantDict* gobj_copy () const
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...

 
 VariantDict ()=delete
 
 VariantDict (const VariantDict&)=delete
 
VariantDictoperator= (const VariantDict&)=delete
 
bool lookup_value_variant (const Glib::ustring& key, const VariantType& expected_type, VariantBase& value) const
 Looks up a value in the VariantDict. More...

 
template<typename T_Value >
bool lookup_value (const Glib::ustring& key, T_Value& value) const
 Looks up a value in the VariantDict. More...

 
bool contains (const Glib::ustring& key) const
 Checks if key exists in dict. More...

 
void insert_value_variant (const Glib::ustring& key, const VariantBase& value)
 Inserts (or replaces) a key in a VariantDict. More...

 
template<typename T_Value >
void insert_value (const Glib::ustring& key, const T_Value& value)
 Inserts (or replaces) a key in a VariantDict. More...

 
bool remove (const Glib::ustring& key)
 Removes a key and its associated value from a VariantDict. More...

 
void clear ()
 Releases all memory associated with a VariantDict without freeing the VariantDict structure itself. More...

 

Static Public Member Functions

static Glib::RefPtr< VariantDictcreate (const VariantBase& from_asv)
 Allocates and initialises a new VariantDict. More...

 
static Glib::RefPtr< VariantDictcreate ()
 A create() convenience overload. More...

 

Protected Member Functions

void operator delete (void*, std::size_t)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Glib::VariantDictwrap (GVariantDict* object, bool take_copy=false)
 A Glib::wrap() method for this object. More...

 

Detailed Description

VariantDict is a mutable interface to Variant dictionaries.

It can be used for doing a sequence of dictionary lookups in an efficient way on an existing Variant dictionary or it can be used to construct new dictionaries with a hashtable-like interface. It can also be used for taking existing dictionaries and modifying them in order to create new ones.

newin{2,40}

Constructor & Destructor Documentation

Glib::VariantDict::VariantDict ( )
delete
Glib::VariantDict::VariantDict ( const VariantDict )
delete

Member Function Documentation

void Glib::VariantDict::clear ( )

Releases all memory associated with a VariantDict without freeing the VariantDict structure itself.

It typically only makes sense to do this on a stack-allocated VariantDict if you want to abort building the value part-way through. This function need not be called if you call g_variant_dict_end() and it also doesn't need to be called on dicts allocated with g_variant_dict_new (see g_variant_dict_unref() for that).

It is valid to call this function on either an initialised VariantDict or one that was previously cleared by an earlier call to g_variant_dict_clear() but it is not valid to call this function on uninitialised memory.

Since glibmm 2.40:
bool Glib::VariantDict::contains ( const Glib::ustring key) const

Checks if key exists in dict.

Since glibmm 2.40:
Parameters
keyThe key to look up in the dictionary.
Returns
true if key is in dict.
static Glib::RefPtr<VariantDict> Glib::VariantDict::create ( const VariantBase from_asv)
static

Allocates and initialises a new VariantDict.

You should call g_variant_dict_unref() on the return value when it is no longer needed. The memory will not be automatically freed by any other call.

In some cases it may be easier to place a VariantDict directly on the stack of the calling function and initialise it with g_variant_dict_init(). This is particularly useful when you are using VariantDict to construct a Variant.

Since glibmm 2.40:
Parameters
from_asvThe Variant with which to initialise the dictionary.
Returns
A VariantDict.
static Glib::RefPtr<VariantDict> Glib::VariantDict::create ( )
static

A create() convenience overload.

GVariantDict* Glib::VariantDict::gobj ( )

Provides access to the underlying C instance.

const GVariantDict* Glib::VariantDict::gobj ( ) const

Provides access to the underlying C instance.

GVariantDict* Glib::VariantDict::gobj_copy ( ) const

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

template <typename T_Value >
void Glib::VariantDict::insert_value ( const Glib::ustring key,
const T_Value &  value 
)

Inserts (or replaces) a key in a VariantDict.

Parameters
keyThe key to insert a value for.
valueThe value to insert.
void Glib::VariantDict::insert_value_variant ( const Glib::ustring key,
const VariantBase value 
)

Inserts (or replaces) a key in a VariantDict.

value is consumed if it is floating.

Since glibmm 2.40:
Parameters
keyThe key to insert a value for.
valueThe value to insert.
template <typename T_Value >
bool Glib::VariantDict::lookup_value ( const Glib::ustring key,
T_Value &  value 
) const

Looks up a value in the VariantDict.

If the key is not found the false is returned.

If the value associated with key has a different type than expected then false is returned.

If the key is found and the value has the correct type, it is returned in the value output variable.

bool Glib::VariantDict::lookup_value_variant ( const Glib::ustring key,
const VariantType expected_type,
VariantBase value 
) const

Looks up a value in the VariantDict.

See also lookup_value().

If the key is not found the false is returned.

The expected_type string specifies what type of value is expected. If the value associated with key has a different type then false is returned.

If the key is found and the value has the correct type, it is returned in the value output variable.

void Glib::VariantDict::operator delete ( void *  ,
std::size_t   
)
protected
VariantDict& Glib::VariantDict::operator= ( const VariantDict )
delete
void Glib::VariantDict::reference ( ) const

Increment the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

bool Glib::VariantDict::remove ( const Glib::ustring key)

Removes a key and its associated value from a VariantDict.

Since glibmm 2.40:
Parameters
keyThe key to remove.
Returns
true if the key was found and removed.
void Glib::VariantDict::unreference ( ) const

Decrement the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

Friends And Related Function Documentation

Glib::RefPtr< Glib::VariantDict > wrap ( GVariantDict *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.