Changeset 9672 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Aug 21, 2006, 5:58:01 PM (18 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/Makefile.am
r9670 r9672 19 19 20 20 21 check_PROGRAMS = test_object_list21 bin_PROGRAMS = test_object_list 22 22 23 23 test_object_list_SOURCES = \ -
trunk/src/lib/lang/new_class_id.cc
r9671 r9672 26 26 */ 27 27 NewClassID::NewClassID () 28 : _objectList(NULL)29 28 {} 30 29 … … 35 34 NewClassID::~NewClassID () 36 35 { 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); 39 41 } 40 42 -
trunk/src/lib/lang/new_class_id.h
r9671 r9672 26 26 27 27 private: 28 NewObjectListBase* _objectList; 29 std::list<NewObjectListBase::IteratorBase*> _iterators; //!< Iterators to the class-list's positions. 28 std::list<NewObjectListBase::ClassEntry> _classes; 30 29 }; 31 30 … … 34 33 inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList) 35 34 { 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));*/ 38 39 } 39 40 -
trunk/src/lib/lang/new_object_list.h
r9671 r9672 25 25 public: 26 26 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 }; 27 32 28 33 public: … … 45 50 static const std::list<std::string>& getClassNames(); 46 51 47 virtual void unregisterObject( std::list<NewObjectListBase::IteratorBase*>_iterators) = 0;52 virtual void unregisterObject(IteratorBase* _iterators) = 0; 48 53 49 54 protected: … … 91 96 { 92 97 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; 95 101 }; 96 102 … … 102 108 inline const list& objects() const { return _objects; }; 103 109 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); 107 112 108 113 virtual void debug() const; … … 145 150 146 151 template <class T> 147 NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object , NewObjectListBase* objectList)152 NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object) 148 153 { 149 if(this->_typeOfList.empty())150 {151 this->_typeOfList.push_back(objectList);152 }153 154 154 this->_objects.push_front(object); 155 155 return new Iterator(this->_objects.begin()); … … 157 157 158 158 template <class T> 159 void NewObjectList<T>::unregisterObject( const IteratorBase&iterator)159 void NewObjectList<T>::unregisterObject(IteratorBase* iterator) 160 160 { 161 this->_objects.erase(static_cast<Iterator >(iterator));161 this->_objects.erase(static_cast<Iterator*>(iterator)->it()); 162 162 //_objects.erase(std::find(_objects.begin(), _objects.end(), object)); 163 163 } -
trunk/src/lib/lang/test_object_list.cc
r9671 r9672 10 10 bool operator==(const std::string& name) const { return _objectName == name; }; 11 11 12 NewObjectListDeclaration(BaseObject); 13 14 12 15 protected: 16 BaseObject(const std::string& objectName = "") : _objectName(objectName) { this->registerObject(this, objectList); }; 13 17 template<class T> 14 18 inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); }; … … 17 21 std::string _objectName; 18 22 23 19 24 }; 25 NewObjectListDefinition(BaseObject); 26 20 27 21 28 class Test : public BaseObject … … 53 60 { 54 61 Test* test = new Test(); 55 test->setName("Test ing");62 test->setName("Test-object"); 56 63 57 64 Test::objectList.debug(); 58 65 59 delete test;60 66 61 67 Test::objectList.debug(); 62 68 Bone* bone = new Bone(); 69 bone->setName("Bone-object"); 70 71 std::cout << "Here is debug of all Classes\n"; 72 BaseObject::objectList.debug(); 63 73 delete bone; 74 delete test; 64 75 65 66 67 std::cout << NewObjectListBase::classCount() << std::endl;68 76 } 69 77
Note: See TracChangeset
for help on using the changeset viewer.