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