libvdo
vdo-map.h File Reference

A class representing a dictionary mapping keys to values. More...

#include <glib-object.h>
Include dependency graph for vdo-map.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define vdo_map_get_printf(self, type, def, len, format, ...)
 Returns a value using a printf-style format string to specify a key. More...
 
#define vdo_map_set_printf(self, type, value, len, format, ...)
 Sets a value using a printf-style format string to specify a key. More...
 

Functions

VdoMapvdo_map_new (void)
 Constructs an new empty VdoMap. More...
 
VdoMapvdo_map_new_from_variant (GVariant *dictionary)
 Constructs a new VdoMap with the same entries as the specified GVariant dictionary. More...
 
gboolean vdo_map_empty (const VdoMap *self)
 Checks if this map is empty. More...
 
gsize vdo_map_size (const VdoMap *self)
 Returns the number of entries in this map. More...
 
void vdo_map_swap (VdoMap *lhs, VdoMap *rhs)
 Swaps the contents of two maps. More...
 
gboolean vdo_map_contains (const VdoMap *self, const gchar *name)
 Checks if this map contains the specified key. More...
 
gboolean vdo_map_contains_va (const VdoMap *self,...)
 Checks if this map contains the specified set of keys. More...
 
gboolean vdo_map_contains_strv (const VdoMap *self, const gchar *const *names)
 Checks if this map contains the specified set of keys. More...
 
gboolean vdo_map_entry_equals (const VdoMap *self, const VdoMap *map, const gchar *name)
 Checks if the specified entry in this map and the specified map are equal. More...
 
gboolean vdo_map_entry_updates (const VdoMap *self, const VdoMap *map, const gchar *name)
 Checks if the specified key in the specified map is mapped to a value that differs from the one in this map. More...
 
gboolean vdo_map_equals (const VdoMap *self, const VdoMap *map)
 Checks if all entries in this map and the specified map are equal. More...
 
gboolean vdo_map_equals_va (const VdoMap *self, const VdoMap *map,...)
 Checks if all of the specified entries in this map and the specified map are equal. More...
 
gboolean vdo_map_equals_strv (const VdoMap *self, const VdoMap *map, const gchar *const *names)
 Checks if all of the specified entries in this map and the specified map are equal. More...
 
void vdo_map_remove (VdoMap *self, const gchar *name)
 Removes the entry with the specified key from this map. More...
 
void vdo_map_remove_va (VdoMap *self,...)
 Removes all entries with the specified keys from this map. More...
 
void vdo_map_remove_strv (VdoMap *self, const gchar *const *names)
 Removes all entries with the specified keys from this map. More...
 
void vdo_map_clear (VdoMap *self)
 Removes all of the entries from this map. More...
 
VdoMapvdo_map_filter_prefix (const VdoMap *self, const gchar *prefix)
 Returns a new map containing all entries from this map with a key that matches the specified prefix. More...
 
VdoMapvdo_map_filter_va (const VdoMap *self,...)
 Returns a new map containing all entries from this map with the specified keys. More...
 
VdoMapvdo_map_filter_strv (const VdoMap *self, const gchar *const *names)
 Returns a new map containing all entries from this map with the specified keys. More...
 
void vdo_map_merge (VdoMap *self, const VdoMap *map)
 Merges the specified map into this map. More...
 
void vdo_map_copy_value (VdoMap *self, const gchar *src, const gchar *dst)
 Copies the value associated with the key src to an entry with the key dst. More...
 
GVariant * vdo_map_to_variant (const VdoMap *self)
 Create a GVariant dictionary containing all entries from this map. More...
 
void vdo_map_dump (const VdoMap *self)
 Print a string representation of this map to stdout. More...
 
GVariant * vdo_map_get_variant (const VdoMap *self, const gchar *name, GVariant *def)
 Returns the value which the key name is associated with. More...
 
void vdo_map_set_boolean (VdoMap *self, const gchar *name, gboolean value)
 Sets the value associated with the specified key. More...
 

Detailed Description

A class representing a dictionary mapping keys to values.

Copyright (C) 2016-2019, Axis Communications AB, Lund

Macro Definition Documentation

◆ vdo_map_get_printf

#define vdo_map_get_printf (   self,
  type,
  def,
  len,
  format,
  ... 
)
Value:
__extension__ ({\
gchar name[len];\
g_snprintf(name, len, format, __VA_ARGS__);\
vdo_map_get_##type(self, name, def);\
})

Returns a value using a printf-style format string to specify a key.

