Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9671 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Aug 21, 2006, 4:14:57 PM (18 years ago)
Author:
bensch
Message:

trunk: just realized, that polimorphism again is the evil part of classes.
Classes, that derive say from PNode and Element2D force that Element2D is registered after PNode, which means, that Element2D is interpretet as being derived from PNode in my implmentational idea…
hmm… now go for some new approach, this cannot and will not be the end of this…

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

Legend:

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

    r9666 r9671  
    3636{
    3737  assert(_objectList != NULL);
    38 
    39 
    40   //  _objectList->unregister(this);
     38  _objectList->unregisterObject(this->_iterators);
    4139}
    4240
  • trunk/src/lib/lang/new_class_id.h

    r9667 r9671  
    2626
    2727private:
    28   NewObjectListBase*            _objectList;
     28  NewObjectListBase*                           _objectList;
    2929  std::list<NewObjectListBase::IteratorBase*>  _iterators; //!< Iterators to the class-list's positions.
    3030};
    3131
    3232
    33 template<class T> void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)
     33template<class T>
     34    inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)
    3435{
    3536  this->_objectList = &objectList;
    36   _iterators.push_back(objectList.registerObject(object));
     37  _iterators.push_back(objectList.registerObject(object, this->_objectList));
    3738}
    3839
  • trunk/src/lib/lang/new_object_list.cc

    r9664 r9671  
    2424{
    2525  if (NewObjectListBase::_classes == NULL)
    26     NewObjectListBase::_classes = new cList;
     26    NewObjectListBase::_classes = new cSet;
     27
     28
    2729  assert(!NewObjectListBase::classNameExists(className) && "Classes should not be included once, and no two classes should have the same name (key value)");
    2830
     
    3739
    3840int NewObjectListBase::_idCounter = 0;
    39 NewObjectListBase::cList* NewObjectListBase::_classes = NULL;
     41NewObjectListBase::cSet* NewObjectListBase::_classes = NULL;
    4042
    4143
     
    4850bool NewObjectListBase::classNameExists(const std::string& name)
    4951{
    50   cList::iterator it;
     52  cSet::iterator it;
    5153  for (it = NewObjectListBase::_classes->begin(); it != NewObjectListBase::_classes->end(); it++)
    5254    if(*it != NULL && (*it)->name() != name)
  • trunk/src/lib/lang/new_object_list.h

    r9667 r9671  
    1111#include <set>
    1212#include <list>
     13#include <vector>
    1314#include <string>
    1415
     
    3334
    3435  /// Comparing operators.
    35   bool compareName(const NewObjectListBase& more) { return this->_name < more.name(); };
    36   bool compareID(const NewObjectListBase& more) { return this->_id < more.id(); };
     36  bool compareName(const NewObjectListBase& more) const { return this->_name < more.name(); };
     37  bool compareID(const NewObjectListBase& more) const { return this->_id < more.id(); };
     38
     39  virtual void debug() const = 0;
    3740
    3841  static unsigned int                   classCount() { return _idCounter; };
     
    4245  static const std::list<std::string>&  getClassNames();
    4346
     47  virtual void unregisterObject(std::list<NewObjectListBase::IteratorBase*> _iterators) = 0;
     48
    4449protected:
    45 
    4650  NewObjectListBase(const std::string& className);
    47   ~NewObjectListBase();
     51  virtual ~NewObjectListBase();
    4852
    4953private:
     
    5256  static bool classNameExists(const std::string& className);
    5357
     58protected:
     59  typedef std::set<NewObjectListBase*>     cSet;    //!< The Generic Set.
     60  typedef std::vector<NewObjectListBase*>  cVector; //!< The
     61
     62  int                           _id;                //!< The ID of the class.
     63  std::string                   _name;              //!< The Name of the Class.
     64
     65  cVector                       _typeOfList;        //!< A List of all classes this class is derived of, and the class itself, ordered by age of addition.
     66  cSet                          _typeOfSet;         //!< A Set of all classes this is derived from and the class itself (for isA).
    5467private:
    55   int                           _id;
    56   std::string                   _name;
    5768
    58 private:
    59   typedef std::set<NewObjectListBase*>  cList;
    60 
    61   static int                           _idCounter;      //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe.
    62   static cList*                        _classes;        //!< A Set of all the classes in existance.
    63   static std::list<std::string>        _classNames;     //!< A list of all the registered ClassNames.
     69  static int                    _idCounter;         //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe.
     70  static cSet*                  _classes;           //!< A Set of all the classes in existance.
     71  static std::list<std::string> _classNames;        //!< A list of all the registered ClassNames.
    6472};
    6573
     
    7684{
    7785public:
    78   typedef std::list<T*>               list;
    79   typedef typename list::iterator     iterator;
     86  typedef std::list<T*>                  list;
     87  typedef typename list::iterator        iterator;
     88  typedef typename list::const_iterator  const_iterator;
    8089
    8190class Iterator : public NewObjectListBase::IteratorBase
     
    93102  inline const list&      objects() const { return _objects; };
    94103
    95   NewObjectListBase::IteratorBase* registerObject(T* object);
     104  NewObjectListBase::IteratorBase* registerObject(T* object, NewObjectListBase* objectList);
    96105  void unregisterObject(const IteratorBase& iterator);
     106  virtual void unregisterObject(std::list<NewObjectListBase::IteratorBase*> _iterators) = 0;
     107
     108  virtual void debug() const;
    97109
    98110private:
     
    119131NewObjectList<T>::~NewObjectList()
    120132{
    121  // assert(_objects.empty());
     133  // assert(_objects.empty());
    122134}
    123135
     
    133145
    134146template <class T>
    135 NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object)
     147    NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object, NewObjectListBase* objectList)
    136148{
     149  if(this->_typeOfList.empty())
     150  {
     151    this->_typeOfList.push_back(objectList);
     152  }
     153
    137154  this->_objects.push_front(object);
    138155  return new Iterator(this->_objects.begin());
     
    146163}
    147164
     165#include <iostream>
     166
     167template <class T>
     168void NewObjectList<T>::debug() const
     169{
     170  const_iterator it;
     171  for (it = this->_objects.begin(); it != this->_objects.end(); ++it)
     172  {
     173    std::cout << (*it)->name() << std::endl;
     174  }
     175}
    148176
    149177#endif /* _NEW_OBJECT_LIST_H */
  • trunk/src/lib/lang/test_object_list.cc

    r9669 r9671  
    33#include <iostream>
    44
    5 class Test
     5class BaseObject
     6{
     7  public:
     8    void setName(const std::string& name) { this->_objectName = name; };
     9  const std::string& name() const { return _objectName; };
     10  bool operator==(const std::string& name) const { return _objectName == name; };
     11
     12protected:
     13  template<class T>
     14      inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); };
     15  private:
     16  NewClassID    _id;
     17  std::string   _objectName;
     18
     19};
     20
     21class Test : public BaseObject
    622{
    723public:
     
    1632
    1733Test::Test()
    18 {  std::cout << "Test()\n"; };
     34{
     35  this->registerObject(this, Test::objectList);
     36  std::cout << "Test()\n";
     37};
    1938Test::~Test()
    2039{ std::cout << "~Test()\n"; }
    2140
    22 class Bone
     41class Bone : public BaseObject
    2342{
    2443public:
    25   Bone() { std::cout << "Bone()\n"; };
     44  Bone() {
     45    this->registerObject(this, Bone::objectList);
     46    std::cout << "Bone()\n"; };
    2647  ~Bone() { std::cout << "~Bone()\n"; };
    2748  NewObjectListDeclaration(Bone);
     
    3253{
    3354  Test* test = new Test();
     55  test->setName("Testing");
    3456
    35   NewClassID id;
    36   id.registerObject(test, Test::objectList);
     57  Test::objectList.debug();
    3758
    3859  delete test;
     60
     61  Test::objectList.debug();
    3962  Bone* bone = new Bone();
    4063  delete bone;
     64
     65
    4166
    4267  std::cout << NewObjectListBase::classCount() << std::endl;
Note: See TracChangeset for help on using the changeset viewer.