edelib
2.1.0
|
A class representing D-Bus struct and array. More...
#include <edelib/EdbusList.h>
Public Types | |
typedef EdbusContainer < EdbusData >::const_iterator | const_iterator |
Public Types inherited from EdbusContainer< EdbusData > | |
typedef list< EdbusData >::iterator | iterator |
typedef list< EdbusData > ::const_iterator | const_iterator |
Public Member Functions | |
EdbusList (bool a) | |
void | append (const EdbusData &val) |
void | clear (void) |
void | remove (const EdbusData &val) |
void | remove_all (const EdbusData &val) |
bool | operator== (const EdbusList &other) const |
bool | operator!= (const EdbusList &other) const |
EdbusDataType | value_type (void) |
bool | value_type_is_container (void) |
bool | list_is_array (void) const |
bool | list_is_struct (void) const |
const_iterator | begin (void) const |
const_iterator | end (void) const |
unsigned int | size (void) const |
Static Public Member Functions | |
static EdbusList | create_array (void) |
static EdbusList | create_struct (void) |
Additional Inherited Members | |
Protected Member Functions inherited from EdbusContainer< EdbusData > | |
void | dispose (void) |
void | unhook (void) |
EdbusContainer () | |
EdbusContainer (const EdbusContainer &other) | |
~EdbusContainer () | |
EdbusContainer & | operator= (const EdbusContainer &other) |
Protected Attributes inherited from EdbusContainer< EdbusData > | |
EdbusContainerPrivate * | impl |
A class representing D-Bus struct and array.
EdbusList is used to implement D-Bus struct and array concept. Althought EdbusList is much more list-like container (indeed, it uses list for storage), accessing elements is done via iterators which, at some point, is similar to accessing elements to ordinary arrays via pointers (if EdbusList is in array mode).
At first look EdbusList sees array and struct at the same way. This is true, at some point, but there is major difference (as in C++ language): arrays can hold only elements of the same type, but structs can hold elements of any type.
This sounds little bit strange, especially knowing that EdbusList element is EdbusData type, but if you look at EdbusData more as proxy for D-Bus types than as concrete type, things will be little bit clearer. This will be much better explained in few examples below.
So, from previous text, EdbusList object can be either array-like or struct-like. This is done via constructor.
When EdbusList object behaves as array, it will assure all elements are the same type so if you try to add via append() element of different type, it will be ignored.
When EdbusList object behaves as struct, elements of any type can be added.
The best way to create EdbusList array object is to use EdbusList::create_array(); it will call EdbusList constructor with correct parameters. The same applies for struct, use EdbusList::create_struct().
Let say you want to prepare some array for sending via bus. This is the way:
Since operator<<() is shorcut for append(), you can use append() instead too.
Now, let say you want to send some struct via bus. Sample:
If EdbusList object is created as array and you add first element, all further elements should be the same type as first element or they will not be added, like:
Some things can look like correct C++ statement, but due D-Bus signatures they are not, like:
For more details,
On other hand, if elements of array is EdbusVariant typs, array can hold different types due EdbusVariant nature. You can look at this as case when you have ordinary C++ array of variant-like objects.
EdbusList uses implicit sharing.
typedef EdbusContainer<EdbusData>::const_iterator const_iterator |
Declares EdbusList iterator
|
explicit |
Create empty container
a | if true, container will be array type, else it will be struct type |
void append | ( | const EdbusData & | val | ) |
Adds element to the end of the container
Referenced by edelib::operator<<().
const_iterator begin | ( | void | ) | const |
Returns iterator at the container start. It points to the first element
void clear | ( | void | ) |
Clears content of container
|
inlinestatic |
Explicitly create array. This function should be used to create arrays
|
inlinestatic |
Explicitly create struct. This function should be used to create structs
const_iterator end | ( | void | ) | const |
Returns iterator at the container end. It does not points to the last element, but element after the last, and you must not dereferce it
|
inline |
Returns true if object behaves as array
|
inline |
Returns true if object behaves as struct
|
inline |
Compares if two arrays or structs are not equal
bool operator== | ( | const EdbusList & | other | ) | const |
Compares if two arrays or structs are equal
void remove | ( | const EdbusData & | val | ) |
Remove element from container, if element is found
void remove_all | ( | const EdbusData & | val | ) |
Remove all elements that are equal to the val
unsigned int size | ( | void | ) | const |
Returns size of container content. This is a constant operation
EdbusDataType value_type | ( | void | ) |
Returns type of values stored in container. Only valid if container is array; if not, EDBUS_TYPE_INVALID will be returned
bool value_type_is_container | ( | void | ) |