These macros work due to a GCC extension: parentheses around a compound statement implicitly make the value of the last expression inside the block the return value of the whole block.

Parameters
selfA VdoMap.
typeThe type of the value to retrieve.
defDefault return value.
lenMaximum string length.
formatA printf-style format string to use as a key.
Returns
The value associated with the specified key, or default value.

◆ vdo_map_set_printf

#define vdo_map_set_printf (   self,
  type,
  value,
  len,
  format,
  ... 
)
Value:
{\
gchar name[len];\
g_snprintf(name, len, format, __VA_ARGS__);\
vdo_map_set_##type(self, name, value);\
}

Sets a value using a printf-style format string to specify a key.

Parameters
selfA VdoMap.
typeThe type of the value to set.
valueThe value to set.
lenMaximum string length.
formatA printf-style format string to use as a key.

Function Documentation

◆ vdo_map_clear()

void vdo_map_clear ( VdoMap self)

Removes all of the entries from this map.

Parameters
selfA VdoMap.

◆ vdo_map_contains()

gboolean vdo_map_contains ( const VdoMap self,
const gchar *  name 
)

Checks if this map contains the specified key.

Parameters
selfA VdoMap.
nameThe key to check for.
Returns
TRUE if this map contains the specified key, otherwise FALSE.

◆ vdo_map_contains_strv()

gboolean vdo_map_contains_strv ( const VdoMap self,
const gchar *const *  names 
)

Checks if this map contains the specified set of keys.

Note
This function takes a string array which must be terminated with the value NULL.
Parameters
selfA VdoMap.
namesA NULL terminated string array containing the keys to be checked for containment in this map.
Returns
TRUE if this map contains all the specified keys, otherwise FALSE.

◆ vdo_map_contains_va()

gboolean vdo_map_contains_va ( const VdoMap self,
  ... 
)

Checks if this map contains the specified set of keys.

Note
This function takes a variable length argument list which must be terminated with the value NULL.
Parameters
selfA VdoMap.
...A NULL terminated variable argument list containing the keys to be checked for containment in this map.
Returns
TRUE if this map contains all the specified keys, otherwise FALSE.

◆ vdo_map_copy_value()

void vdo_map_copy_value ( VdoMap self,
const gchar *  src,
const gchar *  dst 
)

Copies the value associated with the key src to an entry with the key dst.

If an entry with the key dst does not already exist, a new one is created. The value of the existing entry is modified otherwise.

Parameters
selfA VdoMap.
srcThe key associated with the value to copy.
dstThe key for the entry to be created/modified.

◆ vdo_map_dump()

void vdo_map_dump ( const VdoMap self)

Print a string representation of this map to stdout.

Parameters
selfA VdoMap.

◆ vdo_map_empty()

gboolean vdo_map_empty ( const VdoMap self)

Checks if this map is empty.

Parameters
selfA VdoMap.
Returns
TRUE if this map is empty, otherwise FALSE.

◆ vdo_map_entry_equals()

gboolean vdo_map_entry_equals ( const VdoMap self,
const VdoMap map,
const gchar *  name 
)

Checks if the specified entry in this map and the specified map are equal.

Parameters
selfA VdoMap.
mapA map to be checked for equality with this map.
nameThe key specifying the entry to be checked for equality.
Returns
TRUE if the values mapped to the specified key in both maps are equal, otherwise FALSE

◆ vdo_map_entry_updates()

gboolean vdo_map_entry_updates ( const VdoMap self,
const VdoMap map,
const gchar *  name 
)

Checks if the specified key in the specified map is mapped to a value that differs from the one in this map.

Parameters
selfA VdoMap.
mapA map to be checked for an updating entry.
namethe name of the map entry to check.
Returns
TRUE if map contains an updating entry for this map.

◆ vdo_map_equals()

gboolean vdo_map_equals ( const VdoMap self,
const VdoMap map 
)

Checks if all entries in this map and the specified map are equal.

Parameters
selfA VdoMap.
mapA VdoMap to compare for equality.
Returns
TRUE if all entries are equal, otherwise FALSE.

◆ vdo_map_equals_strv()

gboolean vdo_map_equals_strv ( const VdoMap self,
const VdoMap map,
const gchar *const *  names 
)

Checks if all of the specified entries in this map and the specified map are equal.

This function takes a string array which must be terminated with the value NULL.

Parameters
selfA VdoMap.
mapA map to be checked for equality with this map.
namesA NULL terminated string array containing keys to be checked for equality.
Returns
TRUE if all entries are equal, otherwise FALSE.

◆ vdo_map_equals_va()

