GSignondDictionary

GSignondDictionary — a dictionary container holding string keys and variant values

Synopsis

#include <gsignond/gsignond-dictionary.h>

typedef             GSignondDictionary;
GSignondDictionary * gsignond_dictionary_copy           (GSignondDictionary *other);
GVariant *          gsignond_dictionary_get             (GSignondDictionary *dict,
                                                         const gchar *key);
gboolean            gsignond_dictionary_get_boolean     (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gboolean *value);
gboolean            gsignond_dictionary_get_int32       (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gint *value);
gboolean            gsignond_dictionary_get_int64       (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gint64 *value);
const gchar *       gsignond_dictionary_get_string      (GSignondDictionary *dict,
                                                         const gchar *key);
gboolean            gsignond_dictionary_get_uint32      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         guint *value);
gboolean            gsignond_dictionary_get_uint64      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         guint64 *value);
GSignondDictionary * gsignond_dictionary_new            (void);
GSignondDictionary * gsignond_dictionary_new_from_variant
                                                        (GVariant *variant);
GSignondDictionary * gsignond_dictionary_ref            (GSignondDictionary *dict);
gboolean            gsignond_dictionary_remove          (GSignondDictionary *dict,
                                                         const gchar *key);
gboolean            gsignond_dictionary_set             (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         GVariant *value);
gboolean            gsignond_dictionary_set_boolean     (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gboolean value);
gboolean            gsignond_dictionary_set_int32       (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gint value);
gboolean            gsignond_dictionary_set_int64       (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gint64 value);
gboolean            gsignond_dictionary_set_string      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         const gchar *value);
gboolean            gsignond_dictionary_set_uint32      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         guint32 value);
gboolean            gsignond_dictionary_set_uint64      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         guint64 value);
GVariant *          gsignond_dictionary_to_variant      (GSignondDictionary *dict);
void                gsignond_dictionary_unref           (GSignondDictionary *dict);

Description

A GSignondDictionary is a dictionary data structure that maps string keys to GVariant values. It's used in multiple places in gsignond and its public API to pass key-value data sets.

1
2
3
4
5
6
7
8
GSignondDictionary* dict = gsignond_dictionary_new();
    gsignond_dictionary_set_string(dict, "name", "John Smith");
    gsignond_dictionary_set_uint32(dict, "age", 32);

    guint32 age;
    gboolean success = gsignond_dictionary_get_uint32(dict, "age", &age);
    const gchar* name = gsignond_dictionary_get_string(dict, "name");
    gsignond_dictionary_unref(dict);

Details

GSignondDictionary

typedef GHashTable GSignondDictionary;

GSignondDictionary is a typedef for GHashTable, which means the developers may also use methods associated with that structure.


gsignond_dictionary_copy ()

GSignondDictionary * gsignond_dictionary_copy           (GSignondDictionary *other);

Creates a copy of the dictionary.

other :

instance of GSignondDictionary

Returns :

GSignondDictionary object if the copy was successful, NULL otherwise. [transfer full]

gsignond_dictionary_get ()

GVariant *          gsignond_dictionary_get             (GSignondDictionary *dict,
                                                         const gchar *key);

Retrieves a GVariant value from the dictionary. This can be used to retrieve a value of an arbitrary type, and then convert it manually to a specific type using GVariant methods. For most commonly used types, also getters that return the specific type directly are provided (gsignond_dictionary_get_string() and similar).

dict :

instance of GSignondDictionary

key :

the key to look up in the dictionary

Returns :

the value; NULL is returned in case of failure (for example if the entry corresponding to the supplied key doesn't exist). [transfer none]

gsignond_dictionary_get_boolean ()

gboolean            gsignond_dictionary_get_boolean     (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gboolean *value);

Retrieves a gboolean value.

dict :

instance of GSignondDictionary

key :

key to look up. [transfer none]

value :

points to the location where the value should be set

Returns :

TRUE if the value was retrieved successfully, FALSE otherwise.

gsignond_dictionary_get_int32 ()

gboolean            gsignond_dictionary_get_int32       (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gint *value);

Retrieves a int32 value.

dict :

instance of GSignondDictionary

key :

key to look up. [transfer none]

value :

points to the location where the value should be set

Returns :

TRUE if the value was retrieved successfully, FALSE otherwise.

gsignond_dictionary_get_int64 ()

gboolean            gsignond_dictionary_get_int64       (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gint64 *value);

Retrieves a int64 value.

dict :

instance of GSignondDictionary

key :

key to look up. [transfer none]

value :

points to the location where the value should be set

Returns :

TRUE if the value was retrieved successfully, FALSE otherwise.

gsignond_dictionary_get_string ()

const gchar *       gsignond_dictionary_get_string      (GSignondDictionary *dict,
                                                         const gchar *key);

Retrieves a string value.

dict :

instance of GSignondDictionary

key :

key to look up. [transfer none]

Returns :

the value if it was retrieved successfully, NULL otherwise. [transfer none]

gsignond_dictionary_get_uint32 ()

gboolean            gsignond_dictionary_get_uint32      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         guint *value);

