edelib 2.1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | List of all members
EdbusDict Class Reference
D-Bus classes and functions

Dictionary container for D-Bus types. More...

`#include <edelib/EdbusDict.h>`

Inheritance diagram for EdbusDict:

## Public Types
typedef EdbusContainer< EdbusDictEntry >::const_iterator | const_iterator
Public Types inherited from EdbusContainer< EdbusDictEntry >
typedef list< EdbusDictEntry >::iterator | iterator
typedef list< 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

## Additional Inherited Members
Protected Member Functions inherited from EdbusContainer< EdbusDictEntry >
void | dispose (void)
void | unhook (void)
| EdbusContainer ()
| EdbusContainer (const EdbusContainer &other)
| ~EdbusContainer ()
EdbusContainer & | operator= (const EdbusContainer &other)
Protected Attributes inherited from EdbusContainer< EdbusDictEntry >
EdbusContainerPrivate * | impl

## Detailed Description

Dictionary container for D-Bus types.

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.

Note
  Adding (or updating) pairs (via append()) is not efficient like in e.g. STL map; it is more or less linear operation assuring uniqueness; D-Bus protocol can tolerate, but not prefer duplicate keys in dictionary. Dict's in D-Bus are often used to contain a small number of elements so this is not a big deal :)

Class use implicit sharing.

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 (

See also
  Edbus::basic_type()).

If you try to add non-basic D-Bus type as key, it will be ignored.

Todo:
  This should be assertion

Each instance of EdbusDict object will have the same types for the keys and the same types for the values. This means that if you add in freshly created EdbusDict object a key as int32_t and value as string, all further adding is expecting that types too. On other hand, if you try to add a key with different type (in dict that already have few keys with e.g. int32_t), entry (key and value) will be ignored.

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.

See also
  EdbusDictIterator Iterator points to the EdbusDictEntry which have two members, each EdbusData type. This means that you should use is_ members to check key and value types.

This is a sample of listing dict content, without type checks:

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;
}

## Member Typedef Documentation

typedef EdbusContainer<EdbusDictEntry>::const_iterator const_iterator

Declares EdbusDict iterator

## Member Function Documentation

void append | ( | const EdbusData & | key,
|  | const EdbusData & | value
| ) |  |

Assign value with the key and add it. If key already exists, previous value will be overriden with the new one.

Parameters

  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

EdbusData find | ( | const EdbusData & | key | ) |

Find and retrieve value associated with this key. If value is not found, it will retrieve invalid EdbusData type (EDBUS_TYPE_INVALID).

See also
  EdbusData

Returns
  associated value or invalid type

Parameters

  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

Parameters

  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 |  | ) |

Return true if value type is container (EdbusDict or EdbusList)

The documentation for this class was generated from the following file:

- edelib/EdbusDict.h