edelib  2.1.0
Public Member Functions | Static Public Member Functions | List of all members
EdbusData Class Reference

Class for representing D-Bus data types. More...

#include <edelib/EdbusData.h>

Public Member Functions

 EdbusData ()
 
 EdbusData (byte_t val)
 
 EdbusData (bool val)
 
 EdbusData (int16_t val)
 
 EdbusData (uint16_t val)
 
 EdbusData (int32_t val)
 
 EdbusData (uint32_t val)
 
 EdbusData (int64_t val)
 
 EdbusData (uint64_t val)
 
 EdbusData (double val)
 
 EdbusData (const char *val)
 
 EdbusData (const EdbusObjectPath &val)
 
 EdbusData (const EdbusVariant &val)
 
 EdbusData (const EdbusDict &val)
 
 EdbusData (const EdbusList &val)
 
 EdbusData (const EdbusData &other)
 
 ~EdbusData ()
 
EdbusDataType type (void) const
 
byte_t to_byte (void) const
 
char to_char (void) const
 
bool to_bool (void) const
 
int16_t to_int16 (void) const
 
uint16_t to_uint16 (void) const
 
int32_t to_int32 (void) const
 
uint32_t to_uint32 (void) const
 
int64_t to_int64 (void) const
 
uint64_t to_uint64 (void) const
 
double to_double (void) const
 
const char * to_string (void) const
 
EdbusObjectPath to_object_path (void) const
 
EdbusVariant to_variant (void) const
 
EdbusDict to_dict (void) const
 
EdbusList to_array (void) const
 
EdbusList to_struct (void) const
 
EdbusDataoperator= (const EdbusData &other)
 
bool operator== (const EdbusData &other) const
 
bool operator!= (const EdbusData &other) const
 
bool is_valid (void) const
 
bool is_byte (void) const
 
bool is_char (void) const
 
bool is_bool (void) const
 
bool is_int16 (void) const
 
bool is_uint16 (void) const
 
bool is_int32 (void) const
 
bool is_uint32 (void) const
 
bool is_int64 (void) const
 
bool is_uint64 (void) const
 
bool is_double (void) const
 
bool is_string (void) const
 
bool is_object_path (void) const
 
bool is_array (void) const
 
bool is_struct (void) const
 
bool is_variant (void) const
 
bool is_dict (void) const
 

Static Public Member Functions

static bool basic_type (const EdbusData &val)
 
static EdbusData from_invalid (void)
 
static EdbusData from_byte (byte_t val)
 
static EdbusData from_char (char val)
 
static EdbusData from_bool (bool val)
 
static EdbusData from_int16 (int16_t val)
 
static EdbusData from_uint16 (uint16_t val)
 
static EdbusData from_int32 (int32_t val)
 
static EdbusData from_uint32 (uint32_t val)
 
static EdbusData from_int64 (int64_t val)
 
static EdbusData from_uint64 (uint64_t val)
 
static EdbusData from_double (double val)
 
static EdbusData from_string (const char *val)
 
static EdbusData from_object_path (const EdbusObjectPath &val)
 
static EdbusData from_variant (const EdbusVariant &val)
 
static EdbusData from_dict (const EdbusDict &val)
 
static EdbusData from_array (const EdbusList &val)
 
static EdbusData from_struct (const EdbusList &val)
 

Detailed Description

Class for representing D-Bus data types.

This class is variant-like class; this means it can hold any of already predefined types (see EdbusDataType for the list) that D-Bus protocol understainds.

Class use implicit sharing so copying EdbusData objects is cheap operation that does not require content copying.

