_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 #if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
00035 #include <cstdint>
00036 #endif
00037 
00038 namespace glm{
00039 namespace detail
00040 {
00041         class thalf;
00042 
00043 #if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) // C99 detected, 64 bit types available
00044         typedef int64_t                                                         sint64;
00045         typedef uint64_t                                                        uint64;
00046 #elif(GLM_COMPILER & GLM_COMPILER_VC)
00047         typedef signed __int64                                          sint64;
00048         typedef unsigned __int64                                        uint64;
00049 #elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC | GLM_COMPILER_CLANG))
00050         __extension__ typedef signed long long          sint64;
00051         __extension__ typedef unsigned long long        uint64;
00052 #elif(GLM_COMPILER & GLM_COMPILER_BC)
00053         typedef Int64                                                           sint64;
00054         typedef Uint64                                                          uint64;
00055 #else//unknown compiler
00056         typedef signed long     long                                    sint64;
00057         typedef unsigned long long                                      uint64;
00058 #endif//GLM_COMPILER
00059 
00060         template<bool C>
00061         struct If
00062         {
00063                 template<typename F, typename T>
00064                 static GLM_FUNC_QUALIFIER T apply(F functor, const T& val)
00065                 {
00066                         return functor(val);
00067                 }
00068         };
00069 
00070         template<>
00071         struct If<false>
00072         {
00073                 template<typename F, typename T>
00074                 static GLM_FUNC_QUALIFIER T apply(F, const T& val)
00075                 {
00076                         return val;
00077                 }
00078         };
00079 
00080         //template <typename T>
00081         //struct traits
00082         //{
00083         //      static const bool is_signed = false;
00084         //      static const bool is_float = false;
00085         //      static const bool is_vector = false;
00086         //      static const bool is_matrix = false;
00087         //      static const bool is_genType = false;
00088         //      static const bool is_genIType = false;
00089         //      static const bool is_genUType = false;
00090         //};
00091 
00092         //template <>
00093         //struct traits<half>
00094         //{
00095         //      static const bool is_float = true;
00096         //      static const bool is_genType = true;
00097         //};
00098 
00099         //template <>
00100         //struct traits<float>
00101         //{
00102         //      static const bool is_float = true;
00103         //      static const bool is_genType = true;
00104         //};
00105 
00106         //template <>
00107         //struct traits<double>
00108         //{
00109         //      static const bool is_float = true;
00110         //      static const bool is_genType = true;
00111         //};
00112 
00113         //template <typename genType>
00114         //struct desc
00115         //{
00116         //      typedef genType                                                 type;
00117         //      typedef genType *                                               pointer;
00118         //      typedef genType const*                                  const_pointer;
00119         //      typedef genType const *const                    const_pointer_const;
00120         //      typedef genType *const                                  pointer_const;
00121         //      typedef genType &                                               reference;
00122         //      typedef genType const&                                  const_reference;
00123         //      typedef genType const&                                  param_type;
00124 
00125         //      typedef typename genType::value_type    value_type;
00126         //      typedef typename genType::size_type             size_type;
00127         //      static const typename size_type                 value_size;
00128         //};
00129 
00130         //template <typename genType>
00131         //const typename desc<genType>::size_type desc<genType>::value_size = genType::value_size();
00132 
00133         union uif32
00134         {
00135                 GLM_FUNC_QUALIFIER uif32() :
00136                         i(0)
00137                 {}
00138 
00139                 GLM_FUNC_QUALIFIER uif32(float f) :
00140                         f(f)
00141                 {}
00142 
00143                 GLM_FUNC_QUALIFIER uif32(unsigned int i) :
00144                         i(i)
00145                 {}
00146 
00147                 float f;
00148                 unsigned int i;
00149         };
00150 
00151         union uif64
00152         {
00153                 GLM_FUNC_QUALIFIER uif64() :
00154                         i(0)
00155                 {}
00156 
00157                 GLM_FUNC_QUALIFIER uif64(double f) :
00158                         f(f)
00159                 {}
00160 
00161                 GLM_FUNC_QUALIFIER uif64(uint64 i) :
00162                         i(i)
00163                 {}
00164 
00165                 double f;
00166                 uint64 i;
00167         };
00168 
00169         typedef uif32 uif;
00170 
00172         // int
00173 
00174         template <typename T>
00175         struct is_int
00176         {
00177                 enum is_int_enum
00178                 {
00179                         _YES = 0,
00180                         _NO = 1
00181                 };
00182         };
00183 
00184 #define GLM_DETAIL_IS_INT(T)    \
00185         template <>                                     \
00186         struct is_int<T>                        \
00187         {                                                       \
00188                 enum is_int_enum                \
00189                 {                                               \
00190                         _YES = 1,                       \
00191                         _NO = 0                         \
00192                 };                                              \
00193         }
00194 
00196         // uint
00197 
00198         template <typename T>
00199         struct is_uint
00200         {
00201                 enum is_uint_enum
00202                 {
00203                         _YES = 0,
00204                         _NO = 1
00205                 };
00206         };
00207 
00208 #define GLM_DETAIL_IS_UINT(T)   \
00209         template <>                                     \
00210         struct is_uint<T>                       \
00211         {                                                       \
00212                 enum is_uint_enum               \
00213                 {                                               \
00214                         _YES = 1,                       \
00215                         _NO = 0                         \
00216                 };                                              \
00217         }
00218 
00219         //GLM_DETAIL_IS_UINT(unsigned long long)
00220 
00222         // float
00223 
00224         template <typename T>
00225         struct is_float
00226         {
00227                 enum is_float_enum
00228                 {
00229                         _YES = 0,
00230                         _NO = 1
00231                 };
00232         };
00233 
00234 #define GLM_DETAIL_IS_FLOAT(T)  \
00235         template <>                                     \
00236         struct is_float<T>                      \
00237         {                                                       \
00238                 enum is_float_enum              \
00239                 {                                               \
00240                         _YES = 1,                       \
00241                         _NO = 0                         \
00242                 };                                              \
00243         }
00244 
00246         // bool
00247 
00248         template <typename T>
00249         struct is_bool
00250         {
00251                 enum is_bool_enum
00252                 {
00253                         _YES = 0,
00254                         _NO = 1
00255                 };
00256         };
00257         
00258         template <>
00259         struct is_bool<bool>
00260         {
00261                 enum is_bool_enum
00262                 {
00263                         _YES = 1,
00264                         _NO = 0
00265                 };
00266         };
00267         
00269         // vector
00270 
00271         template <typename T>
00272         struct is_vector
00273         {
00274                 enum is_vector_enum
00275                 {
00276                         _YES = 0,
00277                         _NO = 1
00278                 };
00279         };
00280 
00281 #       define GLM_DETAIL_IS_VECTOR(TYPE) \
00282                 template <typename T> \
00283                 struct is_vector<TYPE<T> > \
00284                 { \
00285                         enum is_vector_enum \
00286                         { \
00287                                 _YES = 1, \
00288                                 _NO = 0 \
00289                         }; \
00290                 }
00291 
00293         // matrix
00294 
00295         template <typename T>
00296         struct is_matrix
00297         {
00298                 enum is_matrix_enum
00299                 {
00300                         _YES = 0,
00301                         _NO = 1
00302                 };
00303         };
00304 
00305 #define GLM_DETAIL_IS_MATRIX(T) \
00306         template <>                                     \
00307         struct is_matrix                        \
00308         {                                                       \
00309                 enum is_matrix_enum             \
00310                 {                                               \
00311                         _YES = 1,                       \
00312                         _NO = 0                         \
00313                 };                                              \
00314         }
00315 
00317         // type
00318 
00319         template <typename T>
00320         struct type
00321         {
00322                 enum type_enum
00323                 {
00324                         is_float = is_float<T>::_YES,
00325                         is_int = is_int<T>::_YES,
00326                         is_uint = is_uint<T>::_YES,
00327                         is_bool = is_bool<T>::_YES
00328                 };
00329         };
00330         
00332         // type
00333         
00334         typedef signed char                                                     int8;
00335         typedef signed short                                            int16;
00336         typedef signed int                                                      int32;
00337         typedef detail::sint64                                          int64;
00338         
00339         typedef unsigned char                                           uint8;
00340         typedef unsigned short                                          uint16;
00341         typedef unsigned int                                            uint32;
00342         typedef detail::uint64                                          uint64;
00343         
00344         typedef detail::thalf                                           float16;
00345         typedef float                                                           float32;
00346         typedef double                                                          float64;
00347         
00349         // float_or_int_trait 
00350 
00351         struct float_or_int_value
00352         {
00353                 enum
00354                 {
00355                         ERROR,
00356                         FLOAT,
00357                         INT
00358                 };
00359         };
00360 
00361         template <typename T>
00362         struct float_or_int_trait
00363         {
00364                 enum{ID = float_or_int_value::ERROR};
00365         };
00366 
00367         template <>
00368         struct float_or_int_trait<int8>
00369         {
00370                 enum{ID = float_or_int_value::INT};
00371         };
00372 
00373         template <>
00374         struct float_or_int_trait<int16>
00375         {
00376                 enum{ID = float_or_int_value::INT};
00377         };
00378 
00379         template <>
00380         struct float_or_int_trait<int32>
00381         {
00382                 enum{ID = float_or_int_value::INT};
00383         };
00384 
00385         template <>
00386         struct float_or_int_trait<int64>
00387         {
00388                 enum{ID = float_or_int_value::INT};
00389         };
00390 
00391         template <>
00392         struct float_or_int_trait<uint8>
00393         {
00394                 enum{ID = float_or_int_value::INT};
00395         };
00396 
00397         template <>
00398         struct float_or_int_trait<uint16>
00399         {
00400                 enum{ID = float_or_int_value::INT};
00401         };
00402 
00403         template <>
00404         struct float_or_int_trait<uint32>
00405         {
00406                 enum{ID = float_or_int_value::INT};
00407         };
00408 
00409         template <>
00410         struct float_or_int_trait<uint64>
00411         {
00412                 enum{ID = float_or_int_value::INT};
00413         };
00414 
00415         template <>
00416         struct float_or_int_trait<float16>
00417         {
00418                 enum{ID = float_or_int_value::FLOAT};
00419         };
00420 
00421         template <>
00422         struct float_or_int_trait<float32>
00423         {
00424                 enum{ID = float_or_int_value::FLOAT};
00425         };
00426 
00427         template <>
00428         struct float_or_int_trait<float64>
00429         {
00430                 enum{ID = float_or_int_value::FLOAT};
00431         };
00432 
00433 }//namespace detail
00434 }//namespace glm
00435 
00436 #if((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2005))
00437 #       define GLM_DEPRECATED __declspec(deprecated)
00438 #       define GLM_ALIGN(x) __declspec(align(x)) 
00439 #       define GLM_ALIGNED_STRUCT(x) __declspec(align(x)) struct 
00440 #       define GLM_RESTRICT __declspec(restrict)
00441 #       define GLM_RESTRICT_VAR __restrict
00442 #elif((GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC)) && (GLM_COMPILER >= GLM_COMPILER_GCC31))
00443 #       define GLM_DEPRECATED __attribute__((__deprecated__))
00444 #       define GLM_ALIGN(x) __attribute__((aligned(x)))
00445 #       define GLM_ALIGNED_STRUCT(x) struct __attribute__((aligned(x)))
00446 #       if(GLM_COMPILER >= GLM_COMPILER_GCC33)
00447 #               define GLM_RESTRICT __restrict__
00448 #               define GLM_RESTRICT_VAR __restrict__
00449 #       else
00450 #               define GLM_RESTRICT
00451 #               define GLM_RESTRICT_VAR
00452 #       endif
00453 #       define GLM_RESTRICT __restrict__
00454 #       define GLM_RESTRICT_VAR __restrict__
00455 #else
00456 #       define GLM_DEPRECATED
00457 #       define GLM_ALIGN
00458 #       define GLM_ALIGNED_STRUCT(x) 
00459 #       define GLM_RESTRICT
00460 #       define GLM_RESTRICT_VAR
00461 #endif//GLM_COMPILER
00462 
00463 #endif//glm_core_detail