#include <edelib/EdbusDict.h>
Public Types | |
typedef EdbusContainer < EdbusDictEntry > ::const_iterator | const_iterator |
Public Member Functions | |
void | append (const EdbusData &key, const EdbusData &value) |
void | clear (void) |
void | remove (const EdbusData &key) |
EdbusData | find (const EdbusData &key) |
bool | operator== (const EdbusDict &other) |
bool | operator!= (const EdbusDict &other) |
EdbusDataType | key_type (void) |
EdbusDataType | value_type (void) |
bool | value_type_is_container (void) |
const_iterator | begin (void) const |
const_iterator | end (void) const |
unsigned int | size (void) const |
EdbusDict is a dictionary container (or map in STL). Data is stored in key//value pairs so data search and fetching is done via it's key association.
Stored data will be unique by key: if you add key//value pair and later add another pair with already added key (or to use better term: assign a new value with aleady known key), previous value will be overriden.
EdbusDict uses EdbusData as base type which means you can put any type EdbusData can hold as value. On other hand, D-Bus specification restricts key types to be only basic D-Bus types (
This will summarize the thing:
EdbusDict d; d.append(EdbusData::to_string("foo"), EdbusData::to_int32(4)); // now d will accept only keys of type string and values of type int32_t // ok, it will be added d.append(EdbusData::to_string("baz"), EdbusData::to_int32(5)); // not ok, values are different type; it will not be added d.append(EdbusData::to_string("baz"), EdbusData::to_bool(true));
Besides using find() to get a content, you can use iterator too
EdbusDict d; d.append("foo", 4); d.append("baz", 12); EdbusDict::const_iterator it = d.begin(), it_end = d.end(); while(it != it_end) { printf("key: %s value: %i\n", (*it).key.to_string(), (*it).value.to_int32()); ++it; }
Declares EdbusDict iterator
Reimplemented from EdbusContainer< EdbusDictEntry >.
Assign value with the key and add it. If key already exists, previous value will be overriden with the new one.
key | is key in basic D-Bus type | |
value | is any value EdbusData can hold |
const_iterator begin | ( | void | ) | const |
Returns iterator at the dict start. It points to the first element
void clear | ( | void | ) |
Clear content
const_iterator end | ( | void | ) | const |
Returns iterator at the dict end. It does not points to the last element, but element after the last, and you must not dereferce it
Find and retrieve value associated with this key. If value is not found, it will retrieve invalid EdbusData type (
key | is key//value pair to be searched |
EdbusDataType key_type | ( | void | ) |
Returns type of keys stored in dict
bool operator!= | ( | const EdbusDict & | other | ) | [inline] |
Compares if two dicts are not equal
bool operator== | ( | const EdbusDict & | other | ) |
Compares if two dicts are equal
void remove | ( | const EdbusData & | key | ) |
Remove value and key for the dict. If key is not found, it will do nothing
key | is key to be removed with it's value |
unsigned int size | ( | void | ) | const |
Returns size of dict content. This is a constant operation
EdbusDataType value_type | ( | void | ) |
Returns type of values stored in dict
bool value_type_is_container | ( | void | ) |