Changeset 429


Ignore:
Timestamp:
07/20/15 14:14:22 (10 years ago)
Author:
epyon
Message:
  • cstring_store removed - types uses string_table instead
Location:
trunk/nv
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/types.hh

    r395 r429  
    1313#include <nv/stl/vector.hh>
    1414#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>
    1617#include <nv/stl/type_traits/properties.hh>
    1718
     
    5556        struct type_field
    5657        {
    57                 uint32      name;     //!< name of the field
     58                uint64  name;     //!< name of the field
    5859                type_hash   hash; //!< typeinfo for later retrieval of type
    5960                type_entry* type;     //!< pointer to field type
     
    6465        struct type_enum
    6566        {
    66                 uint32 name;
     67                uint64 name;
    6768                sint32 value;
    6869        };
     
    7576
    7677                type_database*          type_db;     //!< Parent type database
    77                 uint32                  name;        //!< Scoped C++ name of the type
     78                uint64                  name;        //!< Scoped C++ name of the type
    7879                constructor_func        constructor; //!< Pointers to the constructor
    7980                destructor_func         destructor;  //!< Pointers to the destructor
     
    8283                vector<type_field> field_list;  //!< Field list
    8384                vector<type_enum>  enum_list;   //!< Enum list
    84                 cstring_store names;
    8585        };
    8686
     
    109109        {
    110110        public:
     111                friend class type_creator;
     112
    111113                template< typename TYPE >
    112114                type_creator create_type( const char* name )
    113115                {
    114116                        NV_ASSERT( !m_names.exists( name ), "Type redefinition!" );
    115                         uint32 name_idx = m_names.push( name );
     117                        uint64 name_hash = m_names.insert( name );
    116118                        type_entry* i_type = new type_entry;
    117119                        i_type->type_db = this;
    118                         i_type->name = name_idx;
     120                        i_type->name = name_hash;
    119121                        i_type->size = sizeof( TYPE );
    120122
    121123                        i_type->constructor = raw_construct_object < TYPE >;
    122124                        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;
    124127                        m_type_list.push_back( i_type );
    125128                        return type_creator( this, i_type );
     
    128131                type_entry* get_type( const char* name )
    129132                {
    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;
    136136                }
    137137
    138138                type_entry* get_type( type_hash hash )
    139139                {
    140                         type_info_map::iterator it = m_idx_types.find( hash );
    141                         if ( it != m_idx_types.end() )
     140                        type_hash_map::iterator it = m_index_by_type.find( hash );
     141                        if ( it != m_index_by_type.end() )
    142142                        {
    143143                                return it->second;
     
    146146                }
    147147
    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];
    151151                }
    152152
     
    157157        private:
    158158                typedef vector<type_entry*>                   type_list;
    159                 typedef unordered_map<type_hash, type_entry*> type_info_map;
    160                 cstring_store m_names;
     159                typedef unordered_map<type_hash, type_entry*> type_hash_map;
     160                string_table m_names;
    161161                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;
    163164        };
    164165       
     
    176177                NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" );
    177178                type_field f;
    178                 f.name = m_entry->names.insert( name );
     179                f.name = m_database->m_names.insert( name );
    179180                f.hash = rtti_type_hash< remove_pointer_t<field_type> >::hash();
    180181                f.type = type_db->get_type( f.hash );
     
    192193                NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" );
    193194                type_field f;
    194                 f.name = m_entry->names.insert( name );
     195                f.name = m_database->m_names.insert( name );
    195196                f.hash = rtti_type_hash< remove_pointer_t<TFIELD> >::hash();
    196197                f.type = type_db->get_type( f.hash );
     
    207208                NV_ASSERT( m_entry->field_list.empty(), "Type cannot have both enums and fields!" );
    208209                type_enum e;
    209                 e.name = m_entry->names.insert( name );
     210                e.name = m_database->m_names.insert( name );
    210211                e.value = value;
    211212                m_entry->enum_list.push_back( e );
Note: See TracChangeset for help on using the changeset viewer.