edelib 2.0.0
|
00001 /* 00002 * $Id: EdbusData.h 2839 2009-09-28 11:36:20Z karijes $ 00003 * 00004 * D-BUS stuff 00005 * Copyright (c) 2008 edelib authors 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef __EDELIB_EDBUSDATA_H__ 00022 #define __EDELIB_EDBUSDATA_H__ 00023 00024 #include <inttypes.h> 00025 #include "EdbusObjectPath.h" 00026 00027 typedef char byte_t; 00028 00029 /* Sun compiler does not have this type */ 00030 #ifdef __SUNPRO_CC 00031 typedef long long int int64_t; 00032 #endif 00033 00034 EDELIB_NS_BEGIN 00035 00041 enum EdbusDataType { 00042 EDBUS_TYPE_INVALID, 00043 EDBUS_TYPE_BYTE, 00044 EDBUS_TYPE_BOOL, 00045 EDBUS_TYPE_INT16, 00046 EDBUS_TYPE_UINT16, 00047 EDBUS_TYPE_INT32, 00048 EDBUS_TYPE_UINT32, 00049 EDBUS_TYPE_INT64, 00050 EDBUS_TYPE_UINT64, 00051 EDBUS_TYPE_DOUBLE, 00052 EDBUS_TYPE_STRING, 00053 EDBUS_TYPE_OBJECT_PATH, 00054 EDBUS_TYPE_ARRAY, 00055 EDBUS_TYPE_STRUCT, 00056 EDBUS_TYPE_DICT, 00057 EDBUS_TYPE_VARIANT 00058 }; 00059 00060 #ifndef SKIP_DOCS 00061 struct EdbusDataPrivate; 00062 #endif 00063 00064 class EdbusDict; 00065 class EdbusList; 00066 struct EdbusVariant; 00067 00110 class EDELIB_API EdbusData { 00111 private: 00112 EdbusDataPrivate* impl; 00113 void dispose(void); 00114 00115 public: 00119 EdbusData(); 00120 00124 EdbusData(byte_t val); 00125 00129 EdbusData(bool val); 00130 00134 EdbusData(int16_t val); 00135 00139 EdbusData(uint16_t val); 00140 00144 EdbusData(int32_t val); 00145 00149 EdbusData(uint32_t val); 00150 00154 EdbusData(int64_t val); 00155 00159 EdbusData(uint64_t val); 00160 00164 EdbusData(double val); 00165 00169 EdbusData(const char* val); 00170 00174 EdbusData(const EdbusObjectPath& val); 00175 00179 EdbusData(const EdbusVariant& val); 00180 00184 EdbusData(const EdbusDict& val); 00185 00190 EdbusData(const EdbusList& val); 00191 00196 EdbusData(const EdbusData& other); 00197 00201 ~EdbusData(); 00202 00206 EdbusDataType type(void) const; 00207 00211 byte_t to_byte(void) const; 00212 00216 char to_char(void) const { return to_byte(); } 00217 00221 bool to_bool(void) const; 00222 00226 int16_t to_int16(void) const; 00227 00231 uint16_t to_uint16(void) const; 00232 00236 int32_t to_int32(void) const; 00237 00241 uint32_t to_uint32(void) const; 00242 00246 int64_t to_int64(void) const; 00247 00251 uint64_t to_uint64(void) const; 00252 00256 double to_double(void) const; 00257 00261 const char* to_string(void) const; 00262 00266 EdbusObjectPath to_object_path(void) const; 00267 00271 EdbusVariant to_variant(void) const; 00272 00276 EdbusDict to_dict(void) const; 00277 00281 EdbusList to_array(void) const; 00282 00286 EdbusList to_struct(void) const; 00287 00291 EdbusData& operator=(const EdbusData& other); 00292 00297 bool operator==(const EdbusData& other) const; 00298 00302 bool operator!=(const EdbusData& other) const { return !operator==(other); } 00303 00307 bool is_valid(void) const { return type() != EDBUS_TYPE_INVALID; } 00308 00312 bool is_byte(void) const { return type() == EDBUS_TYPE_BYTE; } 00313 00317 bool is_char(void) const { return is_byte(); } 00318 00322 bool is_bool(void) const { return type() == EDBUS_TYPE_BOOL; } 00323 00327 bool is_int16(void) const { return type() == EDBUS_TYPE_INT16; } 00328 00332 bool is_uint16(void) const { return type() == EDBUS_TYPE_UINT16; } 00333 00337 bool is_int32(void) const { return type() == EDBUS_TYPE_INT32; } 00338 00342 bool is_uint32(void) const { return type() == EDBUS_TYPE_UINT32; } 00343 00347 bool is_int64(void) const { return type() == EDBUS_TYPE_INT64; } 00348 00352 bool is_uint64(void) const { return type() == EDBUS_TYPE_UINT64; } 00353 00357 bool is_double(void) const { return type() == EDBUS_TYPE_DOUBLE; } 00358 00362 bool is_string(void) const { return type() == EDBUS_TYPE_STRING; } 00363 00367 bool is_object_path(void) const { return type() == EDBUS_TYPE_OBJECT_PATH; } 00368 00372 bool is_array(void) const { return type() == EDBUS_TYPE_ARRAY; } 00373 00377 bool is_struct(void) const { return type() == EDBUS_TYPE_STRUCT; } 00378 00382 bool is_variant(void) const { return type() == EDBUS_TYPE_VARIANT; } 00383 00387 bool is_dict(void) const { return type() == EDBUS_TYPE_DICT; } 00388 00394 static bool basic_type(const EdbusData& val) { 00395 return ((val.type() != EDBUS_TYPE_ARRAY) && (val.type() != EDBUS_TYPE_STRUCT) && 00396 (val.type() != EDBUS_TYPE_VARIANT) && (val.type() != EDBUS_TYPE_DICT)); 00397 } 00398 00402 static EdbusData from_invalid(void) { return EdbusData(); } 00403 00407 static EdbusData from_byte(byte_t val) { return EdbusData((byte_t)val); } 00408 00412 static EdbusData from_char(char val) { return from_byte(val); } 00413 00417 static EdbusData from_bool(bool val) { return EdbusData((bool)val); } 00418 00422 static EdbusData from_int16(int16_t val) { return EdbusData((int16_t)val); } 00423 00427 static EdbusData from_uint16(uint16_t val) { return EdbusData((uint16_t)val); } 00428 00432 static EdbusData from_int32(int32_t val) { return EdbusData((int32_t)val); } 00433 00437 static EdbusData from_uint32(uint32_t val) { return EdbusData((uint32_t)val); } 00438 00442 static EdbusData from_int64(int64_t val) { return EdbusData((int64_t)val); } 00443 00447 static EdbusData from_uint64(uint64_t val) { return EdbusData((uint64_t)val); } 00448 00452 static EdbusData from_double(double val) { return EdbusData((double)val); } 00453 00457 static EdbusData from_string(const char* val) { return EdbusData((const char*)val); } 00458 00462 static EdbusData from_object_path(const EdbusObjectPath& val) { return EdbusData(val); } 00463 00467 static EdbusData from_variant(const EdbusVariant& val) { return EdbusData(val); } 00468 00472 static EdbusData from_dict(const EdbusDict& val) { return EdbusData(val); } 00473 00477 static EdbusData from_array(const EdbusList& val) { return EdbusData(val); } 00478 00482 static EdbusData from_struct(const EdbusList& val) { return EdbusData(val); } 00483 }; 00484 00490 struct EdbusVariant { 00492 EdbusData value; 00493 }; 00494 00495 EDELIB_NS_END 00496 #endif