edelib 2.1.0

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

- Class List
- Class Hierarchy
- Class Members

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

A class representing D-Bus struct and array. More...

`#include <edelib/EdbusList.h>`

Inheritance diagram for EdbusList:

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

## Detailed Description

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.

Todo:
  This should be probably an assertion

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:

int numbers[] = {1, 2, 3};
EdbusList array = EdbusList::create_array();
array << EdbusData::from_int32(numbers[0]) << EdbusData::from_int32(numbers[1]) << EdbusData::from_int32(numbers[2]);

Since operator<<() is shorcut for append(), you can use append() instead too.

Now, let say you want to send some struct via bus. Sample:

// somewhere outside function
struct some_struct {
int number;
char character;
};
// in your function
some_struct v;
v.number = 3;
v.character = 'c';
EdbusList st = EdbusList::create_struct();
st << EdbusData::from_int32(v.number);
st << EdbusData::from_char(v.character);

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:

EdbusList array = EdbusList::create_array();
array << EdbusData::from_bool(false);
array << EdbusData::from_int32(45); // different type than first element, ignored
array << EdbusData::from_bool(true); // the same type as first element, ok

Some things can look like correct C++ statement, but due D-Bus signatures they are not, like:

EdbusList array = EdbusList::create_array();
array << EdbusData::from_bool(true);
// invalid; singatures for boolean and int32 types are different
// no matter if this is a valid from C++ view
array << EdbusData::from_int32(true);

For more details,

See also
  EdbusData

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.

## Member Typedef Documentation

typedef EdbusContainer<EdbusData>::const_iterator const_iterator

Declares EdbusList iterator

## Constructor & Destructor Documentation

EdbusList | ( | bool | a | ) |
| explicit

Create empty container

Parameters

  a | if true, container will be array type, else it will be struct type

## Member Function Documentation

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

static EdbusList create_array | ( | void |  | ) |
| inline static

Explicitly create array. This function should be used to create arrays

static EdbusList create_struct | ( | void |  | ) |
| inline static

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

bool list_is_array | ( | void |  | ) | const
| inline

Returns true if object behaves as array

bool list_is_struct | ( | void |  | ) | const
| inline

Returns true if object behaves as struct

bool operator!= | ( | const EdbusList & | other | ) | const
| 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 |  | ) |

Return true if value type is container (EdbusDict or EdbusList). Only valid if container is array; if not, EDBUS_TYPE_INVALID will be returned

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

- edelib/EdbusList.h