Changeset 429
- Timestamp:
- 07/20/15 14:14:22 (10 years ago)
- Location:
- trunk/nv
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/types.hh
r395 r429 13 13 #include <nv/stl/vector.hh> 14 14 #include <nv/stl/unordered_map.hh> 15 #include <nv/stl/cstring_store.hh> 15 #include <nv/stl/string_table.hh> 16 #include <nv/stl/functional/hash.hh> 16 17 #include <nv/stl/type_traits/properties.hh> 17 18 … … 55 56 struct type_field 56 57 { 57 uint 32name; //!< name of the field58 uint64 name; //!< name of the field 58 59 type_hash hash; //!< typeinfo for later retrieval of type 59 60 type_entry* type; //!< pointer to field type … … 64 65 struct type_enum 65 66 { 66 uint 32name;67 uint64 name; 67 68 sint32 value; 68 69 }; … … 75 76 76 77 type_database* type_db; //!< Parent type database 77 uint 32name; //!< Scoped C++ name of the type78 uint64 name; //!< Scoped C++ name of the type 78 79 constructor_func constructor; //!< Pointers to the constructor 79 80 destructor_func destructor; //!< Pointers to the destructor … … 82 83 vector<type_field> field_list; //!< Field list 83 84 vector<type_enum> enum_list; //!< Enum list 84 cstring_store names;85 85 }; 86 86 … … 109 109 { 110 110 public: 111 friend class type_creator; 112 111 113 template< typename TYPE > 112 114 type_creator create_type( const char* name ) 113 115 { 114 116 NV_ASSERT( !m_names.exists( name ), "Type redefinition!" ); 115 uint 32 name_idx = m_names.push( name );117 uint64 name_hash = m_names.insert( name ); 116 118 type_entry* i_type = new type_entry; 117 119 i_type->type_db = this; 118 i_type->name = name_ idx;120 i_type->name = name_hash; 119 121 i_type->size = sizeof( TYPE ); 120 122 121 123 i_type->constructor = raw_construct_object < TYPE >; 122 124 i_type->destructor = raw_destroy_object < TYPE >; 123 m_idx_types[typeid( TYPE )] = i_type; 125 m_index_by_type[typeid( TYPE )] = i_type; 126 m_index_by_name[name_hash] = i_type; 124 127 m_type_list.push_back( i_type ); 125 128 return type_creator( this, i_type ); … … 128 131 type_entry* get_type( const char* name ) 129 132 { 130 uint32 name_idx = m_names.resolve( name ); 131 if ( name_idx < m_type_list.size() ) 132 { 133 return m_type_list[name_idx]; 134 } 135 return nullptr; 133 uint64 name_hash = hash_string<type_hash>( name ); 134 auto it = m_index_by_name.find( name_hash ); 135 return it != m_index_by_name.end() ? it->second : nullptr; 136 136 } 137 137 138 138 type_entry* get_type( type_hash hash ) 139 139 { 140 type_ info_map::iterator it = m_idx_types.find( hash );141 if ( it != m_i dx_types.end() )140 type_hash_map::iterator it = m_index_by_type.find( hash ); 141 if ( it != m_index_by_type.end() ) 142 142 { 143 143 return it->second; … … 146 146 } 147 147 148 const char* resolve_name( uint32 name_idx)149 { 150 return m_names .get( name_idx );148 string_view resolve_name( uint64 name_hash ) 149 { 150 return m_names[name_hash]; 151 151 } 152 152 … … 157 157 private: 158 158 typedef vector<type_entry*> type_list; 159 typedef unordered_map<type_hash, type_entry*> type_ info_map;160 cstring_storem_names;159 typedef unordered_map<type_hash, type_entry*> type_hash_map; 160 string_table m_names; 161 161 type_list m_type_list; 162 type_info_map m_idx_types; 162 type_hash_map m_index_by_type; 163 type_hash_map m_index_by_name; 163 164 }; 164 165 … … 176 177 NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" ); 177 178 type_field f; 178 f.name = m_ entry->names.insert( name );179 f.name = m_database->m_names.insert( name ); 179 180 f.hash = rtti_type_hash< remove_pointer_t<field_type> >::hash(); 180 181 f.type = type_db->get_type( f.hash ); … … 192 193 NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" ); 193 194 type_field f; 194 f.name = m_ entry->names.insert( name );195 f.name = m_database->m_names.insert( name ); 195 196 f.hash = rtti_type_hash< remove_pointer_t<TFIELD> >::hash(); 196 197 f.type = type_db->get_type( f.hash ); … … 207 208 NV_ASSERT( m_entry->field_list.empty(), "Type cannot have both enums and fields!" ); 208 209 type_enum e; 209 e.name = m_ entry->names.insert( name );210 e.name = m_database->m_names.insert( name ); 210 211 e.value = value; 211 212 m_entry->enum_list.push_back( e );
Note: See TracChangeset
for help on using the changeset viewer.