Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

merged network back to trunk

Location:
trunk/src/lib/lang
Files:
4 edited

Legend:

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

    r9869 r10114  
    3535}
    3636
     37/**
     38 * copyconstructor
     39 * @param bo instance to copy
     40 */
     41BaseObject::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
    3750/**
    3851 * @brief standard deconstructor
     
    4558  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
    4659  {
    47     if (ORX_DEBUG >= 5)
     60    //if (ORX_DEBUG >= 5)
    4861      assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this));
    4962    (*it)._objectList->unregisterObject((*it)._iterator);
  • trunk/src/lib/lang/base_object.h

    r9869 r10114  
    3030public:
    3131  BaseObject (const std::string& objectName = "");
     32  BaseObject( const BaseObject& bo );
    3233
    3334  virtual ~BaseObject ();
     
    5152  /** @returns the ClassID of this Object */
    5253  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(); }
    5554
    5655  bool isA(const ObjectListBase& objectList) const;
  • 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}
  • trunk/src/lib/lang/object_list.h

    r9869 r10114  
    3232 * @brief Use this macro to easily define a Class to store its own ObjectListDefinition
    3333 * @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 ObjectListDefinition
    41  * @param ClassName: the Name of the Class.
    4234 */
    4335#define ObjectListDefinition(ClassName) \
    44     ObjectListDefinitionID(ClassName, -1)
     36    ObjectList<ClassName> ClassName::_objectList(#ClassName)
    4537
    4638class BaseObject;
     
    109101
    110102protected:
    111   ObjectListBase(const std::string& className, int id = -1);
     103  ObjectListBase(const std::string& className);
    112104  virtual ~ObjectListBase();
    113105
     
    133125  static NameMap*               _classesByName;     //!< A Map of all the classes in existance.
    134126  static std::list<std::string> _classNames;        //!< A list of all the registered ClassNames.
     127
     128public:
     129  static void replaceIDMap( const std::map<std::string, int>& str2id );
     130  static std::map<std::string, int>* createStrToId();
    135131};
    136132
     
    199195
    200196public:
    201   ObjectList(const std::string& name, int id = -1);
     197  ObjectList(const std::string& name);
    202198  ~ObjectList();
    203199
     
    256252 */
    257253template <class T>
    258 ObjectList<T>::ObjectList(const std::string& name, int id)
    259     : ObjectListBase(name, id)
     254ObjectList<T>::ObjectList(const std::string& name)
     255    : ObjectListBase(name)
    260256{}
    261257
Note: See TracChangeset for help on using the changeset viewer.