Changeset 10114 in orxonox.OLD for trunk/src/lib/lang/object_list.cc
- Timestamp:
- Dec 19, 2006, 11:55:26 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.