Changeset 214 for trunk/nv/types.hh


Ignore:
Timestamp:
09/09/13 20:48:38 (12 years ago)
Author:
epyon
Message:
  • types - decomposition, math types go to math, type_traits related to type_traits
  • decoupling of the types.hh dependency from all possible places
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/types.hh

    r190 r214  
    99#include <nv/math.hh>
    1010#include <nv/object.hh>
    11 #include <type_traits>
     11#include <nv/type_traits.hh>
    1212#include <typeinfo>
    1313#include <typeindex>
     
    2020namespace nv
    2121{
    22         enum datatype
    23         {
    24                 INT,
    25                 BYTE,
    26                 SHORT,
    27                 UINT,
    28                 UBYTE,
    29                 USHORT,
    30                 FLOAT,
    31                 FLOAT_VECTOR_2,
    32                 FLOAT_VECTOR_3,
    33                 FLOAT_VECTOR_4,
    34                 FLOAT_MATRIX_2,
    35                 FLOAT_MATRIX_3,
    36                 FLOAT_MATRIX_4,
    37                 INT_VECTOR_2,
    38                 INT_VECTOR_3,
    39                 INT_VECTOR_4,
    40                 // unsupported gl conversion, remove?
    41                 BYTE_VECTOR_2,
    42                 BYTE_VECTOR_3,
    43                 BYTE_VECTOR_4,
    44         };
    45 
    46         template < datatype EnumType > struct enum_to_type {};
    47 
    48         template <> struct enum_to_type< INT >   { typedef int type; };
    49         template <> struct enum_to_type< UINT >  { typedef unsigned int type; };
    50         template <> struct enum_to_type< SHORT > { typedef short type; };
    51         template <> struct enum_to_type< USHORT >{ typedef unsigned short type; };
    52         template <> struct enum_to_type< BYTE >  { typedef char type; };
    53         template <> struct enum_to_type< UBYTE > { typedef unsigned char type; };
    54         template <> struct enum_to_type< FLOAT > { typedef f32 type; };
    55 
    56         template <> struct enum_to_type< FLOAT_VECTOR_2 > { typedef vec2 type; };
    57         template <> struct enum_to_type< FLOAT_VECTOR_3 > { typedef vec3 type; };
    58         template <> struct enum_to_type< FLOAT_VECTOR_4 > { typedef vec4 type; };
    59 
    60         template <> struct enum_to_type< INT_VECTOR_2 > { typedef ivec2 type; };
    61         template <> struct enum_to_type< INT_VECTOR_3 > { typedef ivec3 type; };
    62         template <> struct enum_to_type< INT_VECTOR_4 > { typedef ivec4 type; };
    63 
    64         template <> struct enum_to_type< BYTE_VECTOR_2 > { typedef i8vec2 type; };
    65         template <> struct enum_to_type< BYTE_VECTOR_3 > { typedef i8vec3 type; };
    66         template <> struct enum_to_type< BYTE_VECTOR_4 > { typedef i8vec4 type; };
    67 
    68         template <> struct enum_to_type< FLOAT_MATRIX_2 > { typedef mat2 type; };
    69         template <> struct enum_to_type< FLOAT_MATRIX_3 > { typedef mat3 type; };
    70         template <> struct enum_to_type< FLOAT_MATRIX_4 > { typedef mat4 type; };
    71 
    72         template < typename TYPE > struct type_to_enum {};
    73 
    74         template <> struct type_to_enum< long >          { static const datatype type = INT; };
    75         template <> struct type_to_enum< unsigned long > { static const datatype type = UINT; };
    76         template <> struct type_to_enum< int >           { static const datatype type = INT; };
    77         template <> struct type_to_enum< unsigned int >  { static const datatype type = UINT; };
    78         template <> struct type_to_enum< short >         { static const datatype type = SHORT; };
    79         template <> struct type_to_enum< unsigned short >{ static const datatype type = USHORT; };
    80         template <> struct type_to_enum< char >          { static const datatype type = BYTE; };
    81         template <> struct type_to_enum< signed char >   { static const datatype type = BYTE; };
    82         template <> struct type_to_enum< unsigned char > { static const datatype type = UBYTE; };
    83         template <> struct type_to_enum< f32 > { static const datatype type = FLOAT; };
    84 
    85         template <> struct type_to_enum< vec2 > { static const datatype type = FLOAT_VECTOR_2; };
    86         template <> struct type_to_enum< vec3 > { static const datatype type = FLOAT_VECTOR_3; };
    87         template <> struct type_to_enum< vec4 > { static const datatype type = FLOAT_VECTOR_4; };
    88 
    89         template <> struct type_to_enum< ivec2 > { static const datatype type = INT_VECTOR_2; };
    90         template <> struct type_to_enum< ivec3 > { static const datatype type = INT_VECTOR_3; };
    91         template <> struct type_to_enum< ivec4 > { static const datatype type = INT_VECTOR_4; };
    92 
    93         template <> struct type_to_enum< i8vec2 > { static const datatype type = BYTE_VECTOR_2; };
    94         template <> struct type_to_enum< i8vec3 > { static const datatype type = BYTE_VECTOR_3; };
    95         template <> struct type_to_enum< i8vec4 > { static const datatype type = BYTE_VECTOR_4; };
    96 
    97         template <> struct type_to_enum< mat2 > { static const datatype type = FLOAT_MATRIX_2; };
    98         template <> struct type_to_enum< mat3 > { static const datatype type = FLOAT_MATRIX_3; };
    99         template <> struct type_to_enum< mat4 > { static const datatype type = FLOAT_MATRIX_4; };
    100 
    101         template<typename T>
    102         struct is_container
    103         {
    104                 private:
    105                         typedef char                      yes;
    106                         typedef struct { char array[2]; } no;
    107                         template<typename C> static yes test(typename C::iterator*);
    108                         template<typename C> static no  test(...);
    109                 public:
    110                         static const bool value = sizeof(test<T>(0)) == sizeof(yes);
    111         };
    112 
    113         template<>
    114         struct is_container< std::string > {
    115                 static const bool value = false;
    116         };
    117 
    118         template <typename TYPE> void ConstructObject(void* object)
    119         {
    120                 // Use placement new to call the constructor
    121                 new (object) TYPE;
    122         }
    123         template <typename TYPE> void DestructObject(void* object)
    124         {
    125                 // Explicit call of the destructor
    126                 ((TYPE*)object)->TYPE::~TYPE();
    127         }
    128    
     22
    12923        struct type_entry;
    13024
     
    255149                        i_type->size    = sizeof(TYPE);
    256150
    257                         i_type->constructor = ConstructObject<TYPE>;
    258                         i_type->destructor  = DestructObject<TYPE>;
     151                        i_type->constructor = construct_object<TYPE>;
     152                        i_type->destructor  = destroy_object<TYPE>;
    259153
    260154                        m_name_types[name]        = i_type;
Note: See TracChangeset for help on using the changeset viewer.