Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9671 in orxonox.OLD for trunk/src/lib/lang/new_object_list.h


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…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 */
Note: See TracChangeset for help on using the changeset viewer.