Changeset 273
- Timestamp:
- 07/04/14 19:13:27 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/handle.hh
r272 r273 36 36 handle() : m_index(0), m_counter(0) {} 37 37 38 inline bool operator==(const handle& rhs) {return m_index == rhs.m_index && m_counter == rhs.m_counter; }39 inline bool operator!=(const handle& rhs) {return !(*this == rhs);}38 inline bool operator==(const handle& rhs) const {return m_index == rhs.m_index && m_counter == rhs.m_counter; } 39 inline bool operator!=(const handle& rhs) const {return !(*this == rhs);} 40 40 41 41 bool is_nil() const { return m_index == 0 && m_counter == 0; } 42 42 bool is_valid() const { return !is_nil(); } 43 43 T index() const { return m_index; } 44 size_t hash() const { return std::hash<T>()( m_counter << IBITS | m_index ); } 44 45 protected: 45 46 T m_index : IBITS; … … 50 51 friend class index_store; 51 52 }; 53 54 52 55 53 56 template < typename HANDLE, typename TINDEX = sint32 > … … 120 123 }; 121 124 125 126 122 127 template < typename T, typename HANDLE = handle<>, typename TINDEX = sint32 > 123 128 class entity_store … … 134 139 135 140 entity_store() {} 141 142 explicit entity_store( uint32 reserve ) 143 { 144 m_handles.reserve( reserve ); 145 m_data.reserve( reserve ); 146 } 147 136 148 handle create() 137 149 { … … 140 152 return m_handles.back(); 141 153 } 154 142 155 value_type* get( handle h ) 143 156 { … … 146 159 return eindex >= 0 ? &(m_data[ eindex ]) : nullptr; 147 160 } 161 162 handle get_handle( index_type i ) const { return m_handles[i]; } 163 const T& operator[] ( index_type i ) const { return m_data[i]; } 164 T& operator[] ( index_type i ) { return m_data[i]; } 165 size_t size() const { return m_data.size(); } 166 148 167 void destroy( handle e ) 149 168 { … … 175 194 }; 176 195 177 178 179 196 } 180 197 198 namespace std 199 { 200 template < 201 typename T, 202 unsigned IBITS, 203 unsigned CBITS, 204 typename TAG 205 > 206 struct hash<nv::handle<T,IBITS,CBITS,TAG>> 207 { 208 size_t operator()(const nv::handle<T,IBITS,CBITS,TAG>& h) const 209 { 210 return h.hash(); 211 } 212 }; 213 } 214 181 215 #endif // NV_HANDLE_HH
Note: See TracChangeset
for help on using the changeset viewer.