Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10114 in orxonox.OLD for trunk/src/lib/lang/object_list.cc


Ignore:
Timestamp:
Dec 19, 2006, 11:55:26 PM (19 years ago)
Author:
patrick
Message:

merged network back to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/object_list.cc

    r9869 r10114  
    2525 * @return a new NewObejctList
    2626 */
    27 ObjectListBase::ObjectListBase(const std::string& className, int id)
     27ObjectListBase::ObjectListBase(const std::string& className)
    2828    : _name(className)
    2929{
     
    3636  assert(!ObjectListBase::classNameExists(className) && "Classes should only be included once, and no two classes should have the same name (key value)");
    3737
    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
    4442  assert(!ObjectListBase::classIDExists(id) && "Classes should only be included once, and no two classes should have the same ID (key value)");
    4543
     
    330328    return -1;
    331329}
     330
     331
     332/**
     333 * replace all ids. list must contain all (and no more) ids
     334 * @param str2id list: string -> newId
     335 */
     336void 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 */
     361std::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.