Changeset 10114 in orxonox.OLD for trunk/src/lib/lang
- Timestamp:
- Dec 19, 2006, 11:55:26 PM (18 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/base_object.cc
r9869 r10114 35 35 } 36 36 37 /** 38 * copyconstructor 39 * @param bo instance to copy 40 */ 41 BaseObject::BaseObject( const BaseObject& bo ) 42 { 43 this->className = "BaseObject"; 44 this->objectName = bo.objectName; 45 this->xmlElem = (bo.xmlElem)? bo.xmlElem->Clone() : NULL; 46 this->registerObject( this, BaseObject::_objectList); 47 } 48 49 37 50 /** 38 51 * @brief standard deconstructor … … 45 58 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 46 59 { 47 if (ORX_DEBUG >= 5)60 //if (ORX_DEBUG >= 5) 48 61 assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this)); 49 62 (*it)._objectList->unregisterObject((*it)._iterator); -
trunk/src/lib/lang/base_object.h
r9869 r10114 30 30 public: 31 31 BaseObject (const std::string& objectName = ""); 32 BaseObject( const BaseObject& bo ); 32 33 33 34 virtual ~BaseObject (); … … 51 52 /** @returns the ClassID of this Object */ 52 53 inline const ClassID& getClassID() const { return _classes.front()._objectList->identity(); } 53 /** @returns the ID of the Topmost object of the ClassStack */54 inline const int& getLeafClassID() const { return _classes.front()._objectList->identity().id(); }55 54 56 55 bool isA(const ObjectListBase& objectList) const; -
trunk/src/lib/lang/object_list.cc
r9869 r10114 25 25 * @return a new NewObejctList 26 26 */ 27 ObjectListBase::ObjectListBase(const std::string& className , int id)27 ObjectListBase::ObjectListBase(const std::string& className) 28 28 : _name(className) 29 29 { … … 36 36 assert(!ObjectListBase::classNameExists(className) && "Classes should only be included once, and no two classes should have the same name (key value)"); 37 37 38 if (id == -1) 39 { 40 id = ObjectListBase::_classesByID->size(); 41 // searching for a free ID 42 while (ObjectListBase::classIDExists(id)) ++id; 43 } 38 int id = ObjectListBase::_classesByID->size(); 39 // searching for a free ID 40 while (ObjectListBase::classIDExists(id)) ++id; 41 44 42 assert(!ObjectListBase::classIDExists(id) && "Classes should only be included once, and no two classes should have the same ID (key value)"); 45 43 … … 330 328 return -1; 331 329 } 330 331 332 /** 333 * replace all ids. list must contain all (and no more) ids 334 * @param str2id list: string -> newId 335 */ 336 void ObjectListBase::replaceIDMap( const std::map< std::string, int >& str2id ) 337 { 338 if ( str2id.size() != _classesByID->size() ) 339 { 340 assert( false && "size of str2id does not match" ); 341 } 342 343 IDMap * map = new IDMap(); 344 345 std::map< std::string, int >::const_iterator it; 346 for ( it = str2id.begin(); it != str2id.end(); it++ ) 347 { 348 assert( _classesByName->find( it->first ) != _classesByName->end() ); 349 (*map)[ it->second ] = (*_classesByName)[it->first]; 350 (*map)[ it->second ]->_id = it->second; 351 } 352 353 delete _classesByID; 354 _classesByID = map; 355 } 356 357 /** 358 * 359 * @return 360 */ 361 std::map< std::string, int > * ObjectListBase::createStrToId( ) 362 { 363 std::map< std::string, int > * res = new std::map< std::string, int >(); 364 365 NameMap::const_iterator it; 366 for ( it = _classesByName->begin(); it != _classesByName->end(); it++ ) 367 { 368 IDMap::const_iterator it2; 369 int id = -1; 370 for ( it2 = _classesByID->begin(); it2 != _classesByID->end(); it2++ ) 371 { 372 if ( it->second == it2->second ) 373 { 374 id = it2->first; 375 break; 376 } 377 } 378 379 assert( id != -1 ); 380 (*res)[ it->first ] = id; 381 } 382 383 return res; 384 } -
trunk/src/lib/lang/object_list.h
r9869 r10114 32 32 * @brief Use this macro to easily define a Class to store its own ObjectListDefinition 33 33 * @param ClassName: the Name of the Class. 34 * @param ID: optional set a Fixed ID.35 */36 #define ObjectListDefinitionID(ClassName, ID) \37 ObjectList<ClassName> ClassName::_objectList(#ClassName, ID)38 39 /**40 * @brief Use this macro to easily define a Class to store its own ObjectListDefinition41 * @param ClassName: the Name of the Class.42 34 */ 43 35 #define ObjectListDefinition(ClassName) \ 44 ObjectList DefinitionID(ClassName, -1)36 ObjectList<ClassName> ClassName::_objectList(#ClassName) 45 37 46 38 class BaseObject; … … 109 101 110 102 protected: 111 ObjectListBase(const std::string& className , int id = -1);103 ObjectListBase(const std::string& className); 112 104 virtual ~ObjectListBase(); 113 105 … … 133 125 static NameMap* _classesByName; //!< A Map of all the classes in existance. 134 126 static std::list<std::string> _classNames; //!< A list of all the registered ClassNames. 127 128 public: 129 static void replaceIDMap( const std::map<std::string, int>& str2id ); 130 static std::map<std::string, int>* createStrToId(); 135 131 }; 136 132 … … 199 195 200 196 public: 201 ObjectList(const std::string& name , int id = -1);197 ObjectList(const std::string& name); 202 198 ~ObjectList(); 203 199 … … 256 252 */ 257 253 template <class T> 258 ObjectList<T>::ObjectList(const std::string& name , int id)259 : ObjectListBase(name , id)254 ObjectList<T>::ObjectList(const std::string& name) 255 : ObjectListBase(name) 260 256 {} 261 257
Note: See TracChangeset
for help on using the changeset viewer.