gboolean vdo_map_equals_va ( const VdoMap self,
const VdoMap map,
  ... 
)

Checks if all of the specified entries in this map and the specified map are equal.

This function takes a variable length argument list which must be terminated with the value NULL.

Parameters
selfA VdoMap.
mapA map to be checked for equality with this map.
...A NULL terminated variable argument list containing keys to be checked for equality.
Returns
TRUE if all the specified entries are equal, otherwise FALSE

◆ vdo_map_filter_prefix()

VdoMap* vdo_map_filter_prefix ( const VdoMap self,
const gchar *  prefix 
)

Returns a new map containing all entries from this map with a key that matches the specified prefix.

Parameters
selfA VdoMap.
prefixA prefix string to use as filter.
Returns
A new map containing matching entries from self. Free with g_object_unref().

◆ vdo_map_filter_strv()

VdoMap* vdo_map_filter_strv ( const VdoMap self,
const gchar *const *  names 
)

Returns a new map containing all entries from this map with the specified keys.

This function takes a string array which must be terminated with the value NULL.

Parameters
selfA VdoMap.
namesA NULL terminated array of strings containing keys for entries to be copied to the new map.
Returns
A new map containing matching entries from self. Free with g_object_unref().

◆ vdo_map_filter_va()

VdoMap* vdo_map_filter_va ( const VdoMap self,
  ... 
)

Returns a new map containing all entries from this map with the specified keys.

This function takes a variable length argument list which must be terminated with the value NULL.

Parameters
selfA VdoMap.
...A NULL terminated variable argument list containing keys for entries to be copied to the new map.
Returns
A new map containing matching entries from self. Free with g_object_unref().

◆ vdo_map_get_variant()

GVariant* vdo_map_get_variant ( const VdoMap self,
const gchar *  name,
GVariant *  def 
)

Returns the value which the key name is associated with.

The specified default value def is returned if the specified key does not exists in this map.

Parameters
selfA VdoMap.
nameThe key associated with the value to be returned.
defDefault return value.
Returns
The value associated with the specified key, or default value.

◆ vdo_map_merge()

void vdo_map_merge ( VdoMap self,
const VdoMap map 
)

Merges the specified map into this map.

Parameters
selfA VdoMap.
mapA map to be merged into this map.

◆ vdo_map_new()

VdoMap* vdo_map_new ( void  )

Constructs an new empty VdoMap.

Returns
A VdoMap.

◆ vdo_map_new_from_variant()

VdoMap* vdo_map_new_from_variant ( GVariant *  dictionary)

Constructs a new VdoMap with the same entries as the specified GVariant dictionary.

Parameters
dictionaryA Gvariant dictionary.
Returns
A VdoMap.

◆ vdo_map_remove()

void vdo_map_remove ( VdoMap self,
const gchar *  name 
)

Removes the entry with the specified key from this map.

Parameters
selfA VdoMap.
nameThe key to remove.

◆ vdo_map_remove_strv()

void vdo_map_remove_strv ( VdoMap self,
const gchar *const *  names 
)

Removes all entries with the specified keys from this map.

This function takes a string array which must be terminated with the value NULL.

Parameters
selfA VdoMap.
namesA NULL terminated array of strings containing keys to be removed

◆ vdo_map_remove_va()

void vdo_map_remove_va ( VdoMap self,
  ... 
)

Removes all entries with the specified keys from this map.

This function takes a variable length argument list which must be terminated with the value NULL.

Parameters
selfA VdoMap.
...A NULL terminated variable argument list containing keys to be removed.

◆ vdo_map_set_boolean()

void vdo_map_set_boolean ( VdoMap self,
const gchar *  name,
gboolean  value 
)

Sets the value associated with the specified key.

If an entry with the key name does not exist in this map. a new entry will be created.

Parameters
selfA VdoMap.
nameThe key associated with the value to be set.
valueThe value to set.

◆ vdo_map_size()

gsize vdo_map_size ( const VdoMap self)

Returns the number of entries in this map.

Parameters
selfA VdoMap.
Returns
The number of entries in this map.

◆ vdo_map_swap()

void vdo_map_swap ( VdoMap lhs,
VdoMap rhs 
)

Swaps the contents of two maps.

Parameters
lhsA VdoMap to swap with rhs.
rhsA VdoMap to swap with lhs.

◆ vdo_map_to_variant()

GVariant* vdo_map_to_variant ( const VdoMap self)

Create a GVariant dictionary containing all entries from this map.

Parameters
selfA VdoMap.
Returns
A GVariant dictionary. Free with g_variant_unref().