Changeset 9673 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Aug 21, 2006, 6:22:53 PM (18 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/new_class_id.cc
r9672 r9673 35 35 { 36 36 // assert(_objectList != NULL); 37 std::list<NewObjectListBase::ClassEntry>::iterator it;37 ClassList::iterator it; 38 38 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 39 39 (*it)._objectList->unregisterObject((*it)._iterator); -
trunk/src/lib/lang/new_class_id.h
r9672 r9673 8 8 #define _NEW_CLASS_ID_H 9 9 10 #include "type_info.h" 10 #include "new_object_list.h" 11 11 12 #include <string> 12 13 #include <list> 13 #include "new_object_list.h"14 14 15 15 … … 23 23 ~NewClassID(); 24 24 25 25 26 template<class T> void registerObject(T* object, NewObjectList<T>& list); 27 bool isA(const NewObjectListBase& objectList) const; 28 bool isA(int id) const; 29 bool isA(const std::string& className) const; 26 30 27 31 private: 28 std::list<NewObjectListBase::ClassEntry> _classes; 32 33 ////////////////////////////// 34 //// Type Definition Part //// 35 ////////////////////////////// 36 //! A ClassEntry so we can store Classes inside of Objects 37 struct ClassEntry{ 38 /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */ 39 inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {} 40 NewObjectListBase* _objectList; //!< A ObjectList this Object is part of 41 NewObjectListBase::IteratorBase* _iterator; //!< An iterator pointing to the position of the Object inside of the List. 42 }; 43 typedef std::list<ClassEntry> ClassList; //!< Type definition for the List. 44 ClassList _classes; //!< All Classes this object is part of. 29 45 }; 30 46 31 47 48 /** 49 * @brief Registeres an Object of Type T to objectList 50 * @param object The Object to append to the objectList. 51 * @param objectList The ObjectList to append the Object to. 52 * 53 * This function is essential to integrate objects into their designated ObjectList. 54 * Remember if you do not want objects to be stored in Lists (less overhead), 55 * do not attempt to call this function. 56 */ 32 57 template<class T> 33 58 inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList) 34 59 { 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));*/ 60 this->_classes.push_back(ClassEntry(&objectList, objectList.registerObject(object))); 39 61 } 40 62 -
trunk/src/lib/lang/new_object_list.h
r9672 r9673 21 21 NewObjectList<ClassName> ClassName::objectList(#ClassName) 22 22 23 24 //! The superclass that all NewObjectLists follow. 25 /** 26 * @see template<class T> NewObjectList<T> 27 */ 23 28 class NewObjectListBase 24 29 { 25 30 public: 31 //! An iterator Base-Class, for iterator-casting and storing. 26 32 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 };32 33 33 34 public: … … 83 84 //! Defines a ObjectsList handler for objects of type T. 84 85 /** 86 * To define a Class with a ObjectList, you have to: 87 * 1. Include 'NewObjectListDeclaration(T);' in its Declaration (at the beginning) 88 * 2. Include 'NewObjectListDefinition(T);' in some Definition file (cc-file) 89 * 3. In the constructor add 'registerObject(this, objectList);' 90 * 85 91 * @note The Class must define the compare with const std::string& operator for this to work. 86 92 */ -
trunk/src/lib/lang/test_object_list.cc
r9672 r9673 5 5 class BaseObject 6 6 { 7 8 7 public: 8 void setName(const std::string& name) { this->_objectName = name; }; 9 9 const std::string& name() const { return _objectName; }; 10 10 bool operator==(const std::string& name) const { return _objectName == name; }; … … 16 16 BaseObject(const std::string& objectName = "") : _objectName(objectName) { this->registerObject(this, objectList); }; 17 17 template<class T> 18 19 18 inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); }; 19 private: 20 20 NewClassID _id; 21 21 std::string _objectName; … … 41 41 { 42 42 this->registerObject(this, Test::objectList); 43 std::cout << "Test()\n";43 // std::cout << "Test()\n"; 44 44 }; 45 45 Test::~Test() 46 { std::cout << "~Test()\n"; } 46 { 47 // std::cout << "~Test()\n"; 48 } 47 49 48 50 class Bone : public BaseObject 49 51 { 50 52 public: 51 Bone() { 53 Bone() 54 { 52 55 this->registerObject(this, Bone::objectList); 53 std::cout << "Bone()\n"; }; 54 ~Bone() { std::cout << "~Bone()\n"; }; 56 //std::cout << "Bone()\n"; 57 }; 58 ~Bone() { 59 // std::cout << "~Bone()\n"; 60 }; 55 61 NewObjectListDeclaration(Bone); 56 62 }; … … 59 65 int main() 60 66 { 61 Test* test = new Test();62 test->setName("Test-object");63 64 Test::objectList.debug();65 67 66 68 67 Test::objectList.debug(); 69 70 Test* test = new Test[1000000]; 71 //test->setName("Test-object"); 72 73 // Test::objectList.debug(); 74 /* 68 75 Bone* bone = new Bone(); 69 bone->setName("Bone-object"); 76 bone->setName("Bone-object");*/ 70 77 71 std::cout << "Here is debug of all Classes\n"; 72 BaseObject::objectList.debug(); 73 delete bone; 74 delete test; 75 78 //std::cout << "Here is debug of all Classes\n"; 79 //BaseObject::objectList.debug(); 80 // delete bone; 81 delete []test; 76 82 } 77 83
Note: See TracChangeset
for help on using the changeset viewer.