Changeset 9606 for code/branches/core6/src/libraries/core/object
- Timestamp:
- Mar 30, 2013, 7:26:54 PM (12 years ago)
- Location:
- code/branches/core6/src/libraries/core/object
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
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); }
Note: See TracChangeset
for help on using the changeset viewer.