Changeset 54
- Timestamp:
- 05/29/13 17:35:48 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/types.hh
r53 r54 8 8 #include <glm/glm.hpp> 9 9 #include <nv/common.hh> 10 #include <type_traits> 10 11 #include <utility> 11 12 #include <unordered_map> 13 #include <vector> 12 14 #include <string> 13 15 … … 68 70 template <> struct enum_to_type< FLOAT_MATRIX_4 > { typedef mat4 type; }; 69 71 70 template < typename T ype> struct type_to_enum {};72 template < typename TYPE > struct type_to_enum {}; 71 73 72 74 template <> struct type_to_enum< int > { static const type type = INT; }; … … 96 98 } 97 99 100 #define NV_REGISTER_NAME( s ) template <> inline const char* nv::get_type_name<s> () { return #s; } 101 102 template <> inline const char* get_type_name<int> () { return "sint"; } 98 103 template <> inline const char* get_type_name<sint8> () { return "sint8"; } 99 104 template <> inline const char* get_type_name<sint16>() { return "sint16"; } … … 101 106 template <> inline const char* get_type_name<sint64>() { return "sint64"; } 102 107 103 template <> inline const char* get_type_name<uint8> () { return "uint8"; } 104 template <> inline const char* get_type_name<uint16>() { return "uint16"; } 105 template <> inline const char* get_type_name<uint32>() { return "uint32"; } 106 template <> inline const char* get_type_name<uint64>() { return "uint64"; } 108 template <> inline const char* get_type_name<unsigned int>() { return "uint"; } 109 template <> inline const char* get_type_name<uint8> () { return "uint8"; } 110 template <> inline const char* get_type_name<uint16>() { return "uint16"; } 111 template <> inline const char* get_type_name<uint32>() { return "uint32"; } 112 template <> inline const char* get_type_name<uint64>() { return "uint64"; } 107 113 108 114 template <> inline const char* get_type_name<f32> () { return "f32"; } … … 162 168 namespace nv 163 169 { 170 struct type_entry; 171 172 struct type_field 173 { 174 enum flags 175 { 176 FPOINTER = 0x01, //< field is a pointer 177 FNOSERIALIZE = 0x02, //< ignore during serialization 178 FINVISIBLE = 0x04, //< field invisible to API 179 FREADONLY = 0x08, //< read only field 180 FSIMPLETYPE = 0x10, //< raw binary I/O possible 181 FOWNED = 0x20, 182 }; 183 hash_string name; //< name of the field 184 hash_string type_name; //< name of the type of the field 185 type_entry* type; //< pointer to field type 186 unsigned int flags; //< flags 187 size_t offset; 188 189 template< typename TOBJECT, typename TFIELD> 190 type_field( hash_string name, TFIELD TOBJECT::*field ) 191 : name(name) 192 , type_name( get_type_name< std::remove_pointer<TFIELD>::type >() ) 193 , type( nullptr ) 194 , flags( 0 ) 195 , offset( offsetof( TOBJECT, *field ) ) 196 { 197 flags = 198 ( std::is_pointer<TFIELD>::value ? FPOINTER : 0 ) | 199 ( std::is_pod<TFIELD>::value ? FSIMPLETYPE : 0 ); 200 } 201 }; 202 203 struct type_enum 204 { 205 hash_string name; 206 int value; 207 type_enum( hash_string name, int value ) : name(name), value(value) {} 208 }; 164 209 165 210 struct type_entry … … 181 226 // Result of sizeof(type) operation 182 227 size_t size; 228 229 // Base type 230 type_entry* base_type; 231 232 // Field list 233 std::vector<type_field> field_list; 234 235 // Enum list 236 std::vector<type_enum> enum_list; 237 238 template <int TYPE> 239 type_entry& base() 240 { 241 base_type = type_db->get_type( get_type_name<TYPE>() ) 242 } 243 244 template <int SIZE> 245 type_entry& fields( type_field (&init_fields)[SIZE] ) 246 { 247 for (int i = 0; i < SIZE; i++) 248 { 249 type_field f = init_fields[i]; 250 f.type = type_db->get_type(f.type_name); 251 field_list.push_back(f); 252 } 253 return *this; 254 } 255 256 template <int SIZE> 257 type_entry& enums( type_enum (&init_enums)[SIZE] ) 258 { 259 for (int i = 0; i < SIZE; i++) 260 { 261 enum_list.push_back( init_enums[i] ) 262 } 263 return *this; 264 } 183 265 }; 184 266 185 267 class type_database 186 268 { … … 207 289 return *i_type; 208 290 } 291 209 292 type_entry* get_type( hash_string name ) 210 293 {
Note: See TracChangeset
for help on using the changeset viewer.