Changeset 9671 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Aug 21, 2006, 4:14:57 PM (18 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/new_class_id.cc
r9666 r9671 36 36 { 37 37 assert(_objectList != NULL); 38 39 40 // _objectList->unregister(this); 38 _objectList->unregisterObject(this->_iterators); 41 39 } 42 40 -
trunk/src/lib/lang/new_class_id.h
r9667 r9671 26 26 27 27 private: 28 NewObjectListBase* _objectList;28 NewObjectListBase* _objectList; 29 29 std::list<NewObjectListBase::IteratorBase*> _iterators; //!< Iterators to the class-list's positions. 30 30 }; 31 31 32 32 33 template<class T> void NewClassID::registerObject(T* object, NewObjectList<T>& objectList) 33 template<class T> 34 inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList) 34 35 { 35 36 this->_objectList = &objectList; 36 _iterators.push_back(objectList.registerObject(object ));37 _iterators.push_back(objectList.registerObject(object, this->_objectList)); 37 38 } 38 39 -
trunk/src/lib/lang/new_object_list.cc
r9664 r9671 24 24 { 25 25 if (NewObjectListBase::_classes == NULL) 26 NewObjectListBase::_classes = new cList; 26 NewObjectListBase::_classes = new cSet; 27 28 27 29 assert(!NewObjectListBase::classNameExists(className) && "Classes should not be included once, and no two classes should have the same name (key value)"); 28 30 … … 37 39 38 40 int NewObjectListBase::_idCounter = 0; 39 NewObjectListBase::c List* NewObjectListBase::_classes = NULL;41 NewObjectListBase::cSet* NewObjectListBase::_classes = NULL; 40 42 41 43 … … 48 50 bool NewObjectListBase::classNameExists(const std::string& name) 49 51 { 50 c List::iterator it;52 cSet::iterator it; 51 53 for (it = NewObjectListBase::_classes->begin(); it != NewObjectListBase::_classes->end(); it++) 52 54 if(*it != NULL && (*it)->name() != name) -
trunk/src/lib/lang/new_object_list.h
r9667 r9671 11 11 #include <set> 12 12 #include <list> 13 #include <vector> 13 14 #include <string> 14 15 … … 33 34 34 35 /// 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; 37 40 38 41 static unsigned int classCount() { return _idCounter; }; … … 42 45 static const std::list<std::string>& getClassNames(); 43 46 47 virtual void unregisterObject(std::list<NewObjectListBase::IteratorBase*> _iterators) = 0; 48 44 49 protected: 45 46 50 NewObjectListBase(const std::string& className); 47 ~NewObjectListBase();51 virtual ~NewObjectListBase(); 48 52 49 53 private: … … 52 56 static bool classNameExists(const std::string& className); 53 57 58 protected: 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). 54 67 private: 55 int _id;56 std::string _name;57 68 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. 64 72 }; 65 73 … … 76 84 { 77 85 public: 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; 80 89 81 90 class Iterator : public NewObjectListBase::IteratorBase … … 93 102 inline const list& objects() const { return _objects; }; 94 103 95 NewObjectListBase::IteratorBase* registerObject(T* object );104 NewObjectListBase::IteratorBase* registerObject(T* object, NewObjectListBase* objectList); 96 105 void unregisterObject(const IteratorBase& iterator); 106 virtual void unregisterObject(std::list<NewObjectListBase::IteratorBase*> _iterators) = 0; 107 108 virtual void debug() const; 97 109 98 110 private: … … 119 131 NewObjectList<T>::~NewObjectList() 120 132 { 121 // assert(_objects.empty());133 // assert(_objects.empty()); 122 134 } 123 135 … … 133 145 134 146 template <class T> 135 NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object)147 NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object, NewObjectListBase* objectList) 136 148 { 149 if(this->_typeOfList.empty()) 150 { 151 this->_typeOfList.push_back(objectList); 152 } 153 137 154 this->_objects.push_front(object); 138 155 return new Iterator(this->_objects.begin()); … … 146 163 } 147 164 165 #include <iostream> 166 167 template <class T> 168 void 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 } 148 176 149 177 #endif /* _NEW_OBJECT_LIST_H */ -
trunk/src/lib/lang/test_object_list.cc
r9669 r9671 3 3 #include <iostream> 4 4 5 class Test 5 class 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 12 protected: 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 21 class Test : public BaseObject 6 22 { 7 23 public: … … 16 32 17 33 Test::Test() 18 { std::cout << "Test()\n"; }; 34 { 35 this->registerObject(this, Test::objectList); 36 std::cout << "Test()\n"; 37 }; 19 38 Test::~Test() 20 39 { std::cout << "~Test()\n"; } 21 40 22 class Bone 41 class Bone : public BaseObject 23 42 { 24 43 public: 25 Bone() { std::cout << "Bone()\n"; }; 44 Bone() { 45 this->registerObject(this, Bone::objectList); 46 std::cout << "Bone()\n"; }; 26 47 ~Bone() { std::cout << "~Bone()\n"; }; 27 48 NewObjectListDeclaration(Bone); … … 32 53 { 33 54 Test* test = new Test(); 55 test->setName("Testing"); 34 56 35 NewClassID id; 36 id.registerObject(test, Test::objectList); 57 Test::objectList.debug(); 37 58 38 59 delete test; 60 61 Test::objectList.debug(); 39 62 Bone* bone = new Bone(); 40 63 delete bone; 64 65 41 66 42 67 std::cout << NewObjectListBase::classCount() << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.