cartobase 6.0.6
types.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef CARTOBASE_TYPE_TYPES_H
35#define CARTOBASE_TYPE_TYPES_H
36
39#include <string>
40#include <vector>
41#include <list>
42#include <map>
43#include <set>
44#include <complex>
45#include <typeinfo>
46
47
48/* these types are out of any namespace for 2 reasons:
49 - compatibility: they were in Aims without a namespace
50 - simplicity: they are types used in many places, they have to be short
51
52 BUT: they may conflict with system types
53*/
54
60class Void
61{
62public:
63 Void() { }
64 template<typename T> explicit Void( const T & ) { }
65
66 template<typename T> Void& operator = ( const T& ) { return *this; };
67};
68
69
70inline bool operator == ( const Void&, const Void& )
71{
72 return true;
73}
74
75inline std::ostream& operator << ( std::ostream& os, const Void& )
76{
77 return os;
78}
79
80inline std::istream& operator >> ( std::istream& is, Void& )
81{
82 return is;
83}
84
86typedef uint8_t byte;
88typedef unsigned short ushort;
90typedef uint32_t word;
92typedef unsigned int uint;
94typedef unsigned long ulong;
96typedef std::complex<float> cfloat;
98typedef std::complex<double> cdouble;
99
100
101namespace carto
102{
103
104 //-------------------//
105 // DataTypeCode<T> //
106 //-------------------//
107
110 template<class T> class DataTypeCode
111 {
112 // protected: // we'll make it protected later
113 public:
115
116 public:
117 static inline std::string objectType();
118 static inline std::string dataType();
119 static inline std::string name();
120 };
121
122
123#ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
124
125 //---------------------------//
126 // DataTypeCode<vector<T>> //
127 //---------------------------//
128
129 template<class T> class DataTypeCode< std::vector<T> >
130 {
131 public:
132 static inline std::string objectType()
133 { return( "vector" ); }
134 static inline std::string dataType()
135 { return( DataTypeCode<T>().dataType() ); }
136 static inline std::string name()
137 {
138 return std::string("vector of ") + DataTypeCode< T >::name();
139 }
140 };
141
142 //-------------------------//
143 // DataTypeCode<list<T>> //
144 //-------------------------//
145
146 template<class T> class DataTypeCode< std::list<T> >
147 {
148 public:
149 static inline std::string objectType()
150 { return( "list" ); }
151 static inline std::string dataType()
152 { return( DataTypeCode<T>().dataType() ); }
153 static inline std::string name()
154 {
155 return std::string("list of ") + DataTypeCode< T >::name();
156 }
157 };
158
159
160 //-------------------------//
161 // DataTypeCode<set<T>> //
162 //-------------------------//
163
164 template<class T> class DataTypeCode< std::set<T> >
165 {
166 public:
167 static inline std::string objectType()
168 { return( "set" ); }
169 static inline std::string dataType()
170 { return( DataTypeCode<T>().dataType() ); }
171 static inline std::string name()
172 {
173 return std::string("set of ") + DataTypeCode< T >::name();
174 }
175 };
176
177
178 //-------------------------//
179 // DataTypeCode<map<T,U>> //
180 //-------------------------//
181
182 template<typename T, typename U> class DataTypeCode< std::map<T,U> >
183 {
184 public:
185 static inline std::string objectType()
186 { return "map"; }
187 static inline std::string dataType()
188 { return DataTypeCode<U>::dataType(); }
189 static inline std::string name()
190 {
191 return std::string("map of ") + DataTypeCode< T >::name() + "_"
193 }
194 };
195
196
197 //---------------------------//
198 // DataTypeCode<rc_ptr<T>> //
199 //---------------------------//
200
201 template<typename T> class DataTypeCode< rc_ptr<T> >
202 {
203 public:
204 static inline std::string objectType()
205 { return "rc_ptr"; }
206 static inline std::string dataType()
207 { return DataTypeCode<T>::name(); }
208 static inline std::string name()
209 {
210 return std::string("rc_ptr of ") + DataTypeCode< T >::name();
211 }
212 };
213
214#endif // DOXYGEN_HIDE_INTERNAL_CLASSES
215
216
217 //-------------------//
218 // DataTypeCode<T> //
219 //-------------------//
220
221 //---------------------------------------------------------------------------
222 template<typename T>
223 inline std::string DataTypeCode<T>::objectType()
224 {
225 return "";
226 }
227
228 //---------------------------------------------------------------------------
229 template<typename T>
230 inline std::string DataTypeCode<T>::dataType()
231 {
232 return typeid( T ).name();
233 /*
234 T::make_compilation_error( "this is only here to cause an error: "
235 "this code should NEVER be compiled. "
236 "This function should always be specialized" );
237 return "undefined type";
238 */
239 }
240
241 //---------------------------------------------------------------------------
242 template<typename T>
243 inline std::string DataTypeCode<T>::name()
244 {
246 }
247
248
249 // specializations
250
251 //---------------------------------------------------------------------------
252 template<> inline std::string DataTypeCode<int8_t>::dataType()
253 {
254 return "S8";
255 }
256
257 //---------------------------------------------------------------------------
258 template<> inline std::string DataTypeCode<uint8_t>::dataType()
259 {
260 return "U8";
261 }
262
263 // ### remove after everything has been moved to intN_t/uintN_t
264#if !defined(__sun__) || !defined(_CHAR_IS_SIGNED)
265 //---------------------------------------------------------------------------
266 template<> inline std::string DataTypeCode<char>::dataType()
267 {
268 return "S8";
269 }
270#endif
271
272 //---------------------------------------------------------------------------
273 template<> inline std::string DataTypeCode<int16_t>::dataType()
274 {
275 return "S16";
276 }
277
278 //---------------------------------------------------------------------------
279 template<> inline std::string DataTypeCode<uint16_t>::dataType()
280 {
281 return "U16";
282 }
283
284 //---------------------------------------------------------------------------
285 template<> inline std::string DataTypeCode<int32_t>::dataType()
286 {
287 return "S32";
288 }
289
290 //---------------------------------------------------------------------------
291 template<> inline std::string DataTypeCode<uint32_t>::dataType()
292 {
293 return "U32";
294 }
295
296#ifdef CARTO_LONG_IS_DISTINCT
297 // ### remove after everything has been moved to intN_t/uintN_t
298 //---------------------------------------------------------------------------
299 template<> inline std::string DataTypeCode<long>::dataType()
300 {
301 return "LONG";
302 }
303
304 // ### remove after everything has been moved to intN_t/uintN_t
305 //---------------------------------------------------------------------------
306 template<> inline std::string DataTypeCode<unsigned long>::dataType()
307 {
308 return "ULONG";
309 }
310#endif
311
312 //---------------------------------------------------------------------------
313 template<> inline std::string DataTypeCode<int64_t>::dataType()
314 {
315 return "S64";
316 }
317
318 //---------------------------------------------------------------------------
319 template<> inline std::string DataTypeCode<uint64_t>::dataType()
320 {
321 return "U64";
322 }
323
324 //---------------------------------------------------------------------------
325 template<> inline std::string DataTypeCode<float>::dataType()
326 {
327 return "FLOAT";
328 // return "float";
329 }
330
331 //---------------------------------------------------------------------------
332 template<> inline std::string DataTypeCode<double>::dataType()
333 {
334 return "DOUBLE";
335 // return "double";
336 }
337
338 //---------------------------------------------------------------------------
339 template<> inline std::string DataTypeCode<cfloat>::dataType()
340 {
341 return "CFLOAT";
342 // return "cfloat";
343 }
344
345 //---------------------------------------------------------------------------
346 template<> inline std::string DataTypeCode<cdouble>::dataType()
347 {
348 return "CDOUBLE";
349 // return "cdouble";
350 }
351
352 //---------------------------------------------------------------------------
353 template<> inline std::string DataTypeCode<Void>::dataType()
354 {
355 return "VOID";
356 //return "void";
357 }
358
359 //---------------------------------------------------------------------------
360 template<> inline std::string DataTypeCode<bool>::dataType()
361 {
362 return "boolean";
363 }
364
365 //---------------------------------------------------------------------------
366 template<> inline std::string DataTypeCode<std::string>::dataType()
367 {
368 return "string";
369 }
370
371} // namespace carto
372
373#endif
Void does not contain anything.
Definition types.h:61
Void & operator=(const T &)
Definition types.h:66
Void(const T &)
Definition types.h:64
Void()
Definition types.h:63
static std::string dataType()
Definition types.h:206
static std::string name()
Definition types.h:208
static std::string objectType()
Definition types.h:204
static std::string objectType()
Definition types.h:149
static std::string dataType()
Definition types.h:151
static std::string name()
Definition types.h:153
static std::string dataType()
Definition types.h:187
static std::string objectType()
Definition types.h:185
static std::string dataType()
Definition types.h:169
static std::string objectType()
Definition types.h:167
static std::string name()
Definition types.h:171
static std::string objectType()
Definition types.h:132
static std::string dataType()
Definition types.h:134
static std::string name()
Definition types.h:243
static std::string objectType()
Definition types.h:223
static std::string dataType()
Definition types.h:230
Reference-counting pointer.
Definition rcptr.h:640
STL namespace.
uint32_t word
...
Definition types.h:90
bool operator==(const Void &, const Void &)
Definition types.h:70
std::complex< double > cdouble
Complex 64 bits float.
Definition types.h:98
unsigned long ulong
...
Definition types.h:94
unsigned int uint
...
Definition types.h:92
std::complex< float > cfloat
Complex 32 bits float.
Definition types.h:96
uint8_t byte
...
Definition types.h:86
unsigned short ushort
...
Definition types.h:88
std::ostream & operator<<(std::ostream &os, const Void &)
Definition types.h:75
std::istream & operator>>(std::istream &is, Void &)
Definition types.h:80