edelib 2.1.0

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

- File List

EdbusData.h
1 /*
2 * $Id: EdbusData.h 3441 2012-11-01 20:40:30Z karijes $
3 *
4 * D-BUS stuff
5 * Copyright (c) 2008 edelib authors
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef __EDELIB_EDBUSDATA_H__
22 #define __EDELIB_EDBUSDATA_H__
23
24 #include <inttypes.h>
25 #include "EdbusObjectPath.h"
26
27 typedef char byte_t;
28
29 /* Sun compiler does not have this type */
30 #ifdef __SUNPRO_CC
31 typedef long long int int64_t;
32 #endif
33
34 EDELIB_NS_BEGIN
35
41 enum EdbusDataType {
42 EDBUS_TYPE_INVALID,
43 EDBUS_TYPE_BYTE,
44 EDBUS_TYPE_BOOL,
45 EDBUS_TYPE_INT16,
46 EDBUS_TYPE_UINT16,
47 EDBUS_TYPE_INT32,
48 EDBUS_TYPE_UINT32,
49 EDBUS_TYPE_INT64,
50 EDBUS_TYPE_UINT64,
51 EDBUS_TYPE_DOUBLE,
52 EDBUS_TYPE_STRING,
53 EDBUS_TYPE_OBJECT_PATH,
54 EDBUS_TYPE_ARRAY,
55 EDBUS_TYPE_STRUCT,
56 EDBUS_TYPE_DICT,
57 EDBUS_TYPE_VARIANT
58 };
59
60 #ifndef SKIP_DOCS
61 struct EdbusDataPrivate;
62 #endif
63
64 struct EdbusDict;
65 class EdbusList;
66 struct EdbusVariant;
67
110 class EDELIB_API EdbusData {
111 private:
112 EdbusDataPrivate* impl;
113 void dispose(void);
114
115 public:
119 EdbusData();
120
124 EdbusData(byte_t val);
125
129 EdbusData(bool val);
130
134 EdbusData(int16_t val);
135
139 EdbusData(uint16_t val);
140
144 EdbusData(int32_t val);
145
149 EdbusData(uint32_t val);
150
154 EdbusData(int64_t val);
155
159 EdbusData(uint64_t val);
160
164 EdbusData(double val);
165
169 EdbusData(const char* val);
170
174 EdbusData(const EdbusObjectPath& val);
175
179 EdbusData(const EdbusVariant& val);
180
184 EdbusData(const EdbusDict& val);
185
190 EdbusData(const EdbusList& val);
191
196 EdbusData(const EdbusData& other);
197
201 ~EdbusData();
202
206 EdbusDataType type(void) const;
207
211 byte_t to_byte(void) const;
212
216 char to_char(void) const { return to_byte(); }
217
221 bool to_bool(void) const;
222
226 int16_t to_int16(void) const;
227
231 uint16_t to_uint16(void) const;
232
236 int32_t to_int32(void) const;
237
241 uint32_t to_uint32(void) const;
242
246 int64_t to_int64(void) const;
247
251 uint64_t to_uint64(void) const;
252
256 double to_double(void) const;
257
261 const char* to_string(void) const;
262
266 EdbusObjectPath to_object_path(void) const;
267
271 EdbusVariant to_variant(void) const;
272
276 EdbusDict to_dict(void) const;
277
281 EdbusList to_array(void) const;
282
286 EdbusList to_struct(void) const;
287
291 EdbusData& operator=(const EdbusData& other);
292
297 bool operator==(const EdbusData& other) const;
298
302 bool operator!=(const EdbusData& other) const { return !operator==(other); }
303
307 bool is_valid(void) const { return type() != EDBUS_TYPE_INVALID; }
308
312 bool is_byte(void) const { return type() == EDBUS_TYPE_BYTE; }
313
317 bool is_char(void) const { return is_byte(); }
318
322 bool is_bool(void) const { return type() == EDBUS_TYPE_BOOL; }
323
327 bool is_int16(void) const { return type() == EDBUS_TYPE_INT16; }
328
332 bool is_uint16(void) const { return type() == EDBUS_TYPE_UINT16; }
333
337 bool is_int32(void) const { return type() == EDBUS_TYPE_INT32; }
338
342 bool is_uint32(void) const { return type() == EDBUS_TYPE_UINT32; }
343
347 bool is_int64(void) const { return type() == EDBUS_TYPE_INT64; }
348
352 bool is_uint64(void) const { return type() == EDBUS_TYPE_UINT64; }
353
357 bool is_double(void) const { return type() == EDBUS_TYPE_DOUBLE; }
358
362 bool is_string(void) const { return type() == EDBUS_TYPE_STRING; }
363
367 bool is_object_path(void) const { return type() == EDBUS_TYPE_OBJECT_PATH; }
368
372 bool is_array(void) const { return type() == EDBUS_TYPE_ARRAY; }
373
377 bool is_struct(void) const { return type() == EDBUS_TYPE_STRUCT; }
378
382 bool is_variant(void) const { return type() == EDBUS_TYPE_VARIANT; }
383
387 bool is_dict(void) const { return type() == EDBUS_TYPE_DICT; }
388
394 static bool basic_type(const EdbusData& val) {
395 return ((val.type() != EDBUS_TYPE_ARRAY) && (val.type() != EDBUS_TYPE_STRUCT) &&
396 (val.type() != EDBUS_TYPE_VARIANT) && (val.type() != EDBUS_TYPE_DICT));
397 }
398
402 static EdbusData from_invalid(void) { return EdbusData(); }
403
407 static EdbusData from_byte(byte_t val) { return EdbusData((byte_t)val); }
408
412 static EdbusData from_char(char val) { return from_byte(val); }
413
417 static EdbusData from_bool(bool val) { return EdbusData((bool)val); }
418
422 static EdbusData from_int16(int16_t val) { return EdbusData((int16_t)val); }
423
427 static EdbusData from_uint16(uint16_t val) { return EdbusData((uint16_t)val); }
428
432 static EdbusData from_int32(int32_t val) { return EdbusData((int32_t)val); }
433
437 static EdbusData from_uint32(uint32_t val) { return EdbusData((uint32_t)val); }
438
442 static EdbusData from_int64(int64_t val) { return EdbusData((int64_t)val); }
443
447 static EdbusData from_uint64(uint64_t val) { return EdbusData((uint64_t)val); }
448
452 static EdbusData from_double(double val) { return EdbusData((double)val); }
453
457 static EdbusData from_string(const char* val) { return EdbusData((const char*)val); }
458
462 static EdbusData from_object_path(const EdbusObjectPath& val) { return EdbusData(val); }
463
467 static EdbusData from_variant(const EdbusVariant& val) { return EdbusData(val); }
468
472 static EdbusData from_dict(const EdbusDict& val) { return EdbusData(val); }
473
477 static EdbusData from_array(const EdbusList& val) { return EdbusData(val); }
478
482 static EdbusData from_struct(const EdbusList& val) { return EdbusData(val); }
483 };
484
490 struct EdbusVariant {
492 EdbusData value;
493 };
494
495 EDELIB_NS_END
496 #endif
edelib::EdbusData::from_char
static EdbusData from_char(char val)
Definition: EdbusData.h:412
edelib::EdbusData::is_variant
bool is_variant(void) const
Definition: EdbusData.h:382
edelib::EdbusData::is_bool
bool is_bool(void) const
Definition: EdbusData.h:322
edelib::EdbusData::from_variant
static EdbusData from_variant(const EdbusVariant &val)
Definition: EdbusData.h:467
edelib::EdbusData
Class for representing D-Bus data types.
Definition: EdbusData.h:110
edelib::EdbusData::is_valid
bool is_valid(void) const
Definition: EdbusData.h:307
edelib::EdbusData::is_array
bool is_array(void) const
Definition: EdbusData.h:372
edelib::EdbusData::from_int32
static EdbusData from_int32(int32_t val)
Definition: EdbusData.h:432
edelib::EdbusData::from_bool
static EdbusData from_bool(bool val)
Definition: EdbusData.h:417
edelib::EdbusData::is_int16
bool is_int16(void) const
Definition: EdbusData.h:327
edelib::EdbusList
A class representing D-Bus struct and array.
Definition: EdbusList.h:114
edelib::EdbusData::from_invalid
static EdbusData from_invalid(void)
Definition: EdbusData.h:402
edelib::EdbusData::is_uint64
bool is_uint64(void) const
Definition: EdbusData.h:352
edelib::EDBUS_TYPE_STRING
string
Definition: EdbusData.h:52
edelib::EDBUS_TYPE_VARIANT
variant
Definition: EdbusData.h:57
edelib::EdbusData::from_string
static EdbusData from_string(const char *val)
Definition: EdbusData.h:457
edelib::EdbusObjectPath
Represents D-Bus object path.
Definition: EdbusObjectPath.h:58
edelib::EDBUS_TYPE_UINT16
unsigned short
Definition: EdbusData.h:46
edelib::EDBUS_TYPE_UINT32
unsigned integer
Definition: EdbusData.h:48
edelib::EdbusData::from_object_path
static EdbusData from_object_path(const EdbusObjectPath &val)
Definition: EdbusData.h:462
edelib::EdbusData::from_array
static EdbusData from_array(const EdbusList &val)
Definition: EdbusData.h:477
edelib::EDBUS_TYPE_UINT64
unsigned long long
Definition: EdbusData.h:50
edelib::EdbusData::from_struct
static EdbusData from_struct(const EdbusList &val)
Definition: EdbusData.h:482
edelib::EdbusData::is_dict
bool is_dict(void) const
Definition: EdbusData.h:387
edelib::EdbusData::type
EdbusDataType type(void) const
edelib::EdbusData::from_double
static EdbusData from_double(double val)
Definition: EdbusData.h:452
edelib::EdbusData::is_double
bool is_double(void) const
Definition: EdbusData.h:357
edelib::EdbusData::is_char
bool is_char(void) const
Definition: EdbusData.h:317
edelib::EdbusData::from_uint64
static EdbusData from_uint64(uint64_t val)
Definition: EdbusData.h:447
edelib::EdbusData::from_int64
static EdbusData from_int64(int64_t val)
Definition: EdbusData.h:442
edelib::EdbusData::is_object_path
bool is_object_path(void) const
Definition: EdbusData.h:367
edelib::EDBUS_TYPE_INT64
long long
Definition: EdbusData.h:49
edelib::EDBUS_TYPE_INT32
integer
Definition: EdbusData.h:47
edelib::EdbusData::from_uint16
static EdbusData from_uint16(uint16_t val)
Definition: EdbusData.h:427
edelib::EdbusData::is_byte
bool is_byte(void) const
Definition: EdbusData.h:312
edelib::EDBUS_TYPE_OBJECT_PATH
EdbusObjectPath type.
Definition: EdbusData.h:53
edelib::EdbusVariant::value
EdbusData value
Definition: EdbusData.h:492
edelib::EDBUS_TYPE_INT16
short
Definition: EdbusData.h:45
edelib::EdbusData::is_int64
bool is_int64(void) const
Definition: EdbusData.h:347
edelib::EdbusData::from_dict
static EdbusData from_dict(const EdbusDict &val)
Definition: EdbusData.h:472
edelib::EdbusData::to_char
char to_char(void) const
Definition: EdbusData.h:216
edelib::EdbusDict
Dictionary container for D-Bus types.
Definition: EdbusDict.h:121
edelib::EDBUS_TYPE_BOOL
bool
Definition: EdbusData.h:44
edelib::EDBUS_TYPE_DOUBLE
double
Definition: EdbusData.h:51
edelib::EdbusData::is_uint32
bool is_uint32(void) const
Definition: EdbusData.h:342
edelib::EdbusData::from_byte
static EdbusData from_byte(byte_t val)
Definition: EdbusData.h:407
edelib::EDBUS_TYPE_STRUCT
structure
Definition: EdbusData.h:55
edelib::EdbusData::is_uint16
bool is_uint16(void) const
Definition: EdbusData.h:332
edelib::EdbusData::is_struct
bool is_struct(void) const
Definition: EdbusData.h:377
edelib::EDBUS_TYPE_BYTE
byte
Definition: EdbusData.h:43
edelib::EDBUS_TYPE_INVALID
Invalid type (empty object)
Definition: EdbusData.h:42
edelib::EdbusData::from_uint32
static EdbusData from_uint32(uint32_t val)
Definition: EdbusData.h:437
edelib::EdbusData::basic_type
static bool basic_type(const EdbusData &val)
Definition: EdbusData.h:394
edelib::EDBUS_TYPE_DICT
dictionary
Definition: EdbusData.h:56
edelib::EdbusData::operator!=
bool operator!=(const EdbusData &other) const
Definition: EdbusData.h:302
edelib::EdbusData::is_int32
bool is_int32(void) const
Definition: EdbusData.h:337
edelib::EdbusVariant
Represents D-Bus variant.
Definition: EdbusData.h:490
edelib::EdbusData::is_string
bool is_string(void) const
Definition: EdbusData.h:362
edelib::EDBUS_TYPE_ARRAY
array
Definition: EdbusData.h:54
edelib::EdbusData::from_int16
static EdbusData from_int16(int16_t val)
Definition: EdbusData.h:422
edelib::EdbusDataType
EdbusDataType
Type of data current EdbusData object holds.
Definition: EdbusData.h:41