Since EdbusData object can hold only one type at the time (I'm assuming arrays or structs are types too), when you decide to fetch a currently holding value, make sure you call correct function (e.g. for bool to_bool() or for double to_double()) or assertion will be triggered.

The best way to check what current type is, is to use one of is_XYZ members (e.g. for bool is_bool() or for double is_double()).

When data is assigned to EdbusData, it can implicitly resolve data type (e.g. strings, integers or EdbusObjectPath), but in case of similar types, things can a bit strange at first look. To better explain this, let say you assign 5 as value like:

* EdbusData d = 5;
*

What is d type? byte_t, int16_t, uint16_t, int32_t, uint32_t, int64_t and uint64_t can holds this value; by default, a compiler will use constructor with int32_t and d will be that type. This let-things-done-by-compiler stuff can introduce a strange bugs, so static from_ members are given to make life easier for compiler, like:

* // or to force it inot uint16_t
*
Note
D-Bus signature for above types is different and sending int32_t to the service that expects uint16_t will probably result rejecting whole message!

Constructor & Destructor Documentation

EdbusData ( )

Construct object with invalid type

EdbusData ( byte_t  val)

Construct object with byte (char) type

EdbusData ( bool  val)

Construct object with bool type

EdbusData ( int16_t  val)

Construct object with int16 (short) type

EdbusData ( uint16_t  val)

Construct object with uint16 (unsigned short) type

EdbusData ( int32_t  val)

Construct object with int32 (int) type

EdbusData ( uint32_t  val)

Construct object with uint32 (unsigned int) type

EdbusData ( int64_t  val)

Construct object with int64 (long long) type

EdbusData ( uint64_t  val)

Construct object with uint64 (unsigned long long) type

EdbusData ( double  val)

Construct object with double type

EdbusData ( const char *  val)

Construct object with string type

EdbusData ( const EdbusObjectPath val)

Construct object with EdbusObjectPath type

EdbusData ( const EdbusVariant val)

Construct object with EdbusVariant type

EdbusData ( const EdbusDict val)

Construct object with EdbusDict type

EdbusData ( const EdbusList val)

Construct object with EdbusList type. Correct type will be deduced from EdbusList::list_is_array() and EdbusList::list_is_struct() members

EdbusData ( const EdbusData other)

Construct object with already constructed object. Essential for containers

~EdbusData ( )

Destructs object cleaning allocated data

Member Function Documentation

static bool basic_type ( const EdbusData val)
inlinestatic

Returns true if given object is basic type. Basic types (to D-Bus) are all EdbusDataType types except array, structure, dict and variant

References edelib::EDBUS_TYPE_ARRAY, edelib::EDBUS_TYPE_DICT, edelib::EDBUS_TYPE_STRUCT, edelib::EDBUS_TYPE_VARIANT, and EdbusData::type().

static EdbusData from_array ( const EdbusList val)
inlinestatic

Creates array object. EdbusData constructor will handle EdbusList type

static EdbusData from_bool ( bool  val)
inlinestatic

Creates object with bool value

static EdbusData from_byte ( byte_t  val)
inlinestatic

Creates object with byte value

static EdbusData from_char ( char  val)
inlinestatic

Creates object with char value

static EdbusData from_dict ( const EdbusDict val)
inlinestatic

Creates object with EdbusDict value

static EdbusData from_double ( double  val)
inlinestatic

Creates object with double value

static EdbusData from_int16 ( int16_t  val)
inlinestatic

Creates object with int16 value

static EdbusData from_int32 ( int32_t  val)
inlinestatic

Creates object with int32 value

static EdbusData from_int64 ( int64_t  val)
inlinestatic

Creates object with int64 value

static EdbusData from_invalid ( void  )
inlinestatic

Creates object of invalid type

static EdbusData from_object_path ( const EdbusObjectPath val)
inlinestatic

Creates object with EdbusObjectPath value

static EdbusData from_string ( const char *  val)
inlinestatic

Creates object with string value

static EdbusData from_struct ( const EdbusList val)
inlinestatic

Creates struct object. EdbusData constructor will handle EdbusList type

static EdbusData from_uint16 ( uint16_t  val)
inlinestatic

Creates object with uint16 value

static EdbusData from_uint32 ( uint32_t  val)
inlinestatic

Creates object with uint32 value

static EdbusData from_uint64 ( uint64_t  val)
inlinestatic

Creates object with uint64 value

static EdbusData from_variant ( const EdbusVariant val)
inlinestatic

Creates object with EdbusVariant value

bool is_array ( void  ) const
inline

Returns true if object currently holds a EdbusList as array value

References edelib::EDBUS_TYPE_ARRAY.

bool is_bool ( void  ) const
inline

Returns true if object currently holds a bool value

References edelib::EDBUS_TYPE_BOOL.

bool is_byte ( void  ) const
inline

Returns true if object currently holds a byte value

References edelib::EDBUS_TYPE_BYTE.

bool is_char ( void  ) const
inline

Returns true if object currently holds a char value

bool is_dict ( void  ) const
inline

Returns true if object currently holds a EdbusDict value

References edelib::EDBUS_TYPE_DICT.

bool is_double ( void  ) const
inline

Returns true if object currently holds a double value

References edelib::EDBUS_TYPE_DOUBLE.

bool is_int16 ( void  ) const
inline

Returns true if object currently holds a int16 value

References edelib::EDBUS_TYPE_INT16.

bool is_int32 ( void  ) const
inline

Returns true if object currently holds a int32 value

References edelib::EDBUS_TYPE_INT32.

bool is_int64 ( void  ) const
inline

Returns true if object currently holds a int64 value

References edelib::EDBUS_TYPE_INT64.

bool is_object_path ( void  ) const
inline

Returns true if object currently holds a EdbusObjectPath value

References edelib::EDBUS_TYPE_OBJECT_PATH.

bool is_string ( void  ) const
inline

Returns true if object currently holds a string value

References edelib::EDBUS_TYPE_STRING.

bool is_struct ( void  ) const
inline

Returns true if object currently holds a EdbusList as struct value

References edelib::EDBUS_TYPE_STRUCT.

bool is_uint16 ( void  ) const
inline

Returns true if object currently holds a uint16 value

References edelib::EDBUS_TYPE_UINT16.

bool is_uint32 ( void  ) const
inline

Returns true if object currently holds a uint32 value

References edelib::EDBUS_TYPE_UINT32.

bool is_uint64 ( void  ) const
inline

Returns true if object currently holds a uint64 value

References edelib::EDBUS_TYPE_UINT64.

bool is_valid ( void  ) const
inline

Returns true if object currently holds a value of valid type

References edelib::EDBUS_TYPE_INVALID.

bool is_variant ( void  ) const
inline

Returns true if object currently holds a EdbusVariant value

References edelib::EDBUS_TYPE_VARIANT.

bool operator!= ( const EdbusData other) const
inline

Check if two objects are not equal

EdbusData& operator= ( const EdbusData other)

Assign existing object

bool operator== ( const EdbusData other) const

Check if two objects are the same checking their types and comparing their values if they are same type

EdbusList to_array ( void  ) const

Returns a EdbusList object as array

bool to_bool ( void  ) const

Returns a bool value if it holds

byte_t to_byte ( void  ) const

Returns a byte value if it holds

char to_char ( void  ) const
inline

Returns a char value if it holds

EdbusDict to_dict ( void  ) const

Returns a EdbusDict value if it holds

double to_double ( void  ) const

Returns a double value if it holds

int16_t to_int16 ( void  ) const

Returns a int16 value if it holds

int32_t to_int32 ( void  ) const

Returns a int32 value if it holds

int64_t to_int64 ( void  ) const

Returns a int64 value if it holds

EdbusObjectPath to_object_path ( void  ) const

Returns a EdbusObjectPath value if it holds

const char* to_string ( void  ) const

Returns a string value if it holds

EdbusList to_struct ( void  ) const

Returns a EdbusList object as struct

uint16_t to_uint16 ( void  ) const

Returns a uint16 value if it holds

uint32_t to_uint32 ( void  ) const

Returns a uint32 value if it holds

uint64_t to_uint64 ( void  ) const

Returns a uint64 value if it holds

EdbusVariant to_variant ( void  ) const

Returns a EdbusVariant value if it holds

EdbusDataType type ( void  ) const

Returns a current holding type

Referenced by EdbusData::basic_type().


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