Changeset 9606
- Timestamp:
- Mar 30, 2013, 7:26:54 PM (12 years ago)
- Location:
- code/branches/core6
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/ClassTreeMask.cc
r9563 r9606 849 849 // If there is a first subclass, move the object-iterator to the first object of this class. Else go to the end 850 850 if (this->subclassIterator_ != this->subclasses_.end()) 851 this->objectIterator_ = this->subclassIterator_->first->getObjects()->begin();851 this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin(); 852 852 else 853 853 this->objectIterator_ = ObjectList<BaseObject>::end(); … … 881 881 // Check if there really is a next class. If yes, move the object-iterator to the first object 882 882 if (this->subclassIterator_ != this->subclasses_.end()) 883 this->objectIterator_ = this->subclassIterator_->first->getObjects()->begin();883 this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin(); 884 884 else 885 885 return (*this); -
code/branches/core6/src/libraries/core/class/Identifier.cc
r9602 r9606 52 52 : classID_(IdentifierManager::classIDCounter_s++) 53 53 { 54 this->objects_ = new ObjectListBase();55 56 54 this->bCreatedOneObject_ = false; 57 55 this->bSetName_ = false; … … 70 68 Identifier::~Identifier() 71 69 { 72 delete this->objects_;73 74 70 if (this->factory_) 75 71 delete this->factory_; -
code/branches/core6/src/libraries/core/class/Identifier.h
r9602 r9606 57 57 58 58 OrxonoxClass* other = object->getIdentifier()->fabricate(0); // fabricates a new instance of MyClass 59 60 61 // iterate through all objects of type MyClass:62 ObjectListBase* objects = object->getIdentifier()->getObjects(); // get a pointer to the object-list63 int count;64 for (Iterator<MyClass> it = objects.begin(); it != objects.end(); ++it) // iterate through the objects65 ++count;66 orxout() << count << endl; // prints "2" because we created 2 instances of MyClass so far67 59 68 60 … … 91 83 #include "util/Output.h" 92 84 #include "core/object/ObjectList.h" 93 #include "core/object/ObjectListBase.h" 85 #include "core/object/Listable.h" 86 #include "core/object/Context.h" 94 87 #include "IdentifierManager.h" 95 88 #include "Super.h" … … 126 119 /// Returns the unique ID of the class. 127 120 ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; } 128 129 /// Returns the list of all existing objects of this class.130 inline ObjectListBase* getObjects() const { return this->objects_; }131 121 132 122 /// Sets the Factory. … … 231 221 /// Returns the direct children of the class the Identifier belongs to. 232 222 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; } 233 234 ObjectListBase* objects_; //!< The list of all objects of this class235 223 236 224 private: … … 424 412 */ 425 413 template <class T> 426 void ClassIdentifier<T>::addObjectToList(T* object, Listable*) 427 { 428 orxout(verbose, context::object_list) << "Added object to " << this->getName() << "-list." << endl; 429 object->elements_.push_back(this->objects_->add(object)); 414 void ClassIdentifier<T>::addObjectToList(T* object, Listable* listable) 415 { 416 listable->getContext()->addObject(object); 430 417 } 431 418 -
code/branches/core6/src/libraries/core/object/Context.cc
r9591 r9606 33 33 34 34 #include "Context.h" 35 #include "core/class/Identifier.h" 35 36 36 37 namespace orxonox … … 49 50 return &rootContext; 50 51 } 52 53 ObjectListBase* Context::getObjectList(const Identifier* identifier) 54 { 55 unsigned int classID = identifier->getClassID(); 56 if (classID >= this->objectLists_.size()) 57 this->objectLists_.resize(classID + 1); 58 if (!this->objectLists_[classID]) 59 this->objectLists_[classID] = new ObjectListBase(); 60 return this->objectLists_[classID]; 61 } 51 62 } -
code/branches/core6/src/libraries/core/object/Context.h
r9591 r9606 37 37 #include "core/CorePrereqs.h" 38 38 39 #include <vector> 40 41 #include "ObjectListBase.h" 42 39 43 namespace orxonox 40 44 { … … 42 46 { 43 47 public: 48 static Context* getRootContext(); 49 44 50 Context(Context* context); 45 51 virtual ~Context(); … … 48 54 { return this->parentContext_; } 49 55 50 static Context* getRootContext(); 56 ObjectListBase* getObjectList(const Identifier* identifier); 57 58 template <class T> 59 inline ObjectListBase* getObjectList() 60 { return this->getObjectList(ClassIdentifier<T>::getIdentifier()); } 61 62 template <class T> 63 inline void addObject(T* object) 64 { 65 ObjectListBaseElement* element = this->getObjectList<T>()->add(object); 66 object->elements_.push_back(element); 67 if (this->getParentContext()) 68 this->getParentContext()->addObject(object); 69 } 51 70 52 71 private: 53 72 Context* parentContext_; 73 std::vector<ObjectListBase*> objectLists_; 54 74 }; 55 75 } -
code/branches/core6/src/libraries/core/object/Listable.cc
r9597 r9606 34 34 #include "Listable.h" 35 35 #include "ObjectListBase.h" 36 #include "Context.h" 36 37 37 38 namespace orxonox … … 42 43 Listable::Listable() 43 44 { 45 this->context_ = Context::getRootContext(); 44 46 this->elements_.reserve(6); 45 47 } -
code/branches/core6/src/libraries/core/object/Listable.h
r9597 r9606 49 49 class _CoreExport Listable : virtual public Identifiable 50 50 { 51 template <class T> 52 friend class ClassIdentifier; 51 friend class Context; 53 52 54 53 public: … … 58 57 void unregisterObject(); 59 58 59 inline void setContext(Context* context) 60 { this->context_ = context; } 61 inline Context* getContext() const 62 { return this->context_; } 63 60 64 private: 65 Context* context_; //!< The object will register itself in the object lists of this context 61 66 std::vector<ObjectListBaseElement*> elements_; //!< The corresponding ObjectListElements in all object lists the object is registered in 62 67 }; -
code/branches/core6/src/libraries/core/object/ObjectList.h
r9604 r9606 49 49 #include "ObjectListBase.h" 50 50 #include "ObjectListIterator.h" 51 #include "Context.h" 51 52 52 53 namespace orxonox … … 71 72 inline static size_t size() 72 73 { 73 return C lassIdentifier<T>::getIdentifier()->getObjects()->size();74 return Context::getRootContext()->getObjectList<T>()->size(); 74 75 } 75 76 … … 77 78 inline static ObjectListElement<T>* begin() 78 79 { 79 ObjectListBase* list = C lassIdentifier<T>::getIdentifier()->getObjects();80 ObjectListBase* list = Context::getRootContext()->getObjectList<T>(); 80 81 return static_cast<ObjectListElement<T>*>(list->begin()); 81 82 } … … 84 85 inline static ObjectListElement<T>* end() 85 86 { 86 ObjectListBase* list = C lassIdentifier<T>::getIdentifier()->getObjects();87 ObjectListBase* list = Context::getRootContext()->getObjectList<T>(); 87 88 return static_cast<ObjectListElement<T>*>(list->end()); 88 89 } … … 91 92 inline static ObjectListElement<T>* rbegin() 92 93 { 93 ObjectListBase* list = C lassIdentifier<T>::getIdentifier()->getObjects();94 ObjectListBase* list = Context::getRootContext()->getObjectList<T>(); 94 95 return static_cast<ObjectListElement<T>*>(list->rbegin()); 95 96 } … … 98 99 inline static ObjectListElement<T>* rend() 99 100 { 100 ObjectListBase* list = C lassIdentifier<T>::getIdentifier()->getObjects();101 ObjectListBase* list = Context::getRootContext()->getObjectList<T>(); 101 102 return static_cast<ObjectListElement<T>*>(list->rend()); 102 103 } -
code/branches/core6/src/libraries/core/object/ObjectListBase.cc
r9604 r9606 89 89 } 90 90 91 if (element->objectBase_) 92 orxout(verbose, context::object_list) << "Added object to " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 93 91 94 if (!this->last_) 92 95 { -
code/branches/core6/src/libraries/core/object/ObjectListBase.h
r9604 r9606 124 124 125 125 /// Returns a pointer to the first element in the list. Works only with Iterator. 126 inline ObjectListBaseElement* begin() { return this->first_; }126 inline ObjectListBaseElement* begin() const { return this->first_; } 127 127 /// Returns a pointer to the element after the last element in the list. Works only with Iterator. 128 inline ObjectListBaseElement* end() { return 0; }128 inline ObjectListBaseElement* end() const { return 0; } 129 129 /// Returns a pointer to the last element in the list. Works only with Iterator. 130 inline ObjectListBaseElement* rbegin() { return this->last_; }130 inline ObjectListBaseElement* rbegin() const { return this->last_; } 131 131 /// Returns a pointer to the element in front of the first element in the list. Works only with Iterator. 132 inline ObjectListBaseElement* rend() { return 0; }132 inline ObjectListBaseElement* rend() const { return 0; } 133 133 134 134 inline void registerRemovalListener(ObjectListElementRemovalListener* listener) { this->listeners_.push_back(listener); } -
code/branches/core6/test/core/object/ListableTest.cc
r9605 r9606 54 54 TEST(ListableTest, RemovesFromObjectList) 55 55 { 56 EXPECT_EQ(0u, ObjectList<ListableTest>::size()); 56 57 { 57 58 ListableTest test; … … 64 65 TEST(ListableTest, RemovesFromAllObjectLists) 65 66 { 67 EXPECT_EQ(0u, ObjectList<ListableTest>::size()); 68 EXPECT_EQ(0u, ObjectList<ListableSubclassTest>::size()); 66 69 { 67 70 ListableSubclassTest test;
Note: See TracChangeset
for help on using the changeset viewer.