Changeset 266
- Timestamp:
- 06/19/14 03:49:49 (11 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/common.hh
r262 r266 143 143 namespace nv 144 144 { 145 class uid_store;146 147 145 namespace lua 148 146 { -
trunk/nv/gui/gui_element.hh
r257 r266 186 186 */ 187 187 virtual void recalculate_absolute_children(); 188 189 /** 190 * Moves element to back of child list (top of stack) 191 * 192 * @returns true if object found, false otherwise 193 */ 194 bool move_to_top( element* child ); 195 196 /** 197 * Moves element to front of child list (bottom of stack) 198 * 199 * @returns true if object found, false otherwise 200 */ 201 bool move_to_bottom( element* child ); 188 202 189 203 protected: -
trunk/nv/object.hh
r265 r266 20 20 public: 21 21 friend class root; 22 23 /**24 * Register the object type in the type database.25 */26 //static void register_type( type_database* db );27 22 28 23 /// List type … … 134 129 const std::string& get_id() const { return m_id; } 135 130 136 /**137 * Returns object UID138 */139 int get_lua_index() const { return m_lua_index; }140 141 /**142 * Moves object to back of child list (top of stack)143 *144 * @returns true if object found, false otherwise145 */146 bool move_to_top( object* child );147 148 /**149 * Moves object to front of child list (bottom of stack)150 *151 * @returns true if object found, false otherwise152 */153 bool move_to_bottom( object* child );154 155 131 list::iterator begin() { return m_children.begin(); } 156 132 list::iterator end() { return m_children.end(); } … … 168 144 string m_name; ///< name of the object 169 145 uid m_uid; ///< uid of the object 170 int m_lua_index; ///< lua reference171 int m_lua_proto_index; ///< lua reference172 146 object* m_parent; ///< pointer to parent 173 147 list m_children; ///< children objects -
trunk/nv/root.hh
r264 r266 20 20 { 21 21 public: 22 root() : m_lua_state( nullptr ), m_uid_store( nullptr ) {} 23 lua::state* get_lua_state() const { return m_lua_state; } 24 uid_store* get_uid_store() const { return m_uid_store; } 22 root() {} 25 23 template < typename T > 26 24 object* create_object( const std::string& id ) … … 30 28 return o; 31 29 } 32 void register_with_lua( object* o, const char* lua_name, const char* storage );33 30 void destroy_children( object* o ); 34 31 virtual void destroy_object( object* o ); 35 32 virtual ~root() {} 36 33 protected: 37 virtual void object_created( object* o ); 38 39 lua::state* m_lua_state; 40 uid_store* m_uid_store; 34 virtual void object_created( object* ) {} 41 35 }; 42 36 -
trunk/nv/uid.hh
r262 r266 19 19 namespace nv 20 20 { 21 class object;22 21 23 class uid_store 22 class uid_store_raw 24 23 { 25 24 public: 26 25 27 26 /** 28 * Creates a new instance of the unique i ndentifier store.27 * Creates a new instance of the unique identifier store. 29 28 */ 30 uid_store ();29 uid_store_raw(); 31 30 32 31 /** … … 36 35 * @returns The stored object for that ID. 37 36 */ 38 object* get( uid auid ) const;37 void* get( uid auid ) const; 39 38 40 39 /** … … 52 51 * @param auid The ID to assign to the object. 53 52 */ 54 void insert( object* o, uid auid );53 void insert( void* o, uid auid ); 55 54 56 55 /** … … 60 59 * @returns The ID the object was store under. 61 60 */ 62 uid insert( object* o );61 uid insert( void* o ); 63 62 64 63 /** … … 72 71 * Destroys the unique identifier store. 73 72 */ 74 ~uid_store(); 73 ~uid_store_raw(); 74 75 protected: 76 typedef std::unordered_map< uid, void* > map; 77 map m_map; ///< The hash map everything is stored in. 78 uid m_current; ///< The last UID assigned. 79 }; 80 81 template < typename T > 82 class uid_store 83 { 84 public: 85 T* get( uid auid ) const { return static_cast<T*>( m_store.get( auid ) ); } 86 bool remove( uid auid ) { m_store.remove( auid ); } 87 void insert( T* o, uid auid ) { m_store.insert( o, auid ); } 88 uid insert( T* o ) { return m_store.insert( o ); } 89 uid request_uid() { return m_store.request_uid(); } 75 90 76 91 /** … … 81 96 * @returns An object of the indicated type that was stored at the indicated ID. 82 97 */ 83 template< typename T>84 T* get_as( uid auid ) const98 template< typename U > 99 U* get_as( uid auid ) const 85 100 { 86 return dynamic_cast< T* >( get(auid) );101 return dynamic_cast< U* >( get(auid) ); 87 102 } 88 private: 89 typedef std::unordered_map< uid, object* > map; 90 map m_map; ///< The hash map everything is stored in. 91 uid m_current; ///< The last UID assigned. 103 protected: 104 uid_store_raw m_store; 92 105 }; 106 93 107 } 94 108 -
trunk/src/gui/gui_element.cc
r257 r266 81 81 } 82 82 83 84 bool element::move_to_top( element* child ) 85 { 86 list::iterator it = std::find( m_children.begin(), m_children.end(), (object*)child ); 87 if ( it != m_children.end() ) 88 { 89 m_children.erase( it ); 90 m_children.push_back( child ); 91 return true; 92 } 93 return false; 94 } 95 96 bool element::move_to_bottom( element* child ) 97 { 98 list::iterator it = std::find( m_children.begin(), m_children.end(), (object*)child ); 99 if ( it != m_children.end() ) 100 { 101 m_children.erase( it ); 102 m_children.push_front( child ); 103 return true; 104 } 105 return false; 106 } 107 83 108 element::~element() 84 109 { -
trunk/src/object.cc
r265 r266 8 8 9 9 #include <algorithm> 10 #include "nv/types.hh"11 #include "nv/lua/lua_state.hh"12 #include "nv/uid.hh"13 10 14 11 using namespace nv; … … 18 15 , m_name() 19 16 , m_uid(0) 20 , m_lua_index(lua::ref::none)21 , m_lua_proto_index(lua::ref::none)22 17 , m_parent( nullptr ) 23 18 , m_children() … … 124 119 } 125 120 126 bool object::move_to_top( object* child )127 {128 list::iterator it = std::find( m_children.begin(), m_children.end(), child );129 if ( it != m_children.end() )130 {131 m_children.erase( it );132 m_children.push_back( child );133 return true;134 }135 return false;136 }137 138 bool object::move_to_bottom( object* child )139 {140 list::iterator it = std::find( m_children.begin(), m_children.end(), child );141 if ( it != m_children.end() )142 {143 m_children.erase( it );144 m_children.push_front( child );145 return true;146 }147 return false;148 }149 121 150 122 // void object::register_type( type_database* db ) -
trunk/src/root.cc
r265 r266 10 10 #include "nv/lua/lua_state.hh" 11 11 12 void nv::root::object_created( object* o )13 {14 if ( m_uid_store )15 {16 o->m_uid = m_uid_store->insert( o );17 }18 }19 20 12 void nv::root::destroy_object( object* o ) 21 13 { 22 14 destroy_children( o ); 23 15 o->detach(); 24 if ( m_lua_state && o->m_lua_index != lua::ref::none )25 {26 m_lua_state->unregister_object( lua::ref( o->m_lua_index ) );27 }28 if ( m_uid_store && o->m_uid != 0 )29 {30 m_uid_store->remove( o->m_uid );31 }32 16 delete o; 33 17 } … … 40 24 } 41 25 } 42 43 void nv::root::register_with_lua( object* o, const char* lua_name, const char* storage )44 {45 if ( m_lua_state )46 {47 if ( lua_name != nullptr )48 {49 o->m_lua_index = m_lua_state->register_object( o, lua_name ).get();50 }51 if ( storage != nullptr )52 {53 o->m_lua_proto_index = m_lua_state->register_proto( o->get_id().c_str(), storage ).get();54 }55 }56 57 }58 -
trunk/src/uid.cc
r59 r266 9 9 using namespace nv; 10 10 11 uid_store ::uid_store()11 uid_store_raw::uid_store_raw() 12 12 : m_map(), m_current(0) 13 13 { … … 15 15 } 16 16 17 object* uid_store::get( uid auid ) const17 void* uid_store_raw::get( uid auid ) const 18 18 { 19 19 map::const_iterator i = m_map.find( auid ); … … 25 25 } 26 26 27 bool uid_store ::remove( uid auid )27 bool uid_store_raw::remove( uid auid ) 28 28 { 29 29 return m_map.erase( auid ) != 0; 30 30 } 31 31 32 void uid_store ::insert( object* o, uid auid )32 void uid_store_raw::insert( void* o, uid auid ) 33 33 { 34 34 m_map[ auid ] = o; 35 35 } 36 36 37 uid uid_store ::insert( object* o )37 uid uid_store_raw::insert( void* o ) 38 38 { 39 39 uid u = request_uid(); … … 42 42 } 43 43 44 uid uid_store ::request_uid()44 uid uid_store_raw::request_uid() 45 45 { 46 46 return ++m_current; 47 47 } 48 48 49 uid_store ::~uid_store()49 uid_store_raw::~uid_store_raw() 50 50 { 51 51 // no-op
Note: See TracChangeset
for help on using the changeset viewer.