edelib 2.1.0
EdbusList Class Reference

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

#include <edelib/EdbusList.h>

Inheritance diagram for EdbusList:
EdbusContainer< EdbusData >

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 ()
 
EdbusContaineroperator= (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};
array << EdbusData::from_int32(numbers[0]) << EdbusData::from_int32(numbers[1]) << EdbusData::from_int32(numbers[2]);
static EdbusData from_int32(int32_t val)
Definition EdbusData.h:432
A class representing D-Bus struct and array.
Definition EdbusList.h:114
static EdbusList create_array(void)
Definition EdbusList.h:202

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';
st << EdbusData::from_int32(v.number);
st << EdbusData::from_char(v.character);
static EdbusData from_char(char val)
Definition EdbusData.h:412
static EdbusList create_struct(void)
Definition EdbusList.h:207

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:

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
static EdbusData from_bool(bool val)
Definition EdbusData.h:417

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

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

◆ const_iterator

Declares EdbusList iterator

Constructor & Destructor Documentation

◆ EdbusList()

EdbusList ( bool a)
explicit

Create empty container

Parameters
aif true, container will be array type, else it will be struct type

Member Function Documentation

◆ append()

void append ( const EdbusData & val)

Adds element to the end of the container

Referenced by edelib::operator<<().

◆ begin()

const_iterator begin ( void ) const

Returns iterator at the container start. It points to the first element

◆ clear()

void clear ( void )

Clears content of container

◆ create_array()

static EdbusList create_array ( void )
inlinestatic

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

◆ create_struct()

static EdbusList create_struct ( void )
inlinestatic

Explicitly create struct. This function should be used to create structs

◆ end()

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

◆ list_is_array()

bool list_is_array ( void ) const
inline

Returns true if object behaves as array

◆ list_is_struct()

bool list_is_struct ( void ) const
inline

Returns true if object behaves as struct

◆ operator!=()

bool operator!= ( const EdbusList & other) const
inline

Compares if two arrays or structs are not equal

◆ operator==()

bool operator== ( const EdbusList & other) const

Compares if two arrays or structs are equal

◆ remove()

void remove ( const EdbusData & val)

Remove element from container, if element is found

◆ remove_all()

void remove_all ( const EdbusData & val)

Remove all elements that are equal to the val

◆ size()

unsigned int size ( void ) const

Returns size of container content. This is a constant operation

◆ value_type()

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

◆ value_type_is_container()

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: