rvm  1.11
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
types.h
Go to the documentation of this file.
1 #ifndef __types_h__
2 #define __types_h__
3 
4 #ifdef HAVE_STDLIB_H
5 #include <stdlib.h>
6 #endif
7 
8 /** \file types.h Basic types definitions and templates. */
9 
10 // ----------------------------------------------------------------------------
11 
12 /**
13  \typedef
14  Define a 8-bit unsigned integer type.
15 
16  The following code, along with tests performed by the GNU Autoconf
17  scripts, define a system-independent 8-bit unsigned integer.
18  */
19 #if SIZEOF_UNSIGNED_CHAR == 1
20  typedef unsigned char uint8;
21 #elif SIZEOF_UNSIGNED_SHORT == 1
22  typedef unsigned short uint8;
23 #elif SIZEOF_UNSIGNED_INT == 1
24  typedef unsigned int uint8;
25 #elif SIZEOF_UNSIGNED_LONG == 1
26  typedef unsigned long uint8;
27 #elif SIZEOF_UNSIGNED_LONG_LONG == 1
28  typedef unsigned long long uint8;
29 #else
30 # error *** ERROR: No 8-bit type found to use as uint8
31 #endif
32 
33 /**
34  \typedef
35  Define a 16-bit unsigned integer type.
36 
37  The following code, along with tests performed by the GNU Autoconf
38  scripts, define a system-independent 16-bit unsigned integer.
39  */
40 #if SIZEOF_UNSIGNED_CHAR == 2
41  typedef unsigned char uint16;
42 #elif SIZEOF_UNSIGNED_SHORT == 2
43  typedef unsigned short uint16;
44 #elif SIZEOF_UNSIGNED_INT == 2
45  typedef unsigned int uint16;
46 #elif SIZEOF_UNSIGNED_LONG == 2
47  typedef unsigned long uint16;
48 #elif SIZEOF_UNSIGNED_LONG_LONG == 2
49  typedef unsigned long long uint16;
50 #else
51 # error *** ERROR: No 16-bit type found to use as uint16
52 #endif
53 
54 /**
55  \typedef
56  Define a 32-bit unsigned integer type.
57 
58  The following code, along with tests performed by the GNU Autoconf
59  scripts, define a system-independent 32-bit unsigned integer.
60  */
61 #if SIZEOF_UNSIGNED_CHAR == 4
62  typedef unsigned char uint32;
63 #elif SIZEOF_UNSIGNED_SHORT == 4
64  typedef unsigned short uint32;
65 #elif SIZEOF_UNSIGNED_INT == 4
66  typedef unsigned int uint32;
67 #elif SIZEOF_UNSIGNED_LONG == 4
68  typedef unsigned long uint32;
69 #elif SIZEOF_UNSIGNED_LONG_LONG == 4
70  typedef unsigned long long uint32;
71 #else
72 # error *** ERROR: No 32-bit type found to use as uint32
73 #endif
74 
75 /**
76  \typedef
77  Define a 64-bit unsigned integer type.
78 
79  The following code, along with tests performed by the GNU Autoconf
80  scripts, define a system-independent 64-bit unsigned integer.
81  */
82 #if SIZEOF_UNSIGNED_CHAR == 8
83  typedef unsigned char uint64;
84 #elif SIZEOF_UNSIGNED_SHORT == 8
85  typedef unsigned short uint64;
86 #elif SIZEOF_UNSIGNED_INT == 8
87  typedef unsigned int uint64;
88 #elif SIZEOF_UNSIGNED_LONG == 8
89  typedef unsigned long uint64;
90 #elif SIZEOF_UNSIGNED_LONG_LONG == 8
91  typedef unsigned long long uint64;
92 #else
93 # error *** ERROR: No 64-bit type found to use as uint64
94 #endif
95 
96 // ---------------------------------------------------------------------------
97 
98 /** Return false for any variable that is not a char */
99 template<typename T>
100 static bool is_signed_char(const T& a_arg)
101 { return(false); }
102 
103 /** Return true for any variable that is a char */
104 // template<>
105 bool is_signed_char(const char& a_arg);
106 // { return(true); }
107 
108 /** Return false for any variable that is not an unsigned char */
109 template<typename T>
110 static bool is_unsigned_char(const T& a_arg)
111 { return(false); }
112 
113 /** Return true for any variable that is an unsigned char */
114 // template<>
115 bool is_unsigned_char(const unsigned char& a_arg);
116 // { return(true); }
117 
118 /** Return true for any variable that is either a signed or unsigned char */
119 template<typename T>
120 static bool is_char(const T& a_arg)
121 { return(is_signed_char(a_arg) || is_unsigned_char(a_arg)); }
122 
123 // -----
124 
125 /** Return false for any variable that is not a short */
126 template<typename T>
127 static bool is_signed_short(const T& a_arg)
128 { return(false); }
129 
130 /** Return true for any variable that is a short */
131 // template<>
132 bool is_signed_short(const short& a_arg);
133 // { return(true); }
134 
135 /** Return false for any variable that is not an unsigned short */
136 template<typename T>
137 static bool is_unsigned_short(const T& a_arg)
138 { return(false); }
139 
140 /** Return true for any variable that is an unsigned short */
141 // template<>
142 bool is_unsigned_short(const unsigned short& a_arg);
143 // { return(true); }
144 
145 /** Return true for any variable that is either a signed or unsigned short */
146 template<typename T>
147 static bool is_short(const T& a_arg)
148 { return(is_signed_short(a_arg) || is_unsigned_short(a_arg)); }
149 
150 // -----
151 
152 /** Return false for any variable that is not a int */
153 template<typename T>
154 static bool is_signed_int(const T& a_arg)
155 { return(false); }
156 
157 /** Return true for any variable that is a int */
158 // template<>
159 bool is_signed_int(const int& a_arg);
160 // { return(true); }
161 
162 /** Return false for any variable that is not an unsigned int */
163 template<typename T>
164 static bool is_unsigned_int(const T& a_arg)
165 { return(false); }
166 
167 /** Return true for any variable that is an unsigned int */
168 // template<>
169 bool is_unsigned_int(const unsigned int& a_arg);
170 // { return(true); }
171 
172 /** Return true for any variable that is either a signed or unsigned int */
173 template<typename T>
174 static bool is_int(const T& a_arg)
175 { return(is_signed_int(a_arg) || is_unsigned_int(a_arg)); }
176 
177 // -----
178 
179 /** Return false for any variable that is not a long */
180 template<typename T>
181 static bool is_signed_long(const T& a_arg)
182 { return(false); }
183 
184 /** Return true for any variable that is a long */
185 // template<>
186 bool is_signed_long(const long& a_arg);
187 // { return(true); }
188 
189 /** Return false for any variable that is not an unsigned long */
190 template<typename T>
191 static bool is_unsigned_long(const T& a_arg)
192 { return(false); }
193 
194 /** Return true for any variable that is an unsigned long */
195 // template<>
196 bool is_unsigned_long(const unsigned long& a_arg);
197 // { return(true); }
198 
199 /** Return true for any variable that is either a signed or unsigned long */
200 template<typename T>
201 static bool is_long(const T& a_arg)
202 { return(is_signed_long(a_arg) || is_unsigned_long(a_arg)); }
203 
204 // -----
205 
206 /** Return false for any variable that is not a long long */
207 template<typename T>
208 static bool is_signed_long_long(const T& a_arg)
209 { return(false); }
210 
211 /** Return true for any variable that is a long long */
212 // template<>
213 bool is_signed_long_long(const long long& a_arg);
214 // { return(true); }
215 
216 /** Return false for any variable that is not an unsigned long long */
217 template<typename T>
218 static bool is_unsigned_long_long(const T& a_arg)
219 { return(false); }
220 
221 /** Return true for any variable that is an unsigned long long */
222 // template<>
223 bool is_unsigned_long_long(const unsigned long long& a_arg);
224 // { return(true); }
225 
226 /** Return true for any variable that is either a signed or unsigned long long */
227 template<typename T>
228 static bool is_long_long(const T& a_arg)
229 { return(is_signed_long_long(a_arg) || is_unsigned_long_long(a_arg)); }
230 
231 // -----
232 
233 /** Return false for any variable that is not a float */
234 template<typename T>
235 static bool is_float(const T& a_arg)
236 { return(false); }
237 
238 /** Return true for any variable that is a float */
239 // template<>
240 bool is_float(const float& a_arg);
241 // { return(true); }
242 
243 // -----
244 
245 /** Return false for any variable that is not a double */
246 template<typename T>
247 static bool is_double(const T& a_arg)
248 { return(false); }
249 
250 /** Return true for any variable that is a double */
251 // template<>
252 bool is_double(const double& a_arg);
253 // { return(true); }
254 
255 // -----
256 
257 /** Return false for any variable that is not a bool */
258 template<typename T>
259 static bool is_bool(const T& a_arg)
260 { return(false); }
261 
262 /** Return true for any variable that is a bool */
263 // template<>
264 bool is_bool(const bool& a_arg);
265 // { return(true); }
266 
267 // -----
268 
269 /** Return true for any variable that is a signed type */
270 template<typename T>
271 static bool is_signed(const T& a_arg)
272 {
273  return(
274  is_signed_char(a_arg)
275  || is_signed_short(a_arg)
276  || is_signed_int(a_arg)
277  || is_signed_long(a_arg)
278  || is_signed_long_long(a_arg)
279  || is_float(a_arg)
280  || is_double(a_arg)
281  );
282 }
283 
284 /** Return true for any variable that is an unsigned type */
285 template<typename T>
286 static bool is_unsigned(const T& a_arg)
287 {
288  return(
289  is_unsigned_char(a_arg)
290  || is_unsigned_short(a_arg)
291  || is_unsigned_int(a_arg)
292  || is_unsigned_long(a_arg)
293  || is_unsigned_long_long(a_arg)
294  );
295 }
296 
297 // ----------------------------------------------------------------------------
298 
299 template<typename T>
300 static const char * type_name(const T & a_arg)
301 { return("unknown"); }
302 
303 // template<>
304 const char * type_name(const unsigned char & a_arg);
305 // { return("unsigned char"); }
306 
307 // template<>
308 const char * type_name(const char & a_arg);
309 // { return("char"); }
310 
311 // template<>
312 const char * type_name(const unsigned short & a_arg);
313 // { return("unsigned short"); }
314 
315 // template<>
316 const char * type_name(const short & a_arg);
317 // { return("short"); }
318 
319 // template<>
320 const char * type_name(const unsigned int & a_arg);
321 // { return("unsigned int"); }
322 
323 // template<>
324 const char * type_name(const int & a_arg);
325 // { return("int"); }
326 
327 // template<>
328 const char * type_name(const unsigned long & a_arg);
329 // { return("unsigned long"); }
330 
331 // template<>
332 const char * type_name(const long & a_arg);
333 // { return("long"); }
334 
335 // template<>
336 const char * type_name(const unsigned long long & a_arg);
337 // { return("unsigned long long"); }
338 
339 // template<>
340 const char * type_name(const long long & a_arg);
341 // { return("long long"); }
342 
343 // template<>
344 const char * type_name(const float & a_arg);
345 // { return("float"); }
346 
347 // template<>
348 const char * type_name(const double & a_arg);
349 // { return("double"); }
350 
351 // template<>
352 const char * type_name(const bool & a_arg);
353 // { return("bool"); }
354 
355 // ----------------------------------------------------------------------------
356 
357 #endif
static bool is_signed_short(const T &a_arg)
Return false for any variable that is not a short.
Definition: types.h:127
static bool is_long_long(const T &a_arg)
Return true for any variable that is either a signed or unsigned long long.
Definition: types.h:228
static bool is_double(const T &a_arg)
Return false for any variable that is not a double.
Definition: types.h:247
static bool is_unsigned_long(const T &a_arg)
Return false for any variable that is not an unsigned long.
Definition: types.h:191
static bool is_unsigned_short(const T &a_arg)
Return false for any variable that is not an unsigned short.
Definition: types.h:137
static bool is_unsigned(const T &a_arg)
Return true for any variable that is an unsigned type.
Definition: types.h:286
static bool is_long(const T &a_arg)
Return true for any variable that is either a signed or unsigned long.
Definition: types.h:201
static bool is_signed_char(const T &a_arg)
Return false for any variable that is not a char.
Definition: types.h:100
static bool is_unsigned_long_long(const T &a_arg)
Return false for any variable that is not an unsigned long long.
Definition: types.h:218
static bool is_signed_int(const T &a_arg)
Return false for any variable that is not a int.
Definition: types.h:154
static bool is_unsigned_int(const T &a_arg)
Return false for any variable that is not an unsigned int.
Definition: types.h:164
static bool is_unsigned_char(const T &a_arg)
Return false for any variable that is not an unsigned char.
Definition: types.h:110
static bool is_short(const T &a_arg)
Return true for any variable that is either a signed or unsigned short.
Definition: types.h:147
static bool is_signed(const T &a_arg)
Return true for any variable that is a signed type.
Definition: types.h:271
static bool is_signed_long(const T &a_arg)
Return false for any variable that is not a long.
Definition: types.h:181
static bool is_signed_long_long(const T &a_arg)
Return false for any variable that is not a long long.
Definition: types.h:208
static bool is_char(const T &a_arg)
Return true for any variable that is either a signed or unsigned char.
Definition: types.h:120
static bool is_int(const T &a_arg)
Return true for any variable that is either a signed or unsigned int.
Definition: types.h:174
static bool is_float(const T &a_arg)
Return false for any variable that is not a float.
Definition: types.h:235
static bool is_bool(const T &a_arg)
Return false for any variable that is not a bool.
Definition: types.h:259
static const char * type_name(const T &a_arg)
Definition: types.h:300