- Timestamp:
- 05/29/13 22:25:30 (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/types.hh
r55 r57 8 8 #include <glm/glm.hpp> 9 9 #include <nv/common.hh> 10 #include <nv/object.hh> 10 11 #include <type_traits> 11 12 #include <utility> … … 14 15 #include <string> 15 16 17 #define NV_REGISTER_NAME( s ) template <> inline const char* nv::get_type_name<s> () { return #s; } 18 16 19 namespace nv 17 20 { 21 18 22 enum type 19 23 { … … 95 99 inline const char* get_type_name() 96 100 { 97 static_assert < FALSE >("Type not implemented!" );101 static_assert( false, "Type not implemented!" ); 98 102 } 99 100 #define NV_REGISTER_NAME( s ) template <> inline const char* nv::get_type_name<s> () { return #s; }101 103 102 104 template <> inline const char* get_type_name<int> () { return "sint"; } … … 130 132 131 133 template <> inline const char* get_type_name<std::string> () { return "string"; } 134 template <> inline const char* get_type_name<object> () { return "object"; } 135 136 template<typename T> 137 struct is_container 138 { 139 private: 140 typedef char yes; 141 typedef struct { char array[2]; } no; 142 template<typename C> static yes test(typename C::iterator*); 143 template<typename C> static no test(...); 144 public: 145 static const bool value = sizeof(test<T>(0)) == sizeof(yes); 146 }; 147 148 template<> 149 struct is_container< std::string > { 150 static const bool value = false; 151 }; 152 132 153 133 154 template <typename TYPE> … … 170 191 struct type_entry; 171 192 193 enum type_flag 194 { 195 TF_POINTER = 0x01, //< field is a pointer 196 TF_NOSERIALIZE = 0x02, //< ignore during serialization 197 TF_INVISIBLE = 0x04, //< field invisible to API 198 TF_READONLY = 0x08, //< read only field 199 TF_SIMPLETYPE = 0x10, //< raw binary I/O possible 200 TF_OWNED = 0x20, 201 TF_CONTAINER = 0x40, //< is a container 202 }; 203 172 204 struct type_field 173 205 { 174 enum flags175 {176 FPOINTER = 0x01, //< field is a pointer177 FNOSERIALIZE = 0x02, //< ignore during serialization178 FINVISIBLE = 0x04, //< field invisible to API179 FREADONLY = 0x08, //< read only field180 FSIMPLETYPE = 0x10, //< raw binary I/O possible181 FOWNED = 0x20,182 };183 206 hash_string name; //< name of the field 184 207 hash_string type_name; //< name of the type of the field … … 187 210 size_t offset; 188 211 189 template< typename TOBJECT, typename TFIELD> 190 type_field( hash_string name, TFIELD TOBJECT::*field ) 212 template< typename TOBJECT, typename TFIELD > 213 type_field( hash_string name, TFIELD TOBJECT::*field, typename std::enable_if< is_container<TFIELD>::value, void* >::type = nullptr ) 214 : name(name) 215 , type_name( get_type_name< std::remove_pointer<TFIELD::value_type>::type >() ) 216 , type( nullptr ) 217 , flags( 0 ) 218 , offset( offsetof( TOBJECT, *field ) ) 219 // NOTE: if offsetof behaves badly, check offset_of in common.hh 220 { 221 flags = FCONTAINER | 222 ( std::is_pointer<TFIELD::value_type>::value ? FPOINTER : 0 ) | 223 ( std::is_pod<TFIELD::value_type>::value ? FSIMPLETYPE : 0 ); 224 } 225 226 template< typename TOBJECT, typename TFIELD > 227 type_field( hash_string name, TFIELD TOBJECT::*field, typename std::enable_if< !is_container<TFIELD>::value, void* >::type = nullptr ) 191 228 : name(name) 192 229 , type_name( get_type_name< std::remove_pointer<TFIELD>::type >() ) … … 199 236 ( std::is_pointer<TFIELD>::value ? FPOINTER : 0 ) | 200 237 ( std::is_pod<TFIELD>::value ? FSIMPLETYPE : 0 ); 238 } 239 240 type_field& flag( unsigned int f ) 241 { 242 flags |= f; 243 return *this; 201 244 } 202 245 };
Note: See TracChangeset
for help on using the changeset viewer.