- Main Page
- Related Pages
- Modules
- Files

- File List

_detail.hpp
Go to the documentation of this file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef glm_core_detail
30 #define glm_core_detail
31
32 #include "setup.hpp"
33 #include <cassert>
34 #if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
35 #include <cstdint>
36 #endif
37
38 namespace glm{
39 namespace detail
40 {
41 class half;
42
43 #if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) // C99 detected, 64 bit types available
44 typedef int64_t sint64;
45 typedef uint64_t uint64;
46 #elif(GLM_COMPILER & GLM_COMPILER_VC)
47 typedef signed __int64 sint64;
48 typedef unsigned __int64 uint64;
49 #elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC | GLM_COMPILER_CLANG))
50 __extension__ typedef signed long long sint64;
51 __extension__ typedef unsigned long long uint64;
52 #elif(GLM_COMPILER & GLM_COMPILER_BC)
53 typedef Int64 sint64;
54 typedef Uint64 uint64;
55 #else//unknown compiler
56 typedef signed long long sint64;
57 typedef unsigned long long uint64;
58 #endif//GLM_COMPILER
59
60 template<bool C>
61 struct If
62 {
63 template<typename F, typename T>
64 static GLM_FUNC_QUALIFIER T apply(F functor, const T& val)
65 {
66 return functor(val);
67 }
68 };
69
70 template<>
71 struct If<false>
72 {
73 template<typename F, typename T>
74 static GLM_FUNC_QUALIFIER T apply(F, const T& val)
75 {
76 return val;
77 }
78 };
79
80 //template <typename T>
81 //struct traits
82 //{
83 // static const bool is_signed = false;
84 // static const bool is_float = false;
85 // static const bool is_vector = false;
86 // static const bool is_matrix = false;
87 // static const bool is_genType = false;
88 // static const bool is_genIType = false;
89 // static const bool is_genUType = false;
90 //};
91
92 //template <>
93 //struct traits<half>
94 //{
95 // static const bool is_float = true;
96 // static const bool is_genType = true;
97 //};
98
99 //template <>
100 //struct traits<float>
101 //{
102 // static const bool is_float = true;
103 // static const bool is_genType = true;
104 //};
105
106 //template <>
107 //struct traits<double>
108 //{
109 // static const bool is_float = true;
110 // static const bool is_genType = true;
111 //};
112
113 //template <typename genType>
114 //struct desc
115 //{
116 // typedef genType type;
117 // typedef genType * pointer;
118 // typedef genType const* const_pointer;
119 // typedef genType const *const const_pointer_const;
120 // typedef genType *const pointer_const;
121 // typedef genType & reference;
122 // typedef genType const& const_reference;
123 // typedef genType const& param_type;
124
125 // typedef typename genType::value_type value_type;
126 // typedef typename genType::size_type size_type;
127 // static const typename size_type value_size;
128 //};
129
130 //template <typename genType>
131 //const typename desc<genType>::size_type desc<genType>::value_size = genType::value_size();
132
133 union uif32
134 {
135 GLM_FUNC_QUALIFIER uif32() :
136 i(0)
137 {}
138
139 GLM_FUNC_QUALIFIER uif32(float f) :
140 f(f)
141 {}
142
143 GLM_FUNC_QUALIFIER uif32(unsigned int i) :
144 i(i)
145 {}
146
147 float f;
148 unsigned int i;
149 };
150
151 union uif64
152 {
153 GLM_FUNC_QUALIFIER uif64() :
154 i(0)
155 {}
156
157 GLM_FUNC_QUALIFIER uif64(double f) :
158 f(f)
159 {}
160
161 GLM_FUNC_QUALIFIER uif64(uint64 i) :
162 i(i)
163 {}
164
165 double f;
166 uint64 i;
167 };
168
169 typedef uif32 uif;
170
172 // int
173
174 template <typename T>
175 struct is_int
176 {
177 enum is_int_enum
178 {
179 _YES = 0,
180 _NO = 1
181 };
182 };
183
184 #define GLM_DETAIL_IS_INT(T) \
185 template <> \
186 struct is_int<T> \
187 { \
188 enum is_int_enum \
189 { \
190 _YES = 1, \
191 _NO = 0 \
192 }; \
193 }
194
196 // uint
197
198 template <typename T>
199 struct is_uint
200 {
201 enum is_uint_enum
202 {
203 _YES = 0,
204 _NO = 1
205 };
206 };
207
208 #define GLM_DETAIL_IS_UINT(T) \
209 template <> \
210 struct is_uint<T> \
211 { \
212 enum is_uint_enum \
213 { \
214 _YES = 1, \
215 _NO = 0 \
216 }; \
217 }
218
219 //GLM_DETAIL_IS_UINT(unsigned long long)
220
222 // float
223
224 template <typename T>
225 struct is_float
226 {
227 enum is_float_enum
228 {
229 _YES = 0,
230 _NO = 1
231 };
232 };
233
234 #define GLM_DETAIL_IS_FLOAT(T) \
235 template <> \
236 struct is_float<T> \
237 { \
238 enum is_float_enum \
239 { \
240 _YES = 1, \
241 _NO = 0 \
242 }; \
243 }
244
245 GLM_DETAIL_IS_FLOAT(detail::half);
246 GLM_DETAIL_IS_FLOAT(float);
247 GLM_DETAIL_IS_FLOAT(double);
248 GLM_DETAIL_IS_FLOAT(long double);
249
251 // bool
252
253 template <typename T>
254 struct is_bool
255 {
256 enum is_bool_enum
257 {
258 _YES = 0,
259 _NO = 1
260 };
261 };
262
263 template <>
264 struct is_bool<bool>
265 {
266 enum is_bool_enum
267 {
268 _YES = 1,
269 _NO = 0
270 };
271 };
272
274 // vector
275
276 template <typename T>
277 struct is_vector
278 {
279 enum is_vector_enum
280 {
281 _YES = 0,
282 _NO = 1
283 };
284 };
285
286 # define GLM_DETAIL_IS_VECTOR(TYPE) \
287 template <typename T> \
288 struct is_vector<TYPE<T> > \
289 { \
290 enum is_vector_enum \
291 { \
292 _YES = 1, \
293 _NO = 0 \
294 }; \
295 }
296
298 // matrix
299
300 template <typename T>
301 struct is_matrix
302 {
303 enum is_matrix_enum
304 {
305 _YES = 0,
306 _NO = 1
307 };
308 };
309
310 #define GLM_DETAIL_IS_MATRIX(T) \
311 template <> \
312 struct is_matrix \
313 { \
314 enum is_matrix_enum \
315 { \
316 _YES = 1, \
317 _NO = 0 \
318 }; \
319 }
320
322 // type
323
324 template <typename T>
325 struct type
326 {
327 enum type_enum
328 {
329 is_float = is_float<T>::_YES,
330 is_int = is_int<T>::_YES,
331 is_uint = is_uint<T>::_YES,
332 is_bool = is_bool<T>::_YES
333 };
334 };
335
337 // type
338
339 typedef signed char int8;
340 typedef signed short int16;
341 typedef signed int int32;
342 typedef detail::sint64 int64;
343
344 typedef unsigned char uint8;
345 typedef unsigned short uint16;
346 typedef unsigned int uint32;
347 typedef detail::uint64 uint64;
348
349 typedef detail::half float16;
350 typedef float float32;
351 typedef double float64;
352
354 // float_or_int_trait
355
356 struct float_or_int_value
357 {
358 enum
359 {
360 GLM_ERROR,
361 GLM_FLOAT,
362 GLM_INT
363 };
364 };
365
366 template <typename T>
367 struct float_or_int_trait
368 {
369 enum{ID = float_or_int_value::GLM_ERROR};
370 };
371
372 template <>
373 struct float_or_int_trait<int8>
374 {
375 enum{ID = float_or_int_value::GLM_INT};
376 };
377
378 template <>
379 struct float_or_int_trait<int16>
380 {
381 enum{ID = float_or_int_value::GLM_INT};
382 };
383
384 template <>
385 struct float_or_int_trait<int32>
386 {
387 enum{ID = float_or_int_value::GLM_INT};
388 };
389
390 template <>
391 struct float_or_int_trait<int64>
392 {
393 enum{ID = float_or_int_value::GLM_INT};
394 };
395
396 template <>
397 struct float_or_int_trait<uint8>
398 {
399 enum{ID = float_or_int_value::GLM_INT};
400 };
401
402 template <>
403 struct float_or_int_trait<uint16>
404 {
405 enum{ID = float_or_int_value::GLM_INT};
406 };
407
408 template <>
409 struct float_or_int_trait<uint32>
410 {
411 enum{ID = float_or_int_value::GLM_INT};
412 };
413
414 template <>
415 struct float_or_int_trait<uint64>
416 {
417 enum{ID = float_or_int_value::GLM_INT};
418 };
419
420 template <>
421 struct float_or_int_trait<float16>
422 {
423 enum{ID = float_or_int_value::GLM_FLOAT};
424 };
425
426 template <>
427 struct float_or_int_trait<float32>
428 {
429 enum{ID = float_or_int_value::GLM_FLOAT};
430 };
431
432 template <>
433 struct float_or_int_trait<float64>
434 {
435 enum{ID = float_or_int_value::GLM_FLOAT};
436 };
437
438 }//namespace detail
439 }//namespace glm
440
441 #if((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2005))
442 # define GLM_DEPRECATED __declspec(deprecated)
443 # define GLM_ALIGN(x) __declspec(align(x))
444 # define GLM_ALIGNED_STRUCT(x) __declspec(align(x)) struct
445 # define GLM_RESTRICT __declspec(restrict)
446 # define GLM_RESTRICT_VAR __restrict
447 # define GLM_CONSTEXPR
448 #elif((GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC)) && (GLM_COMPILER >= GLM_COMPILER_GCC31))
449 # define GLM_DEPRECATED __attribute__((__deprecated__))
450 # define GLM_ALIGN(x) __attribute__((aligned(x)))
451 # define GLM_ALIGNED_STRUCT(x) struct __attribute__((aligned(x)))
452 # if(GLM_COMPILER >= GLM_COMPILER_GCC33)
453 # define GLM_RESTRICT __restrict__
454 # define GLM_RESTRICT_VAR __restrict__
455 # else
456 # define GLM_RESTRICT
457 # define GLM_RESTRICT_VAR
458 # endif
459 # define GLM_RESTRICT __restrict__
460 # define GLM_RESTRICT_VAR __restrict__
461 # if((GLM_COMPILER >= GLM_COMPILER_GCC47) && ((GLM_LANG & GLM_LANG_CXX0X) == GLM_LANG_CXX0X))
462 # define GLM_CONSTEXPR constexpr
463 # else
464 # define GLM_CONSTEXPR
465 # endif
466 #else
467 # define GLM_DEPRECATED
468 # define GLM_ALIGN
469 # define GLM_ALIGNED_STRUCT(x)
470 # define GLM_RESTRICT
471 # define GLM_RESTRICT_VAR
472 # define GLM_CONSTEXPR
473 #endif//GLM_COMPILER
474
475 #endif//glm_core_detail