Changeset 370 for trunk


Ignore:
Timestamp:
05/22/15 13:23:02 (10 years ago)
Author:
epyon
Message:
  • own type_index implementation
  • more stl headers removed from nv headers
Location:
trunk/nv
Files:
2 edited

Legend:

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

    r352 r370  
    77
    88#include <nv/core/common.hh>
    9 #include <nv/core/math.hh>
    10 #include <nv/core/cstring_store.hh>
    11 #include <nv/core/type_traits.hh>
    12 #include <typeinfo>
    13 #include <typeindex>
    14 #include <utility>
     9#include <nv/stl/math.hh>
     10#include <nv/stl/cstring_store.hh>
     11#include <nv/stl/type_traits.hh>
    1512#include <unordered_map>
    1613#include <vector>
    17 #include <string>
    18 #include <cstddef>
    1914
    2015namespace nv
     
    121116                type_entry* get_type( const std::type_info& t )
    122117                {
    123                         type_info_map::iterator it = m_idx_types.find( std::type_index( t ) );
     118                        type_info_map::iterator it = m_idx_types.find( type_index( t ) );
    124119                        if ( it != m_idx_types.end() )
    125120                        {
     
    140135        private:
    141136                typedef std::vector<type_entry*>                         type_list;
    142                 typedef std::unordered_map<std::type_index, type_entry*> type_info_map;
     137                typedef std::unordered_map<type_index, type_entry*> type_info_map;
    143138                cstring_store m_names;
    144139                type_list     m_type_list;
  • trunk/nv/stl/type_traits.hh

    r368 r370  
    1818#include <nv/core/common.hh>
    1919#include <type_traits>
     20#include <typeinfo>
     21#include <string>
    2022
    2123namespace nv
     
    173175        };
    174176
     177        class type_index
     178        {
     179        public:
     180                inline type_index( const std::type_info& info ) : m_type_info( &info ) {}
     181                inline size_t hash_code() const { return m_type_info->hash_code(); }
     182                inline const char *name() const { return m_type_info->name(); }
     183
     184                inline bool operator==( const type_index& rhs ) const
     185                {
     186                        return ( *m_type_info == *rhs.m_type_info );
     187                }
     188
     189                inline bool operator!=( const type_index& rhs ) const
     190                {
     191                        return ( !( *this == rhs ) );
     192                }
     193
     194                inline bool operator<( const type_index& rhs ) const
     195                {
     196                        return ( m_type_info->before( *rhs.m_type_info ) );
     197                }
     198
     199                inline bool operator>=( const type_index& rhs ) const
     200                {
     201                        return ( !( *this < rhs ) );
     202                }
     203
     204                inline bool operator>( const type_index& rhs ) const
     205                {
     206                        return ( rhs < *this );
     207                }
     208
     209                inline bool operator<=( const type_index& rhs ) const
     210                {
     211                        return ( !( rhs < *this ) );
     212                }
     213
     214        private:
     215                const std::type_info* m_type_info;
     216        };
    175217
    176218}
    177219
     220namespace std
     221{
     222        template<>
     223        struct hash< nv::type_index >
     224        {
     225                size_t operator()( nv::type_index key ) const
     226                {
     227                        return ( key.hash_code() );
     228                }
     229        };
     230}
     231
    178232#endif // NV_CORE_TYPE_TRAITS_HH
Note: See TracChangeset for help on using the changeset viewer.