edelib  2.1.0
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 
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 {
493 };
494 
495 EDELIB_NS_END
496 #endif
static EdbusData from_char(char val)
Definition: EdbusData.h:412
bool is_variant(void) const
Definition: EdbusData.h:382
bool is_bool(void) const
Definition: EdbusData.h:322
static EdbusData from_variant(const EdbusVariant &val)
Definition: EdbusData.h:467
Class for representing D-Bus data types.
Definition: EdbusData.h:110
bool is_valid(void) const
Definition: EdbusData.h:307
bool is_array(void) const
Definition: EdbusData.h:372
static EdbusData from_int32(int32_t val)
Definition: EdbusData.h:432
static EdbusData from_bool(bool val)
Definition: EdbusData.h:417
bool is_int16(void) const
Definition: EdbusData.h:327
A class representing D-Bus struct and array.
Definition: EdbusList.h:114
static EdbusData from_invalid(void)
Definition: EdbusData.h:402
bool is_uint64(void) const
Definition: EdbusData.h:352
string
Definition: EdbusData.h:52
variant
Definition: EdbusData.h:57
static EdbusData from_string(const char *val)
Definition: EdbusData.h:457
Represents D-Bus object path.
Definition: EdbusObjectPath.h:58
unsigned short
Definition: EdbusData.h:46
unsigned integer
Definition: EdbusData.h:48
static EdbusData from_object_path(const EdbusObjectPath &val)
Definition: EdbusData.h:462
static EdbusData from_array(const EdbusList &val)
Definition: EdbusData.h:477
unsigned long long
Definition: EdbusData.h:50
static EdbusData from_struct(const EdbusList &val)
Definition: EdbusData.h:482
bool is_dict(void) const
Definition: EdbusData.h:387
EdbusDataType type(void) const
static EdbusData from_double(double val)
Definition: EdbusData.h:452
bool is_double(void) const
Definition: EdbusData.h:357
bool is_char(void) const
Definition: EdbusData.h:317
static EdbusData from_uint64(uint64_t val)
Definition: EdbusData.h:447
static EdbusData from_int64(int64_t val)
Definition: EdbusData.h:442
bool is_object_path(void) const
Definition: EdbusData.h:367
long long
Definition: EdbusData.h:49
integer
Definition: EdbusData.h:47
static EdbusData from_uint16(uint16_t val)
Definition: EdbusData.h:427
bool is_byte(void) const
Definition: EdbusData.h:312
EdbusObjectPath type.
Definition: EdbusData.h:53
EdbusData value
Definition: EdbusData.h:492
short
Definition: EdbusData.h:45
bool is_int64(void) const
Definition: EdbusData.h:347
static EdbusData from_dict(const EdbusDict &val)
Definition: EdbusData.h:472
char to_char(void) const
Definition: EdbusData.h:216
Dictionary container for D-Bus types.
Definition: EdbusDict.h:121
bool
Definition: EdbusData.h:44
double
Definition: EdbusData.h:51
bool is_uint32(void) const
Definition: EdbusData.h:342
static EdbusData from_byte(byte_t val)
Definition: EdbusData.h:407
structure
Definition: EdbusData.h:55
bool is_uint16(void) const
Definition: EdbusData.h:332
bool is_struct(void) const
Definition: EdbusData.h:377
byte
Definition: EdbusData.h:43
Invalid type (empty object)
Definition: EdbusData.h:42
static EdbusData from_uint32(uint32_t val)
Definition: EdbusData.h:437
static bool basic_type(const EdbusData &val)
Definition: EdbusData.h:394
dictionary
Definition: EdbusData.h:56
bool operator!=(const EdbusData &other) const
Definition: EdbusData.h:302
bool is_int32(void) const
Definition: EdbusData.h:337
Represents D-Bus variant.
Definition: EdbusData.h:490
bool is_string(void) const
Definition: EdbusData.h:362
array
Definition: EdbusData.h:54
static EdbusData from_int16(int16_t val)
Definition: EdbusData.h:422
EdbusDataType
Type of data current EdbusData object holds.
Definition: EdbusData.h:41