Changeset 333
- Timestamp:
- 09/17/14 14:18:10 (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/handle.hh
r323 r333 29 29 public: 30 30 typedef T value_type; 31 typedef TAG tag_type; 31 32 static const int INDEX_BITS = IBITS; 32 33 static const int COUNTER_BITS = IBITS; … … 48 49 49 50 handle( T a_index, T a_counter ) : m_index( a_index ), m_counter( a_counter ) {} 50 template < typename H, typename I > 51 friend class index_store; 52 }; 53 51 template < typename H > 52 friend class handle_operator; 53 }; 54 55 template < typename HANDLE > 56 class handle_operator 57 { 58 public: 59 typedef typename HANDLE::value_type value_type; 60 61 static HANDLE create( value_type index, value_type counter ) 62 { 63 return HANDLE( index, counter ); 64 } 65 static value_type get_counter( const HANDLE& h ) { return h.m_counter; } 66 static value_type get_index( const HANDLE& h ) { return h.m_index; } 67 }; 54 68 55 69 … … 66 80 handle create_handle( index_type index ) 67 81 { 82 typedef handle_operator<HANDLE> hop; 68 83 value_type i = get_free_entry(); 69 84 m_entries[i].index = index; 70 85 m_entries[i].counter++; 71 return h andle( i, m_entries[i].counter );86 return hop::create( i, m_entries[i].counter ); 72 87 } 73 88 74 89 void free_handle( handle h ) 75 90 { 76 m_entries[ h. m_index].index = -1;77 m_entries[ h. m_index].next_free = -1;91 m_entries[ h.index() ].index = -1; 92 m_entries[ h.index() ].next_free = -1; 78 93 if ( m_last_free == -1 ) 79 94 { 80 m_first_free = m_last_free = h. m_index;95 m_first_free = m_last_free = h.index(); 81 96 return; 82 97 } 83 m_entries[ (unsigned)m_last_free ].next_free = h. m_index;84 m_last_free = h. m_index;98 m_entries[ (unsigned)m_last_free ].next_free = h.index(); 99 m_last_free = h.index(); 85 100 } 86 101 87 102 void swap_indices( handle h1, handle h2 ) 88 103 { 89 std::swap( m_entries[ h1. m_index ].index, m_entries[ h2.m_index].index );104 std::swap( m_entries[ h1.index() ].index, m_entries[ h2.index() ].index ); 90 105 } 91 106 92 107 sint32 get_index( handle h ) const 93 108 { 94 return m_entries[ h.m_index ].counter == h.m_counter ? m_entries[ h.m_index ].index : -1; 109 typedef handle_operator<HANDLE> hop; 110 return m_entries[ h.index() ].counter == hop::get_counter(h) ? m_entries[ h.index() ].index : -1; 95 111 } 96 112 private: -
trunk/nv/lua/lua_state.hh
r319 r333 14 14 #include <nv/core/common.hh> 15 15 #include <nv/core/flags.hh> 16 #include <nv/core/handle.hh> 16 17 #include <istream> 17 18 #include <map> -
trunk/src/lua/lua_state.cc
r319 r333 261 261 lua_pushliteral(m_state, LUA_TABLIBNAME); 262 262 lua_call(m_state, 1, 0); 263 264 { 265 // Preregister 8 references for Handle registry 266 lua_newtable(m_state); 267 NV_ASSERT( luaL_ref( m_state, LUA_REGISTRYINDEX ) == 1, "First reference not 1!" ); 268 for ( uint32 i = 1; i < 8; ++i ) 269 { 270 lua_newtable(m_state); 271 luaL_ref( m_state, LUA_REGISTRYINDEX ); 272 } 273 } 263 274 264 275 if ( load_libs )
Note: See TracChangeset
for help on using the changeset viewer.