Retrieves a uint32 value.

dict :

instance of GSignondDictionary

key :

key to look up. [transfer none]

value :

points to the location where the value should be set

Returns :

TRUE if the value was retrieved successfully, FALSE otherwise.

gsignond_dictionary_get_uint64 ()

gboolean            gsignond_dictionary_get_uint64      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         guint64 *value);

Retrieves a uint64 value.

dict :

instance of GSignondDictionary

key :

key to look up. [transfer none]

value :

points to the location where the value should be set

Returns :

TRUE if the value was retrieved successfully, FALSE otherwise.

gsignond_dictionary_new ()

GSignondDictionary * gsignond_dictionary_new            (void);

Creates a new instance of GSignondDictionary.

Returns :

GSignondDictionary object if successful, NULL otherwise. [transfer full]

gsignond_dictionary_new_from_variant ()

GSignondDictionary * gsignond_dictionary_new_from_variant
                                                        (GVariant *variant);

Converts the GVariant to GSignondDictionary. This is useful for example if the dictionary needs to be deserialized, or if it's contained in another GSignondDictionary and has been retrieved using gsignond_dictionary_get().

variant :

instance of GVariant

Returns :

GSignondDictionary if successful, NULL otherwise. [transfer full]

gsignond_dictionary_ref ()

GSignondDictionary * gsignond_dictionary_ref            (GSignondDictionary *dict);

Increments the reference count of the dictionary structure.

dict :

instance of GSignondDictionary

Returns :

the pointer to the passed in GSignondDictionary

gsignond_dictionary_remove ()

gboolean            gsignond_dictionary_remove          (GSignondDictionary *dict,
                                                         const gchar *key);

Removes key-value pair in the dictionary as per key.

dict :

instance of GSignondDictionary

key :

key which needs to be removed from the dictionary. [transfer none]

Returns :

TRUE if successful, FALSE otherwise.

gsignond_dictionary_set ()

gboolean            gsignond_dictionary_set             (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         GVariant *value);

Adds or replaces key-value pair in the dictionary. This allows to set a value of an arbitrary type: it first needs to be converted to a GVariant. For most commonly used types also type-specific setters are provided.

dict :

instance of GSignondDictionary

key :

key to be set. [transfer none]

value :

value to be set. [transfer full]

Returns :

TRUE if successful, FALSE otherwise.

gsignond_dictionary_set_boolean ()

gboolean            gsignond_dictionary_set_boolean     (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gboolean value);

Sets or replaces a gboolean value in the dictionary.

dict :

instance of GSignondDictionary

key :

key to set. [transfer none]

value :

value to set

Returns :

TRUE if the value was set or replaced successfully, FALSE otherwise.

gsignond_dictionary_set_int32 ()

gboolean            gsignond_dictionary_set_int32       (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gint value);

Sets or replaces a int32 value in the dictionary.

dict :

instance of GSignondDictionary

key :

key to set. [transfer none]

value :

value to set

Returns :

TRUE if the value was set or replaced successfully, FALSE otherwise.

gsignond_dictionary_set_int64 ()

gboolean            gsignond_dictionary_set_int64       (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         gint64 value);

Sets or replaces a int64 value in the dictionary.

dict :

instance of GSignondDictionary

key :

key to set. [transfer none]

value :

value to set

Returns :

TRUE if the value was set or replaced successfully, FALSE otherwise.

gsignond_dictionary_set_string ()

gboolean            gsignond_dictionary_set_string      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         const gchar *value);

Sets or replaces a string value in the dictionary.

dict :

instance of GSignondDictionary

key :

key to set. [transfer none]

value :

value to set. [transfer none]

Returns :

TRUE if the value was set or replaced successfully, FALSE otherwise.

gsignond_dictionary_set_uint32 ()

gboolean            gsignond_dictionary_set_uint32      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         guint32 value);

Sets or replaces a uint32 value in the dictionary.

dict :

instance of GSignondDictionary

key :

key to set. [transfer none]

value :

value to set

Returns :

TRUE if the value was set or replaced successfully, FALSE otherwise.

gsignond_dictionary_set_uint64 ()

gboolean            gsignond_dictionary_set_uint64      (GSignondDictionary *dict,
                                                         const gchar *key,
                                                         guint64 value);

Sets or replaces a uint64 value in the dictionary.

dict :

instance of GSignondDictionary

key :

key to set. [transfer none]

value :

value to set

Returns :

TRUE if the value was set or replaced successfully, FALSE otherwise.

gsignond_dictionary_to_variant ()

GVariant *          gsignond_dictionary_to_variant      (GSignondDictionary *dict);

Converts the GSignondDictionary to a GVariant. The result can be serialized or put into another GSignondDictionary using gsignond_dictionary_set().

dict :

instance of GSignondDictionary

Returns :

GVariant object if successful, NULL otherwise. [transfer full]

gsignond_dictionary_unref ()

void                gsignond_dictionary_unref           (GSignondDictionary *dict);

Decrements the reference count of the dictionary structure. If the reference count reaches zero, the structure is deallocated and shouldn't be used.

dict :

instance of GSignondDictionary