edelib 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