Changeset 9651 for code/branches/core6/src/libraries
- Timestamp:
- Aug 16, 2013, 9:20:59 PM (11 years ago)
- Location:
- code/branches/core6/src/libraries/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/class/Identifier.h
r9646 r9651 409 409 void ClassIdentifier<T>::addObjectToList(T* object, Listable* listable) 410 410 { 411 listable->getContext()->addObject(object); 411 if (listable->getContext()) 412 listable->getContext()->addObject(object); 412 413 } 413 414 -
code/branches/core6/src/libraries/core/class/IdentifierManager.cc
r9646 r9651 127 127 initializedIdentifiers.insert(it->second); 128 128 } 129 130 size_t numberOfObjects = temporaryContext.getObjectList<Listable>()->size(); 131 if (numberOfObjects > 0) 132 orxout(internal_warning) << "There are still " << numberOfObjects << " listables left after creating the class hierarchy" << endl; 129 133 } 130 134 -
code/branches/core6/src/libraries/core/object/Context.cc
r9650 r9651 42 42 Context* Context::rootContext_s = 0; 43 43 44 Context ::Context(Context* context) : Listable(this), parentContext_(context)44 Context* getContextForInitializationOfOtherContexts() 45 45 { 46 // we have to call Listable(this) to avoid circular initialization when creating a Context because Listable calls Context::getRootContext() by 47 // default AND we have to set the context again in the constructor because of other classes inheriting from Context (Listable is a virtual base 48 // and each subclass must call its constructor individually, so either all subclasses add Listable(this) to their initialization list or we call 49 // setContext(this) here). 46 static size_t count = 0; 47 // the first time this is called, ++count returns 1 and the context is created 48 // the second time this is called, ++count returns 2 and NULL is returned because we're in the constructor of the context itself 49 // for each future call the context (now completely created) is returned 50 if (++count == 2) 51 return NULL; 52 else 53 { 54 static Context context(NULL); 55 return &context; 56 } 57 } 58 59 // Initialize Listable(*) with a special context, only used to initialize other contexts. Later in the constructor we change the context 60 Context::Context(Context* context) : Listable(getContextForInitializationOfOtherContexts()), parentContext_(context) 61 { 62 RegisterObject(Context); 63 64 // the context is its own context 50 65 this->setContext(this); 51 52 RegisterObject(Context);53 66 } 54 67 -
code/branches/core6/src/libraries/core/object/Listable.cc
r9627 r9651 33 33 34 34 #include "Listable.h" 35 #include "core/CoreIncludes.h" 35 36 #include "ObjectListBase.h" 36 37 #include "Context.h" … … 38 39 namespace orxonox 39 40 { 41 RegisterClass(Listable); 42 40 43 /** 41 44 @brief Constructor: Allocates space in the element list. … … 45 48 this->context_ = Context::getRootContext(); 46 49 this->elements_.reserve(6); 50 51 RegisterObject(Listable); 47 52 } 48 53 49 54 /** 50 @brief Constructor: Allocates space in the element list and assign es the context55 @brief Constructor: Allocates space in the element list and assigns the context 51 56 */ 52 57 Listable::Listable(Context* context) … … 54 59 this->context_ = context; 55 60 this->elements_.reserve(6); 61 62 RegisterObject(Listable); 56 63 } 57 64 … … 80 87 void Listable::setContext(Context* context) 81 88 { 89 assert(context); 82 90 std::vector<ObjectListBaseElement*> copy = this->elements_; 83 91 this->elements_.clear();
Note: See TracChangeset
for help on using the changeset viewer.