Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9672 in orxonox.OLD for trunk


Ignore:
Timestamp:
Aug 21, 2006, 5:58:01 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: ClassList objectively implemented. This is not the fastest, but the most modular approach.
Now is the question of redundancy in code writing:
Should the ClassWriter explicitely declare a Class with superclasses, or should on runtime each object decide for itself, as it is done in BaseObject at the moment… questions questions questions…

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

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/Makefile.am

    r9670 r9672  
    1919
    2020
    21 check_PROGRAMS = test_object_list
     21bin_PROGRAMS = test_object_list
    2222
    2323test_object_list_SOURCES = \
  • trunk/src/lib/lang/new_class_id.cc

    r9671 r9672  
    2626 */
    2727NewClassID::NewClassID ()
    28     : _objectList(NULL)
    2928{}
    3029
     
    3534NewClassID::~NewClassID ()
    3635{
    37   assert(_objectList != NULL);
    38   _objectList->unregisterObject(this->_iterators);
     36  //  assert(_objectList != NULL);
     37  std::list<NewObjectListBase::ClassEntry>::iterator it;
     38  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     39    (*it)._objectList->unregisterObject((*it)._iterator);
     40  //_objectList->unregisterObject(this->_iterators);
    3941}
    4042
  • trunk/src/lib/lang/new_class_id.h

    r9671 r9672  
    2626
    2727private:
    28   NewObjectListBase*                           _objectList;
    29   std::list<NewObjectListBase::IteratorBase*>  _iterators; //!< Iterators to the class-list's positions.
     28  std::list<NewObjectListBase::ClassEntry>       _classes;
    3029};
    3130
     
    3433    inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)
    3534{
    36   this->_objectList = &objectList;
    37   _iterators.push_back(objectList.registerObject(object, this->_objectList));
     35  this->_classes.push_back(NewObjectListBase::ClassEntry(&objectList, objectList.registerObject(object)));
     36
     37  /*  this->_objectList = &objectList;
     38  _iterators.push_back(objectList.registerObject(object, this->_objectList));*/
    3839}
    3940
  • trunk/src/lib/lang/new_object_list.h

    r9671 r9672  
    2525public:
    2626  class IteratorBase { };
     27  struct ClassEntry{
     28    inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
     29    NewObjectListBase*                _objectList;
     30    NewObjectListBase::IteratorBase*  _iterator;
     31  };
    2732
    2833public:
     
    4550  static const std::list<std::string>&  getClassNames();
    4651
    47   virtual void unregisterObject(std::list<NewObjectListBase::IteratorBase*> _iterators) = 0;
     52  virtual void unregisterObject(IteratorBase* _iterators) = 0;
    4853
    4954protected:
     
    9196  {
    9297  public:
    93     Iterator(iterator it) { it = it; }
    94     typename NewObjectList::iterator it;
     98    Iterator(iterator it) { _it = it; }
     99    inline iterator& it() { return _it; }
     100    typename NewObjectList::iterator _it;
    95101  };
    96102
     
    102108  inline const list&      objects() const { return _objects; };
    103109
    104   NewObjectListBase::IteratorBase* registerObject(T* object, NewObjectListBase* objectList);
    105   void unregisterObject(const IteratorBase& iterator);
    106   virtual void unregisterObject(std::list<NewObjectListBase::IteratorBase*> _iterators) = 0;
     110  NewObjectListBase::IteratorBase* registerObject(T* object);
     111  void unregisterObject(IteratorBase* iterator);
    107112
    108113  virtual void debug() const;
     
    145150
    146151template <class T>
    147     NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object, NewObjectListBase* objectList)
     152    NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object)
    148153{
    149   if(this->_typeOfList.empty())
    150   {
    151     this->_typeOfList.push_back(objectList);
    152   }
    153 
    154154  this->_objects.push_front(object);
    155155  return new Iterator(this->_objects.begin());
     
    157157
    158158template <class T>
    159 void NewObjectList<T>::unregisterObject(const IteratorBase& iterator)
     159void NewObjectList<T>::unregisterObject(IteratorBase* iterator)
    160160{
    161   this->_objects.erase(static_cast<Iterator>(iterator));
     161  this->_objects.erase(static_cast<Iterator*>(iterator)->it());
    162162  //_objects.erase(std::find(_objects.begin(), _objects.end(), object));
    163163}
  • trunk/src/lib/lang/test_object_list.cc

    r9671 r9672  
    1010  bool operator==(const std::string& name) const { return _objectName == name; };
    1111
     12  NewObjectListDeclaration(BaseObject);
     13
     14
    1215protected:
     16  BaseObject(const std::string& objectName = "") : _objectName(objectName) { this->registerObject(this, objectList); };
    1317  template<class T>
    1418      inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); };
     
    1721  std::string   _objectName;
    1822
     23
    1924};
     25NewObjectListDefinition(BaseObject);
     26
    2027
    2128class Test : public BaseObject
     
    5360{
    5461  Test* test = new Test();
    55   test->setName("Testing");
     62  test->setName("Test-object");
    5663
    5764  Test::objectList.debug();
    5865
    59   delete test;
    6066
    6167  Test::objectList.debug();
    6268  Bone* bone = new Bone();
     69  bone->setName("Bone-object");
     70
     71  std::cout << "Here is debug of all Classes\n";
     72  BaseObject::objectList.debug();
    6373  delete bone;
     74  delete test;
    6475
    65 
    66 
    67   std::cout << NewObjectListBase::classCount() << std::endl;
    6876}
    6977
Note: See TracChangeset for help on using the changeset viewer.