Changeset 214


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
Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gl/gl_enum.hh

    r70 r214  
    1313#define NV_GL_ENUM_HH
    1414
     15#include <nv/math.hh>
    1516#include <nv/interface/clear_state.hh>
    1617#include <nv/interface/render_state.hh>
     
    1819#include <nv/interface/texture2d.hh>
    1920#include <nv/interface/context.hh>
    20 #include <nv/types.hh>
    2121
    2222namespace nv
  • trunk/nv/interface/clear_state.hh

    r121 r214  
    1515
    1616#include <nv/common.hh>
    17 #include <nv/types.hh>
     17#include <nv/math.hh>
    1818
    1919namespace nv
  • trunk/nv/interface/mesh.hh

    r148 r214  
    1616#include <nv/common.hh>
    1717#include <nv/string.hh>
    18 #include <nv/types.hh>
     18#include <nv/math.hh>
    1919#include <nv/interface/context.hh>
    2020#include <unordered_map>
  • trunk/nv/interface/program.hh

    r161 r214  
    1818#include <nv/common.hh>
    1919#include <nv/string.hh>
    20 #include <nv/types.hh>
     20#include <nv/math.hh>
    2121
    2222namespace nv
  • trunk/nv/interface/render_state.hh

    r110 r214  
    1515
    1616#include <nv/common.hh>
    17 #include <nv/types.hh>
     17#include <nv/math.hh>
    1818#include <nv/interface/clear_state.hh>
    1919#include <nv/string.hh>
  • trunk/nv/interface/texture2d.hh

    r121 r214  
    1414
    1515#include <nv/common.hh>
    16 #include <nv/types.hh>
     16#include <nv/math.hh>
    1717
    1818namespace nv
  • trunk/nv/interface/vertex_buffer.hh

    r155 r214  
    1414
    1515#include <nv/common.hh>
    16 #include <nv/types.hh>
     16#include <nv/math.hh>
    1717#include <unordered_map>
    1818#include <string>
  • trunk/nv/io_event.hh

    r184 r214  
    1515
    1616#include <nv/common.hh>
    17 #include <nv/types.hh>
    1817
    1918namespace nv
  • trunk/nv/math.hh

    r190 r214  
    88#define NV_MATH_HH
    99
     10#include <nv/common.hh>
     11
    1012#if NV_COMPILER == NV_GNUC
    1113#pragma GCC system_header
     
    1416#endif
    1517
    16 #include <nv/common.hh>
    1718#include <glm/glm.hpp>
    1819#include <glm/gtc/matrix_transform.hpp>
     
    7576        using glm::min;
    7677
     78        enum datatype
     79        {
     80                INT,
     81                BYTE,
     82                SHORT,
     83                UINT,
     84                UBYTE,
     85                USHORT,
     86                FLOAT,
     87                FLOAT_VECTOR_2,
     88                FLOAT_VECTOR_3,
     89                FLOAT_VECTOR_4,
     90                FLOAT_MATRIX_2,
     91                FLOAT_MATRIX_3,
     92                FLOAT_MATRIX_4,
     93                INT_VECTOR_2,
     94                INT_VECTOR_3,
     95                INT_VECTOR_4,
     96                // unsupported gl conversion, remove?
     97                BYTE_VECTOR_2,
     98                BYTE_VECTOR_3,
     99                BYTE_VECTOR_4,
     100        };
     101
     102        template < datatype EnumType > struct enum_to_type {};
     103
     104        template <> struct enum_to_type< INT >   { typedef int type; };
     105        template <> struct enum_to_type< UINT >  { typedef unsigned int type; };
     106        template <> struct enum_to_type< SHORT > { typedef short type; };
     107        template <> struct enum_to_type< USHORT >{ typedef unsigned short type; };
     108        template <> struct enum_to_type< BYTE >  { typedef char type; };
     109        template <> struct enum_to_type< UBYTE > { typedef unsigned char type; };
     110        template <> struct enum_to_type< FLOAT > { typedef f32 type; };
     111
     112        template <> struct enum_to_type< FLOAT_VECTOR_2 > { typedef vec2 type; };
     113        template <> struct enum_to_type< FLOAT_VECTOR_3 > { typedef vec3 type; };
     114        template <> struct enum_to_type< FLOAT_VECTOR_4 > { typedef vec4 type; };
     115
     116        template <> struct enum_to_type< INT_VECTOR_2 > { typedef ivec2 type; };
     117        template <> struct enum_to_type< INT_VECTOR_3 > { typedef ivec3 type; };
     118        template <> struct enum_to_type< INT_VECTOR_4 > { typedef ivec4 type; };
     119
     120        template <> struct enum_to_type< BYTE_VECTOR_2 > { typedef i8vec2 type; };
     121        template <> struct enum_to_type< BYTE_VECTOR_3 > { typedef i8vec3 type; };
     122        template <> struct enum_to_type< BYTE_VECTOR_4 > { typedef i8vec4 type; };
     123
     124        template <> struct enum_to_type< FLOAT_MATRIX_2 > { typedef mat2 type; };
     125        template <> struct enum_to_type< FLOAT_MATRIX_3 > { typedef mat3 type; };
     126        template <> struct enum_to_type< FLOAT_MATRIX_4 > { typedef mat4 type; };
     127
     128        template < typename TYPE > struct type_to_enum {};
     129
     130        template <> struct type_to_enum< long >          { static const datatype type = INT; };
     131        template <> struct type_to_enum< unsigned long > { static const datatype type = UINT; };
     132        template <> struct type_to_enum< int >           { static const datatype type = INT; };
     133        template <> struct type_to_enum< unsigned int >  { static const datatype type = UINT; };
     134        template <> struct type_to_enum< short >         { static const datatype type = SHORT; };
     135        template <> struct type_to_enum< unsigned short >{ static const datatype type = USHORT; };
     136        template <> struct type_to_enum< char >          { static const datatype type = BYTE; };
     137        template <> struct type_to_enum< signed char >   { static const datatype type = BYTE; };
     138        template <> struct type_to_enum< unsigned char > { static const datatype type = UBYTE; };
     139        template <> struct type_to_enum< f32 > { static const datatype type = FLOAT; };
     140
     141        template <> struct type_to_enum< vec2 > { static const datatype type = FLOAT_VECTOR_2; };
     142        template <> struct type_to_enum< vec3 > { static const datatype type = FLOAT_VECTOR_3; };
     143        template <> struct type_to_enum< vec4 > { static const datatype type = FLOAT_VECTOR_4; };
     144
     145        template <> struct type_to_enum< ivec2 > { static const datatype type = INT_VECTOR_2; };
     146        template <> struct type_to_enum< ivec3 > { static const datatype type = INT_VECTOR_3; };
     147        template <> struct type_to_enum< ivec4 > { static const datatype type = INT_VECTOR_4; };
     148
     149        template <> struct type_to_enum< i8vec2 > { static const datatype type = BYTE_VECTOR_2; };
     150        template <> struct type_to_enum< i8vec3 > { static const datatype type = BYTE_VECTOR_3; };
     151        template <> struct type_to_enum< i8vec4 > { static const datatype type = BYTE_VECTOR_4; };
     152
     153        template <> struct type_to_enum< mat2 > { static const datatype type = FLOAT_MATRIX_2; };
     154        template <> struct type_to_enum< mat3 > { static const datatype type = FLOAT_MATRIX_3; };
     155        template <> struct type_to_enum< mat4 > { static const datatype type = FLOAT_MATRIX_4; };
     156
     157
    77158} // namespace nv
    78159
  • trunk/nv/type_traits.hh

    r211 r214  
    181181        };
    182182
     183        template<typename T>
     184        struct is_container
     185        {
     186        private:
     187                typedef char                      yes;
     188                typedef struct { char array[2]; } no;
     189                template<typename C> static yes test(typename C::iterator*);
     190                template<typename C> static no  test(...);
     191        public:
     192                static const bool value = sizeof(test<T>(0)) == sizeof(yes);
     193        };
     194
     195        template<>
     196        struct is_container< std::string > {
     197                static const bool value = false;
     198        };
     199
     200        template <typename TYPE>
     201        void construct_object(void* object)
     202        {
     203                new (object) TYPE;
     204        }
     205        template <typename TYPE>
     206        void destroy_object(void* object)
     207        {
     208                ((TYPE*)object)->TYPE::~TYPE();
     209        }
    183210}
    184211
  • 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;
  • trunk/src/io_event.cc

    r184 r214  
    66
    77#include "nv/io_event.hh"
     8
     9#include <nv/types.hh>
    810
    911using namespace nv;
  • trunk/tests/cachebuf_test/nv_cachebuf_test.cc

    r161 r214  
    1212#include <glm/gtc/type_ptr.hpp>
    1313#include <nv/string.hh>
    14 #include <nv/types.hh>
    1514#include <nv/interface/mesh.hh>
    1615#include <cstdlib> // rand
  • trunk/tests/lualib_test/init.lua

    r52 r214  
     1print "hello world from Lua!"
     2hello( "Hello" )
  • trunk/tests/lualib_test/lualib_test.cc

    r213 r214  
    55#include <nv/lua/lua_glm.hh>
    66#include <nv/logger.hh>
    7 #include <nv/types.hh>
     7#include <nv/math.hh>
    88#include <nv/object.hh>
    99#include <string>
  • trunk/tests/md2_test/md2_test.cc

    r189 r214  
    1818#include <nv/time.hh>
    1919#include <nv/string.hh>
    20 #include <nv/types.hh>
    2120#include <nv/interface/mesh.hh>
    2221#include <glm/gtx/rotate_vector.hpp>
  • trunk/tests/objload_test/objload_test.cc

    r139 r214  
    1313#include <nv/math.hh>
    1414#include <nv/string.hh>
    15 #include <nv/types.hh>
    1615#include <nv/interface/mesh.hh>
    1716
  • trunk/tests/render_test/rl.cc

    r121 r214  
    1010#include <nv/math.hh>
    1111#include <nv/string.hh>
    12 #include <nv/types.hh>
    1312#include <nv/interface/mesh.hh>
    1413
Note: See TracChangeset for help on using the changeset viewer.