00001 /*************************************************************************** 00002 * Copyright (C) 2007,2008,2009,2010 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the dbus-cxx library. * 00006 * * 00007 * The dbus-cxx library is free software; you can redistribute it and/or * 00008 * modify it under the terms of the GNU General Public License * 00009 * version 3 as published by the Free Software Foundation. * 00010 * * 00011 * The dbus-cxx library is distributed in the hope that it will be * 00012 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * 00013 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this software. If not see <http://www.gnu.org/licenses/>. * 00018 ***************************************************************************/ 00019 #include <typeinfo> 00020 #include <string> 00021 00022 #include <sigc++/sigc++.h> 00023 00024 #include <dbus-cxx/enums.h> 00025 #include <dbus-cxx/path.h> 00026 #include <dbus-cxx/signature.h> 00027 00028 #ifndef DBUSCXX_TYPES_H 00029 #define DBUSCXX_TYPES_H 00030 00031 namespace DBus 00032 { 00033 00034 typedef sigc::nil nil; 00035 00036 inline Type type( uint8_t ) { return TYPE_BYTE; } 00037 inline Type type( bool ) { return TYPE_BOOLEAN; } 00038 inline Type type( int16_t ) { return TYPE_INT16; } 00039 inline Type type( uint16_t ) { return TYPE_UINT16; } 00040 inline Type type( int32_t ) { return TYPE_INT32; } 00041 inline Type type( uint32_t ) { return TYPE_UINT32; } 00042 inline Type type( int64_t ) { return TYPE_INT64; } 00043 inline Type type( uint64_t ) { return TYPE_UINT64; } 00044 inline Type type( double ) { return TYPE_DOUBLE; } 00045 inline Type type( const std::string& ) { return TYPE_STRING; } 00046 inline Type type( const char* ) { return TYPE_STRING; } 00047 inline Type type( Path ) { return TYPE_OBJECT_PATH; } 00048 inline Type type( Signature ) { return TYPE_SIGNATURE; } 00049 // inline Type type( Variant ) { return TYPE_VARIANT; } 00050 00051 inline Type type( char ) { return TYPE_BYTE; } 00052 inline Type type( int8_t ) { return TYPE_BYTE; } 00053 00054 #if DBUS_CXX_SIZEOF_LONG_INT == 4 00055 inline Type type( long int ) { return TYPE_INT32; } 00056 inline Type type( long unsigned int ) { return TYPE_UINT32; } 00057 #endif 00058 00059 inline Type type( float ) { return TYPE_DOUBLE; } 00060 00061 template <typename T> inline Type type() { return std::string(); /* This is 00062 invalid; you must use one of the specializations only */} 00063 template<> inline Type type<uint8_t>() { return TYPE_BYTE; } 00064 template<> inline Type type<bool>() { return TYPE_BOOLEAN; } 00065 template<> inline Type type<int16_t>() { return TYPE_INT16; } 00066 template<> inline Type type<uint16_t>() { return TYPE_UINT16; } 00067 template<> inline Type type<int32_t>() { return TYPE_INT32; } 00068 template<> inline Type type<uint32_t>() { return TYPE_UINT32; } 00069 template<> inline Type type<int64_t>() { return TYPE_INT64; } 00070 template<> inline Type type<uint64_t>() { return TYPE_UINT64; } 00071 template<> inline Type type<double>() { return TYPE_DOUBLE; } 00072 template<> inline Type type<const std::string&>() { return TYPE_STRING; } 00073 template<> inline Type type<const char*>() { return TYPE_STRING; } 00074 template<> inline Type type<Path>() { return TYPE_OBJECT_PATH; } 00075 template<> inline Type type<Signature>() { return TYPE_SIGNATURE; } 00076 // template<> inline Type type<Variant>() { return TYPE_VARIANT; } 00077 00078 template<> inline Type type<char>() { return TYPE_BYTE; } 00079 template<> inline Type type<int8_t>() { return TYPE_BYTE; } 00080 00081 #if DBUS_CXX_SIZEOF_LONG_INT == 4 00082 template<> inline Type type<long int>() { return TYPE_INT32; } 00083 template<> inline Type type<long unsigned int>() { return TYPE_UINT32; } 00084 #endif 00085 00086 template<> inline Type type<float>() { return TYPE_DOUBLE; } 00087 00088 00089 // template <typename T> inline Type type(const std::vector<T>&) { return TYPE_ARRAY; } 00090 00091 // template <typename T0> 00092 // inline Type type( const Struct<T0>& ) { return TYPE_STRUCT; } 00093 // 00094 // template <typename T0, typename T1> 00095 // inline Type type( const Struct<T0,T1>& ) { return TYPE_STRUCT; } 00096 // 00097 // template <typename T0, typename T1, typename T2> 00098 // inline Type type( const Struct<T0,T1,T2>& ) { return TYPE_STRUCT; } 00099 // 00100 // template <typename T0, typename T1, typename T2, typename T3> 00101 // inline Type type( const Struct<T0,T1,T2,T3>& ) { return TYPE_STRUCT; } 00102 // 00103 // template <typename T0, typename T1, typename T2, typename T3, typename T4> 00104 // inline Type type( const Struct<T0,T1,T2,T3,T4>& ) { return TYPE_STRUCT; } 00105 // 00106 // template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5> 00107 // inline Type type( const Struct<T0,T1,T2,T3,T4,T5>& ) { return TYPE_STRUCT; } 00108 // 00109 // template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> 00110 // inline Type type( const Struct<T0,T1,T2,T3,T4,T5,T6>& ) { return TYPE_STRUCT; } 00111 00112 inline std::string type_string( uint8_t ) { return "byte"; } 00113 inline std::string type_string( bool ) { return "boolean"; } 00114 inline std::string type_string( int16_t ) { return "int16_t"; } 00115 inline std::string type_string( uint16_t ) { return "uint16_t"; } 00116 inline std::string type_string( int32_t ) { return "int32_t"; } 00117 inline std::string type_string( uint32_t ) { return "uint32_t"; } 00118 inline std::string type_string( int64_t ) { return "int64_t"; } 00119 inline std::string type_string( uint64_t ) { return "uint64_t"; } 00120 inline std::string type_string( double ) { return "double"; } 00121 inline std::string type_string( std::string ) { return "std::string"; } 00122 inline std::string type_string( Path ) { return "Path"; } 00123 inline std::string type_string( Signature ) { return "Signature"; } 00124 // inline std::string type_string( Variant ) { return "Variant"; } 00125 00126 template <typename T> inline std::string type_string() { return 1; /* This is invalid; you must use one of the specializations only */} 00127 template<> inline std::string type_string<uint8_t>() { return "byte"; } 00128 template<> inline std::string type_string<bool>() { return "boolean"; } 00129 template<> inline std::string type_string<int16_t>() { return "int16_t"; } 00130 template<> inline std::string type_string<uint16_t>() { return "uint16_t"; } 00131 template<> inline std::string type_string<int32_t>() { return "int32_t"; } 00132 template<> inline std::string type_string<uint32_t>() { return "uint32_t"; } 00133 template<> inline std::string type_string<int64_t>() { return "int64_t"; } 00134 template<> inline std::string type_string<uint64_t>() { return "uint64_t"; } 00135 template<> inline std::string type_string<double>() { return "double"; } 00136 template<> inline std::string type_string<std::string>() { return "std::string"; } 00137 template<> inline std::string type_string<Path>() { return "Path"; } 00138 template<> inline std::string type_string<Signature>() { return "Signature"; } 00139 // template<> inline std::string type_string<Variant>() { return "Variant"; } 00140 00141 inline std::string type_string_from_code( DBus::Type t ) 00142 { 00143 switch ( t ) 00144 { 00145 case TYPE_BYTE: 00146 return "byte"; 00147 case TYPE_BOOLEAN: 00148 return "boolean"; 00149 case TYPE_INT16: 00150 return "int16_t"; 00151 case TYPE_UINT16: 00152 return "uint16_t"; 00153 case TYPE_INT32: 00154 return "int32_t"; 00155 case TYPE_UINT32: 00156 return "uint32_t"; 00157 case TYPE_INT64: 00158 return "int64_t"; 00159 case TYPE_UINT64: 00160 return "uint64_t"; 00161 case TYPE_DOUBLE: 00162 return "double"; 00163 case TYPE_STRING: 00164 return "string"; 00165 case TYPE_OBJECT_PATH: 00166 return "Path"; 00167 case TYPE_SIGNATURE: 00168 return "Signature"; 00169 case TYPE_ARRAY: 00170 return "Array"; 00171 case TYPE_VARIANT: 00172 return "Variant"; 00173 case TYPE_STRUCT: 00174 return "Struct"; 00175 case TYPE_DICT_ENTRY: 00176 return "Dict Entry"; 00177 default: 00178 break; 00179 } 00180 return std::string("Invalid"); 00181 } 00182 00183 inline 00184 Type checked_type_cast(int n) 00185 { 00186 return (Type)(n); 00187 } 00188 00189 00190 } 00191 00192 #endif