dbus-cxx logo
types.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007,2008,2009,2010 by Rick L. Vinyard, Jr. *
3  * rvinyard@cs.nmsu.edu *
4  * *
5  * This file is part of the dbus-cxx library. *
6  * *
7  * The dbus-cxx library is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU General Public License *
9  * version 3 as published by the Free Software Foundation. *
10  * *
11  * The dbus-cxx library is distributed in the hope that it will be *
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty *
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this software. If not see <http://www.gnu.org/licenses/>. *
18  ***************************************************************************/
19 #include <stdint.h>
20 #include <typeinfo>
21 #include <string>
22 
23 #include <sigc++/sigc++.h>
24 
25 #include <dbus-cxx/enums.h>
26 #include <dbus-cxx/path.h>
27 #include <dbus-cxx/signature.h>
29 
30 #ifndef DBUSCXX_TYPES_H
31 #define DBUSCXX_TYPES_H
32 
33 namespace DBus
34 {
35 
36  typedef sigc::nil nil;
37 
38  inline Type type( uint8_t ) { return TYPE_BYTE; }
39  inline Type type( bool ) { return TYPE_BOOLEAN; }
40  inline Type type( int16_t ) { return TYPE_INT16; }
41  inline Type type( uint16_t ) { return TYPE_UINT16; }
42  inline Type type( int32_t ) { return TYPE_INT32; }
43  inline Type type( uint32_t ) { return TYPE_UINT32; }
44  inline Type type( int64_t ) { return TYPE_INT64; }
45  inline Type type( uint64_t ) { return TYPE_UINT64; }
46  inline Type type( double ) { return TYPE_DOUBLE; }
47  inline Type type( const std::string& ) { return TYPE_STRING; }
48  inline Type type( const char* ) { return TYPE_STRING; }
49  inline Type type( Path ) { return TYPE_OBJECT_PATH; }
50  inline Type type( Signature ) { return TYPE_SIGNATURE; }
51 template <class T>
52  inline Type type( Variant<T> ) { return TYPE_VARIANT; }
53  inline Type type( FileDescriptor ) { return TYPE_UNIX_FD; }
54 
55  inline Type type( char ) { return TYPE_BYTE; }
56  inline Type type( int8_t ) { return TYPE_BYTE; }
57 
58 #if DBUS_CXX_SIZEOF_LONG_INT == 4
59  inline Type type( long int ) { return TYPE_INT32; }
60  inline Type type( long unsigned int ) { return TYPE_UINT32; }
61 #endif
62 
63  inline Type type( float ) { return TYPE_DOUBLE; }
64 
65  template <typename T>
66  inline Type type(const std::vector<T>&) { return TYPE_ARRAY; }
67 
68 // template <typename T> inline Type type(const std::vector<T>&) { return TYPE_ARRAY; }
69 
70 // template <typename T0>
71 // inline Type type( const Struct<T0>& ) { return TYPE_STRUCT; }
72 //
73 // template <typename T0, typename T1>
74 // inline Type type( const Struct<T0,T1>& ) { return TYPE_STRUCT; }
75 //
76 // template <typename T0, typename T1, typename T2>
77 // inline Type type( const Struct<T0,T1,T2>& ) { return TYPE_STRUCT; }
78 //
79 // template <typename T0, typename T1, typename T2, typename T3>
80 // inline Type type( const Struct<T0,T1,T2,T3>& ) { return TYPE_STRUCT; }
81 //
82 // template <typename T0, typename T1, typename T2, typename T3, typename T4>
83 // inline Type type( const Struct<T0,T1,T2,T3,T4>& ) { return TYPE_STRUCT; }
84 //
85 // template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
86 // inline Type type( const Struct<T0,T1,T2,T3,T4,T5>& ) { return TYPE_STRUCT; }
87 //
88 // template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
89 // inline Type type( const Struct<T0,T1,T2,T3,T4,T5,T6>& ) { return TYPE_STRUCT; }
90 
91  inline std::string type_string( uint8_t& ) { return "byte"; }
92  inline std::string type_string( int8_t& ) { return "byte"; }
93  inline std::string type_string( bool& ) { return "bool"; }
94  inline std::string type_string( int16_t& ) { return "int16_t"; }
95  inline std::string type_string( uint16_t& ) { return "uint16_t"; }
96  inline std::string type_string( int32_t& ) { return "int32_t"; }
97  inline std::string type_string( uint32_t& ) { return "uint32_t"; }
98  inline std::string type_string( int64_t& ) { return "int64_t"; }
99  inline std::string type_string( uint64_t& ) { return "uint64_t"; }
100  inline std::string type_string( double& ) { return "double"; }
101  inline std::string type_string( float& ) { return "double"; }
102  inline std::string type_string( std::string& ) { return "std::string"; }
103  inline std::string type_string( Path& ) { return "Path"; }
104  inline std::string type_string( Signature& ) { return "Signature"; }
105 template <class T>
106  inline std::string type_string( Variant<T>& ) { return "Variant"; }
107 template <class T>
108  inline std::string type_string( std::vector<T>& ) { return "Array"; }
109 // template <typename T> inline std::string type_string() { return 1; /* This is invalid; you must use one of the specializations only */}
110 /* template<> inline std::string type_string<uint8_t>() { return "byte"; }
111  template<> inline std::string type_string<int8_t>() { return "byte"; }
112  template<> inline std::string type_string<bool>() { return "boolean"; }
113  template<> inline std::string type_string<int16_t>() { return "int16_t"; }
114  template<> inline std::string type_string<uint16_t>() { return "uint16_t"; }
115  template<> inline std::string type_string<int32_t>() { return "int32_t"; }
116  template<> inline std::string type_string<uint32_t>() { return "uint32_t"; }
117  template<> inline std::string type_string<int64_t>() { return "int64_t"; }
118  template<> inline std::string type_string<uint64_t>() { return "uint64_t"; }
119  template<> inline std::string type_string<double>() { return "double"; }
120  template<> inline std::string type_string<float>() { return "double"; }
121  template<> inline std::string type_string<std::string>() { return "std::string"; }
122  template<> inline std::string type_string<Path>() { return "Path"; }
123  template<> inline std::string type_string<Signature>() { return "Signature"; }
124  template<> inline std::string type_string<Variant<class T>>() { return "Variant"; }
125 */
126  inline std::string type_string_from_code( DBus::Type t )
127  {
128  switch ( t )
129  {
130  case TYPE_BYTE:
131  return "uint8_t";
132  case TYPE_BOOLEAN:
133  return "bool";
134  case TYPE_INT16:
135  return "int16_t";
136  case TYPE_UINT16:
137  return "uint16_t";
138  case TYPE_INT32:
139  return "int32_t";
140  case TYPE_UINT32:
141  return "uint32_t";
142  case TYPE_INT64:
143  return "int64_t";
144  case TYPE_UINT64:
145  return "uint64_t";
146  case TYPE_DOUBLE:
147  return "double";
148  case TYPE_STRING:
149  return "std::string";
150  case TYPE_OBJECT_PATH:
151  return "DBus::Path";
152  case TYPE_SIGNATURE:
153  return "DBus::Signature";
154  case TYPE_ARRAY:
155  return "std::vector";
156  case TYPE_VARIANT:
157  return "DBus::Variant<>";
158  case TYPE_STRUCT:
159  return "Struct";
160  case TYPE_DICT_ENTRY:
161  return "std::pair<>";
162  default:
163  break;
164  }
165  return std::string("Invalid");
166  }
167 
168  inline
170  {
171  return (Type)(n);
172  }
173 
174 
175 }
176 
177 #endif
Definition: enums.h:54
sigc::nil nil
Definition: types.h:36
Definition: enums.h:55
Definition: enums.h:44
Definition: enums.h:48
Definition: accumulators.h:24
Definition: enums.h:45
Definition: enums.h:49
Definition: enums.h:47
Definition: enums.h:60
Definition: enums.h:51
Definition: enums.h:52
A Variant is a type of DBus object that can be one of several different types of normal DBus object...
Definition: variant.h:33
Definition: enums.h:57
Type checked_type_cast(int n)
Definition: types.h:169
std::string type_string_from_code(DBus::Type t)
Definition: types.h:126
Definition: enums.h:56
Definition: enums.h:59
Definition: enums.h:58
std::string type_string(uint8_t &)
Definition: types.h:91
Definition: enums.h:46
A FileDescriptor holds a UNIX file descriptor that can be passed between processes.
Definition: filedescriptor.h:30
Type
Definition: enums.h:41
Definition: path.h:31
Definition: signature.h:37
Type type(uint8_t)
Definition: types.h:38
Definition: enums.h:50
Definition: enums.h:53

Generated on Sun Mar 19 2017 14:54:27 for dbus-cxx by doxygen 1.8.8