_detail.hpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 #ifndef glm_core_detail
00030 #define glm_core_detail
00031 
00032 #include "setup.hpp"
00033 #include <cassert>
00034 
00035 namespace glm{
00036 namespace detail
00037 {
00038         class thalf;
00039 
00040 #if(__STDC_VERSION__ >= 199901L) // C99 detected, 64 bit types available
00041         typedef int64_t                                                         sint64;
00042         typedef uint64_t                                                        uint64;
00043 #elif(GLM_COMPILER & GLM_COMPILER_VC)
00044         typedef signed __int64                                          sint64;
00045         typedef unsigned __int64                                        uint64;
00046 #elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC | GLM_COMPILER_CLANG))
00047         __extension__ typedef signed long long          sint64;
00048         __extension__ typedef unsigned long long        uint64;
00049 #elif(GLM_COMPILER & GLM_COMPILER_BC)
00050         typedef Int64                                                           sint64;
00051         typedef Uint64                                                          uint64;
00052 #else//unknown compiler
00053         typedef signed long     long                                    sint64;
00054         typedef unsigned long long                                      uint64;
00055 #endif//GLM_COMPILER
00056 
00057         template<bool C>
00058         struct If
00059         {
00060                 template<typename F, typename T>
00061                 static GLM_FUNC_QUALIFIER T apply(F functor, const T& val)
00062                 {
00063                         return functor(val);
00064                 }
00065         };
00066 
00067         template<>
00068         struct If<false>
00069         {
00070                 template<typename F, typename T>
00071                 static GLM_FUNC_QUALIFIER T apply(F, const T& val)
00072                 {
00073                         return val;
00074                 }
00075         };
00076 
00077         //template <typename T>
00078         //struct traits
00079         //{
00080         //      static const bool is_signed = false;
00081         //      static const bool is_float = false;
00082         //      static const bool is_vector = false;
00083         //      static const bool is_matrix = false;
00084         //      static const bool is_genType = false;
00085         //      static const bool is_genIType = false;
00086         //      static const bool is_genUType = false;
00087         //};
00088 
00089         //template <>
00090         //struct traits<half>
00091         //{
00092         //      static const bool is_float = true;
00093         //      static const bool is_genType = true;
00094         //};
00095 
00096         //template <>
00097         //struct traits<float>
00098         //{
00099         //      static const bool is_float = true;
00100         //      static const bool is_genType = true;
00101         //};
00102 
00103         //template <>
00104         //struct traits<double>
00105         //{
00106         //      static const bool is_float = true;
00107         //      static const bool is_genType = true;
00108         //};
00109 
00110         //template <typename genType>
00111         //struct desc
00112         //{
00113         //      typedef genType                                                 type;
00114         //      typedef genType *                                               pointer;
00115         //      typedef genType const*                                  const_pointer;
00116         //      typedef genType const *const                    const_pointer_const;
00117         //      typedef genType *const                                  pointer_const;
00118         //      typedef genType &                                               reference;
00119         //      typedef genType const&                                  const_reference;
00120         //      typedef genType const&                                  param_type;
00121 
00122         //      typedef typename genType::value_type    value_type;
00123         //      typedef typename genType::size_type             size_type;
00124         //      static const typename size_type                 value_size;
00125         //};
00126 
00127         //template <typename genType>
00128         //const typename desc<genType>::size_type desc<genType>::value_size = genType::value_size();
00129 
00130         union uif32
00131         {
00132                 GLM_FUNC_QUALIFIER uif32() :
00133                         i(0)
00134                 {}
00135 
00136                 GLM_FUNC_QUALIFIER uif32(float f) :
00137                         f(f)
00138                 {}
00139 
00140                 GLM_FUNC_QUALIFIER uif32(unsigned int i) :
00141                         i(i)
00142                 {}
00143 
00144                 float f;
00145                 unsigned int i;
00146         };
00147 
00148         union uif64
00149         {
00150                 GLM_FUNC_QUALIFIER uif64() :
00151                         i(0)
00152                 {}
00153 
00154                 GLM_FUNC_QUALIFIER uif64(double f) :
00155                         f(f)
00156                 {}
00157 
00158                 GLM_FUNC_QUALIFIER uif64(uint64 i) :
00159                         i(i)
00160                 {}
00161 
00162                 double f;
00163                 uint64 i;
00164         };
00165 
00166         typedef uif32 uif;
00167 
00169         // int
00170 
00171         template <typename T>
00172         struct is_int
00173         {
00174                 enum is_int_enum
00175                 {
00176                         _YES = 0,
00177                         _NO = 1
00178                 };
00179         };
00180 
00181 #define GLM_DETAIL_IS_INT(T)    \
00182         template <>                                     \
00183         struct is_int<T>                        \
00184         {                                                       \
00185                 enum is_int_enum                \
00186                 {                                               \
00187                         _YES = 1,                       \
00188                         _NO = 0                         \
00189                 };                                              \
00190         }
00191 
00193         // uint
00194 
00195         template <typename T>
00196         struct is_uint
00197         {
00198                 enum is_uint_enum
00199                 {
00200                         _YES = 0,
00201                         _NO = 1
00202                 };
00203         };
00204 
00205 #define GLM_DETAIL_IS_UINT(T)   \
00206         template <>                                     \
00207         struct is_uint<T>                       \
00208         {                                                       \
00209                 enum is_uint_enum               \
00210                 {                                               \
00211                         _YES = 1,                       \
00212                         _NO = 0                         \
00213                 };                                              \
00214         }
00215 
00216         //GLM_DETAIL_IS_UINT(unsigned long long)
00217 
00219         // float
00220 
00221         template <typename T>
00222         struct is_float
00223         {
00224                 enum is_float_enum
00225                 {
00226                         _YES = 0,
00227                         _NO = 1
00228                 };
00229         };
00230 
00231 #define GLM_DETAIL_IS_FLOAT(T)  \
00232         template <>                                     \
00233         struct is_float<T>                      \
00234         {                                                       \
00235                 enum is_float_enum              \
00236                 {                                               \
00237                         _YES = 1,                       \
00238                         _NO = 0                         \
00239                 };                                              \
00240         }
00241 
00243         // bool
00244 
00245         template <typename T>
00246         struct is_bool
00247         {
00248                 enum is_bool_enum
00249                 {
00250                         _YES = 0,
00251                         _NO = 1
00252                 };
00253         };
00254         
00255         template <>
00256         struct is_bool<bool>
00257         {
00258                 enum is_bool_enum
00259                 {
00260                         _YES = 1,
00261                         _NO = 0
00262                 };
00263         };
00264         
00266         // vector
00267 
00268         template <typename T>
00269         struct is_vector
00270         {
00271                 enum is_vector_enum
00272                 {
00273                         _YES = 0,
00274                         _NO = 1
00275                 };
00276         };
00277 
00278 #       define GLM_DETAIL_IS_VECTOR(TYPE) \
00279                 template <typename T> \
00280                 struct is_vector<TYPE<T> > \
00281                 { \
00282                         enum is_vector_enum \
00283                         { \
00284                                 _YES = 1, \
00285                                 _NO = 0 \
00286                         }; \
00287                 }
00288 
00290         // matrix
00291 
00292         template <typename T>
00293         struct is_matrix
00294         {
00295                 enum is_matrix_enum
00296                 {
00297                         _YES = 0,
00298                         _NO = 1
00299                 };
00300         };
00301 
00302 #define GLM_DETAIL_IS_MATRIX(T) \
00303         template <>                                     \
00304         struct is_matrix                        \
00305         {                                                       \
00306                 enum is_matrix_enum             \
00307                 {                                               \
00308                         _YES = 1,                       \
00309                         _NO = 0                         \
00310                 };                                              \
00311         }
00312 
00314         // type
00315 
00316         template <typename T>
00317         struct type
00318         {
00319                 enum type_enum
00320                 {
00321                         is_float = is_float<T>::_YES,
00322                         is_int = is_int<T>::_YES,
00323                         is_uint = is_uint<T>::_YES,
00324                         is_bool = is_bool<T>::_YES
00325                 };
00326         };
00327 
00329         // type
00330 
00331         typedef signed char                                                     int8;
00332         typedef signed short                                            int16;
00333         typedef signed int                                                      int32;
00334         typedef detail::sint64                                          int64;
00335 
00336         typedef unsigned char                                           uint8;
00337         typedef unsigned short                                          uint16;
00338         typedef unsigned int                                            uint32;
00339         typedef detail::uint64                                          uint64;
00340 
00341         typedef detail::thalf                                           float16;
00342         typedef float                                                           float32;
00343         typedef double                                                          float64;
00344 
00345 }//namespace detail
00346 }//namespace glm
00347 
00348 #if((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2005))
00349 #       define GLM_DEPRECATED __declspec(deprecated)
00350 #       define GLM_ALIGN(x) __declspec(align(x)) 
00351 #       define GLM_ALIGNED_STRUCT(x) __declspec(align(x)) struct 
00352 #       define GLM_RESTRICT __declspec(restrict)
00353 #       define GLM_RESTRICT_VAR __restrict
00354 #elif((GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC)) && (GLM_COMPILER >= GLM_COMPILER_GCC31))
00355 #       define GLM_DEPRECATED __attribute__((__deprecated__))
00356 #       define GLM_ALIGN(x) __attribute__((aligned(x)))
00357 #       define GLM_ALIGNED_STRUCT(x) struct __attribute__((aligned(x)))
00358 #       if(GLM_COMPILER >= GLM_COMPILER_GCC33)
00359 #               define GLM_RESTRICT __restrict__
00360 #               define GLM_RESTRICT_VAR __restrict__
00361 #       else
00362 #               define GLM_RESTRICT
00363 #               define GLM_RESTRICT_VAR
00364 #       endif
00365 #       define GLM_RESTRICT __restrict__
00366 #       define GLM_RESTRICT_VAR __restrict__
00367 #else
00368 #       define GLM_DEPRECATED
00369 #       define GLM_ALIGN
00370 #       define GLM_ALIGNED_STRUCT(x) 
00371 #       define GLM_RESTRICT
00372 #       define GLM_RESTRICT_VAR
00373 #endif//GLM_COMPILER
00374 
00375 #endif//glm_core_detail