Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 16, 2013, 9:20:59 PM (11 years ago)
Author:
landauf
Message:

register Listable in the framework

Location:
code/branches/core6/src/libraries/core/object
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core6/src/libraries/core/object/Context.cc

    r9650 r9651  
    4242    Context* Context::rootContext_s = 0;
    4343
    44     Context::Context(Context* context) : Listable(this), parentContext_(context)
     44    Context* getContextForInitializationOfOtherContexts()
    4545    {
    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
    5065        this->setContext(this);
    51 
    52         RegisterObject(Context);
    5366    }
    5467
  • code/branches/core6/src/libraries/core/object/Listable.cc

    r9627 r9651  
    3333
    3434#include "Listable.h"
     35#include "core/CoreIncludes.h"
    3536#include "ObjectListBase.h"
    3637#include "Context.h"
     
    3839namespace orxonox
    3940{
     41    RegisterClass(Listable);
     42
    4043    /**
    4144        @brief Constructor: Allocates space in the element list.
     
    4548        this->context_ = Context::getRootContext();
    4649        this->elements_.reserve(6);
     50
     51        RegisterObject(Listable);
    4752    }
    4853
    4954    /**
    50         @brief Constructor: Allocates space in the element list and assignes the context
     55        @brief Constructor: Allocates space in the element list and assigns the context
    5156    */
    5257    Listable::Listable(Context* context)
     
    5459        this->context_ = context;
    5560        this->elements_.reserve(6);
     61
     62        RegisterObject(Listable);
    5663    }
    5764
     
    8087    void Listable::setContext(Context* context)
    8188    {
     89        assert(context);
    8290        std::vector<ObjectListBaseElement*> copy = this->elements_;
    8391        this->elements_.clear();
Note: See TracChangeset for help on using the changeset viewer.