# GLM: _detail.hpp Source File

- Main Page
- Namespaces
- Files

- File List

# _detail.hpp

    00001
    00002 // OpenGL Mathematics Copyright (c) 2005 - 2009 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 //#define valType                       typename genType::value_type
    00017 //#define valType_cref  typename genType::value_type const &
    00018 //#define genType_cref  typename genType const &
    00019
    00020 namespace glm{
    00021 namespace detail{
    00022
    00023         class thalf;
    00024
    00025 #if(defined(GLM_COMPILER) && (GLM_COMPILER & GLM_COMPILER_VC))
    00026         typedef signed __int64                                          sint64;
    00027         typedef unsigned __int64                                        uint64;
    00028 #elif(defined(GLM_COMPILER) && (GLM_COMPILER & GLM_COMPILER_GCC))
    00029         __extension__ typedef signed long long          sint64;
    00030         __extension__ typedef unsigned long long        uint64;
    00031 #else//unknown compiler
    00032         typedef signed long                                                     sint64;
    00033         typedef unsigned long                                           uint64;
    00034 #endif//GLM_COMPILER
    00035
    00036         template<bool C>
    00037         struct If
    00038         {
    00039                 template<typename F, typename T>
    00040                 static inline T apply(F functor, const T& val)
    00041                 {
    00042                         return functor(val);
    00043                 }
    00044         };
    00045
    00046         template<>
    00047         struct If<false>
    00048         {
    00049                 template<typename F, typename T>
    00050                 static inline T apply(F, const T& val)
    00051                 {
    00052                         return val;
    00053                 }
    00054         };
    00055
    00056         //template <typename T>
    00057         //struct traits
    00058         //{
    00059         //      static const bool is_signed = false;
    00060         //      static const bool is_float = false;
    00061         //      static const bool is_vector = false;
    00062         //      static const bool is_matrix = false;
    00063         //      static const bool is_genType = false;
    00064         //      static const bool is_genIType = false;
    00065         //      static const bool is_genUType = false;
    00066         //};
    00067
    00068         //template <>
    00069         //struct traits<half>
    00070         //{
    00071         //      static const bool is_float = true;
    00072         //      static const bool is_genType = true;
    00073         //};
    00074
    00075         //template <>
    00076         //struct traits<float>
    00077         //{
    00078         //      static const bool is_float = true;
    00079         //      static const bool is_genType = true;
    00080         //};
    00081
    00082         //template <>
    00083         //struct traits<double>
    00084         //{
    00085         //      static const bool is_float = true;
    00086         //      static const bool is_genType = true;
    00087         //};
    00088
    00089         //template <typename genType>
    00090         //struct desc
    00091         //{
    00092         //      typedef genType                                                 type;
    00093         //      typedef genType *                                               pointer;
    00094         //      typedef genType const*                                  const_pointer;
    00095         //      typedef genType const *const                    const_pointer_const;
    00096         //      typedef genType *const                                  pointer_const;
    00097         //      typedef genType &                                               reference;
    00098         //      typedef genType const&                                  const_reference;
    00099         //      typedef genType const&                                  param_type;
    00100
    00101         //      typedef typename genType::value_type    value_type;
    00102         //      typedef typename genType::size_type             size_type;
    00103         //      static const typename size_type                 value_size;
    00104         //};
    00105
    00106         //template <typename genType>
    00107         //const typename desc<genType>::size_type desc<genType>::value_size = genType::value_size();
    00108
    00109         union uif32
    00110         {
    00111                 uif32() :
    00112                         i(0)
    00113                 {}
    00114
    00115                 uif32(float f) :
    00116                         f(f)
    00117                 {}
    00118
    00119                 uif32(unsigned int i) :
    00120                         i(i)
    00121                 {}
    00122
    00123                 float f;
    00124                 unsigned int i;
    00125         };
    00126
    00127         union uif64
    00128         {
    00129                 uif64() :
    00130                         i(0)
    00131                 {}
    00132
    00133                 uif64(double f) :
    00134                         f(f)
    00135                 {}
    00136
    00137                 uif64(uint64 i) :
    00138                         i(i)
    00139                 {}
    00140
    00141                 double f;
    00142                 uint64 i;
    00143         };
    00144
    00145         typedef uif32 uif;
    00146
    00148         // int
    00149
    00150         template <typename T>
    00151         struct is_int
    00152         {
    00153                 enum is_int_enum
    00154                 {
    00155                         YES = 0,
    00156                         NO = 1
    00157                 };
    00158         };
    00159
    00160 #define GLM_DETAIL_IS_INT(T)    \
    00161         template <>                                     \
    00162         struct is_int<T>                        \
    00163         {                                                       \
    00164                 enum is_int_enum                \
    00165                 {                                               \
    00166                         YES = 1,                        \
    00167                         NO = 0                          \
    00168                 };                                              \
    00169         }
    00170
    00172         // uint
    00173
    00174         template <typename T>
    00175         struct is_uint
    00176         {
    00177                 enum is_uint_enum
    00178                 {
    00179                         YES = 0,
    00180                         NO = 1
    00181                 };
    00182         };
    00183
    00184 #define GLM_DETAIL_IS_UINT(T)   \
    00185         template <>                                     \
    00186         struct is_uint<T>                       \
    00187         {                                                       \
    00188                 enum is_uint_enum               \
    00189                 {                                               \
    00190                         YES = 1,                        \
    00191                         NO = 0                          \
    00192                 };                                              \
    00193         }
    00194
    00195         //GLM_DETAIL_IS_UINT(unsigned long long)
    00196
    00198         // float
    00199
    00200         template <typename T>
    00201         struct is_float
    00202         {
    00203                 enum is_float_enum
    00204                 {
    00205                         YES = 0,
    00206                         NO = 1
    00207                 };
    00208         };
    00209
    00210 #define GLM_DETAIL_IS_FLOAT(T)  \
    00211         template <>                                     \
    00212         struct is_float<T>                      \
    00213         {                                                       \
    00214                 enum is_float_enum              \
    00215                 {                                               \
    00216                         YES = 1,                        \
    00217                         NO = 0                          \
    00218                 };                                              \
    00219         }
    00220
    00222         // bool
    00223
    00224         template <typename T>
    00225         struct is_bool
    00226         {
    00227                 enum is_bool_enum
    00228                 {
    00229                         YES = 0,
    00230                         NO = 1
    00231                 };
    00232         };
    00233
    00234         template <>
    00235         struct is_bool<bool>
    00236         {
    00237                 enum is_bool_enum
    00238                 {
    00239                         YES = 1,
    00240                         NO = 0
    00241                 };
    00242         };
    00243
    00245         // vector
    00246
    00247         template <typename T>
    00248         struct is_vector
    00249         {
    00250                 enum is_vector_enum
    00251                 {
    00252                         YES = 0,
    00253                         NO = 1
    00254                 };
    00255         };
    00256
    00257 #define GLM_DETAIL_IS_VECTOR(T) \
    00258         template <>                                     \
    00259         struct is_vector                        \
    00260         {                                                       \
    00261                 enum is_vector_enum             \
    00262                 {                                               \
    00263                         YES = 1,                        \
    00264                         NO = 0                          \
    00265                 };                                              \
    00266         }
    00267
    00269         // matrix
    00270
    00271         template <typename T>
    00272         struct is_matrix
    00273         {
    00274                 enum is_matrix_enum
    00275                 {
    00276                         YES = 0,
    00277                         NO = 1
    00278                 };
    00279         };
    00280
    00281 #define GLM_DETAIL_IS_MATRIX(T) \
    00282         template <>                                     \
    00283         struct is_matrix                        \
    00284         {                                                       \
    00285                 enum is_matrix_enum             \
    00286                 {                                               \
    00287                         YES = 1,                        \
    00288                         NO = 0                          \
    00289                 };                                              \
    00290         }
    00291
    00293         // type
    00294
    00295         template <typename T>
    00296         struct type
    00297         {
    00298                 enum type_enum
    00299                 {
    00300                         is_float = is_float<T>::YES,
    00301                         is_int = is_int<T>::YES,
    00302                         is_uint = is_uint<T>::YES,
    00303                         is_bool = is_bool<T>::YES
    00304                 };
    00305         };
    00306
    00308         // type
    00309
    00310         typedef signed char                                                     int8;
    00311         typedef signed short                                            int16;
    00312         typedef signed int                                                      int32;
    00313         typedef detail::sint64                                          int64;
    00314
    00315         typedef unsigned char                                           uint8;
    00316         typedef unsigned short                                          uint16;
    00317         typedef unsigned int                                            uint32;
    00318         typedef detail::uint64                                          uint64;
    00319
    00320         typedef detail::thalf                                           float16;
    00321         typedef float                                                           float32;
    00322         typedef double                                                          float64;
    00323
    00324 }//namespace detail
    00325 }//namespace glm
    00326
    00327 #endif//glm_core_detail