Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_wearable / dbus / include / dpl / dbus / dbus_signature.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        dbus_deserialization.h
18  * @author      Tomasz Swierczek (t.swierczek@samsung.com)
19  * @version     1.0
20  * @brief       Header file for DBus data signatures
21  */
22
23 #ifndef DPL_DBUS_SIGNATURE_H
24 #define DPL_DBUS_SIGNATURE_H
25
26 #include <dbus/dbus.h>
27 #include <string>
28
29 namespace DPL {
30 namespace DBus {
31 template<typename T>
32 struct SimpleType;
33
34 template<typename T>
35 struct Signature
36 {
37     static inline const char* value()
38     {
39         static const char signature[] =
40         { (char) SimpleType<T>::value, 0 };
41         return signature;
42     }
43 };
44
45 // signed integer types
46 template<int size>
47 struct __SignedIntegerType;
48
49 template<>
50 struct __SignedIntegerType<1>
51 {
52     static const int value = DBUS_TYPE_INT16;
53 };
54
55 template<>
56 struct __SignedIntegerType<2>
57 {
58     static const int value = DBUS_TYPE_INT16;
59 };
60
61 template<>
62 struct __SignedIntegerType<4>
63 {
64     static const int value = DBUS_TYPE_INT32;
65 };
66
67 template<>
68 struct __SignedIntegerType<8>
69 {
70     static const int value = DBUS_TYPE_INT64;
71 };
72
73 // unsigned integer types
74 template<int size>
75 struct __UnsignedIntegerType;
76
77 template<>
78 struct __UnsignedIntegerType<1>
79 {
80     static const int value = DBUS_TYPE_BYTE;
81 };
82 template<>
83 struct __UnsignedIntegerType<2>
84 {
85     static const int value = DBUS_TYPE_UINT16;
86 };
87 template<>
88 struct __UnsignedIntegerType<4>
89 {
90     static const int value = DBUS_TYPE_UINT32;
91 };
92 template<>
93 struct __UnsignedIntegerType<8>
94 {
95     static const int value = DBUS_TYPE_UINT64;
96 };
97
98 // basic types
99 template<>
100 struct SimpleType<bool>
101 {
102     static const int value = DBUS_TYPE_BOOLEAN;
103 };
104
105 template<>
106 struct SimpleType<char>
107 {
108     static const int value = __UnsignedIntegerType<sizeof(char)>::value;
109 };
110
111 template<>
112 struct SimpleType<signed char>
113 {
114     static const int value = __SignedIntegerType<sizeof(signed char)>::value;
115 };
116
117 template<>
118 struct SimpleType<unsigned char>
119 {
120     static const int value =
121         __UnsignedIntegerType<sizeof(unsigned char)>::value;
122 };
123
124 template<>
125 struct SimpleType<short>
126 {
127     static const int value = __SignedIntegerType<sizeof(short)>::value;
128 };
129
130 template<>
131 struct SimpleType<unsigned short>
132 {
133     static const int value =
134         __UnsignedIntegerType<sizeof(unsigned short)>::value;
135 };
136
137 template<>
138 struct SimpleType<int>
139 {
140     static const int value = __SignedIntegerType<sizeof(int)>::value;
141 };
142
143 template<>
144 struct SimpleType<unsigned int>
145 {
146     static const int value =
147         __UnsignedIntegerType<sizeof(unsigned int)>::value;
148 };
149
150 template<>
151 struct SimpleType<long>
152 {
153     static const int value = __SignedIntegerType<sizeof(long)>::value;
154 };
155
156 template<>
157 struct SimpleType<unsigned long>
158 {
159     static const int value =
160         __UnsignedIntegerType<sizeof(unsigned long)>::value;
161 };
162
163 template<>
164 struct SimpleType<long long>
165 {
166     static const int value = __SignedIntegerType<sizeof(long long)>::value;
167 };
168
169 template<>
170 struct SimpleType<unsigned long long>
171 {
172     static const int value = __UnsignedIntegerType<
173             sizeof(unsigned long long)>::value;
174 };
175
176 template<>
177 struct SimpleType<float>
178 {
179     static const int value = DBUS_TYPE_DOUBLE;
180 };
181
182 template<>
183 struct SimpleType<double>
184 {
185     static const int value = DBUS_TYPE_DOUBLE;
186 };
187
188 template<>
189 struct SimpleType<const char *>
190 {
191     static const int value = DBUS_TYPE_STRING;
192 };
193
194 template<>
195 struct SimpleType<char *>
196 {
197     static const int value = DBUS_TYPE_STRING;
198 };
199
200 template<>
201 struct SimpleType<std::string>
202 {
203     static const int value = DBUS_TYPE_STRING;
204 };
205
206 // STL containers signatures
207
208 // generic array
209 template<typename T>
210 struct ArraySignature
211 {
212     static inline const char* value()
213     {
214         static const std::string signature = std::string(
215                 DBUS_TYPE_ARRAY_AS_STRING) + Signature<T>::value();
216         return signature.c_str();
217     }
218 };
219
220 // std::vector
221 template<typename T>
222 struct Signature<std::vector<T> > : public ArraySignature<T>
223 {};
224
225 // std::list
226 template<typename T>
227 struct Signature<std::list<T> > : public ArraySignature<T>
228 {};
229
230 // std::set
231 template<typename T>
232 struct Signature<std::set<T> > : public ArraySignature<T>
233 {};
234
235 // std::pair
236 template<typename K, typename V>
237 struct Signature<std::pair<K, V> >
238 {
239     static inline const char* value()
240     {
241         static const std::string signature = std::string(
242                 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING)
243             + Signature<K>::value() + Signature<V>::value()
244             + DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
245         return signature.c_str();
246     }
247 };
248
249 // std::map
250 template<typename K, typename V>
251 struct Signature<std::map<K, V> > : public ArraySignature<std::pair<K, V> >
252 {};
253 } // namespace DBus
254 } // namespace DPL
255
256 #endif // DPL_DBUS_SIGNATURE_H