Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9651 for code/branches


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

register Listable in the framework

Location:
code/branches/core6
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core6/src/libraries/core/class/Identifier.h

    r9646 r9651  
    409409    void ClassIdentifier<T>::addObjectToList(T* object, Listable* listable)
    410410    {
    411         listable->getContext()->addObject(object);
     411        if (listable->getContext())
     412            listable->getContext()->addObject(object);
    412413    }
    413414
  • code/branches/core6/src/libraries/core/class/IdentifierManager.cc

    r9646 r9651  
    127127                initializedIdentifiers.insert(it->second);
    128128            }
     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;
    129133        }
    130134
  • 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();
  • code/branches/core6/test/core/class/IdentifierClassHierarchyTest.cc

    r9646 r9651  
    130130                virtual void SetUp()
    131131                {
     132                    registerClass("Context", new ClassFactoryWithContext<Context>());
     133                    registerClass("Listable", new ClassFactoryWithContext<Listable>());
    132134                    registerClass("OrxonoxInterface", new ClassFactoryNoArgs<OrxonoxInterface>());
    133135                    registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>());
     
    230232        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxInterface)));
    231233
    232         EXPECT_EQ(2u, identifier->getParents().size());
    233         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     234        EXPECT_EQ(3u, identifier->getParents().size());
     235        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     236        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    234237        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface)));
    235238    }
     
    252255        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxInterface)));
    253256
    254         EXPECT_EQ(2u, identifier->getParents().size());
    255         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     257        EXPECT_EQ(3u, identifier->getParents().size());
     258        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     259        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    256260        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface)));
    257261    }
     
    274278        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseInterface1)));
    275279
    276         EXPECT_EQ(3u, identifier->getParents().size());
    277         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     280        EXPECT_EQ(4u, identifier->getParents().size());
     281        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     282        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    278283        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface)));
    279284        EXPECT_TRUE(contains(identifier->getParents(), Class(BaseInterface1)));
     
    295300        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseInterface2)));
    296301
    297         EXPECT_EQ(3u, identifier->getParents().size());
    298         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     302        EXPECT_EQ(4u, identifier->getParents().size());
     303        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     304        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    299305        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface)));
    300306        EXPECT_TRUE(contains(identifier->getParents(), Class(BaseInterface2)));
     
    322328        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass)));
    323329
    324         EXPECT_EQ(2u, identifier->getParents().size());
    325         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     330        EXPECT_EQ(3u, identifier->getParents().size());
     331        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     332        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    326333        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
    327334    }
     
    338345        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass)));
    339346
    340         EXPECT_EQ(3u, identifier->getParents().size());
    341         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     347        EXPECT_EQ(4u, identifier->getParents().size());
     348        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     349        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    342350        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
    343351        EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass)));
     
    356364        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Interface1)));
    357365
    358         EXPECT_EQ(6u, identifier->getParents().size());
    359         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     366        EXPECT_EQ(7u, identifier->getParents().size());
     367        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     368        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    360369        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
    361370        EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass)));
     
    378387        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Interface2)));
    379388
    380         EXPECT_EQ(8u, identifier->getParents().size());
    381         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     389        EXPECT_EQ(9u, identifier->getParents().size());
     390        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     391        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    382392        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
    383393        EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass)));
     
    402412        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Interface2)));
    403413
    404         EXPECT_EQ(8u, identifier->getParents().size());
    405         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     414        EXPECT_EQ(9u, identifier->getParents().size());
     415        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     416        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    406417        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
    407418        EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass)));
     
    426437        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseInterface2)));
    427438
    428         EXPECT_EQ(6u, identifier->getParents().size());
    429         EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     439        EXPECT_EQ(7u, identifier->getParents().size());
     440        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     441        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    430442        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
    431443        EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass)));
  • code/branches/core6/test/core/class/IdentifierSimpleClassHierarchyTest.cc

    r9646 r9651  
    4646                virtual void SetUp()
    4747                {
     48                    registerClass("Context", new ClassFactoryWithContext<Context>());
     49                    registerClass("Listable", new ClassFactoryWithContext<Listable>());
    4850                    registerClass("OrxonoxInterface", new ClassFactoryNoArgs<OrxonoxInterface>());
    4951                    registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>());
     
    99101        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxInterface)));
    100102
    101         EXPECT_EQ(2u, identifier->getParents().size());
     103        EXPECT_EQ(3u, identifier->getParents().size());
    102104        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     105        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    103106        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface)));
    104107    }
     
    117120        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass)));
    118121
    119         EXPECT_EQ(2u, identifier->getParents().size());
     122        EXPECT_EQ(3u, identifier->getParents().size());
    120123        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     124        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    121125        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
    122126    }
     
    134138        EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass)));
    135139
    136         EXPECT_EQ(5u, identifier->getParents().size());
     140        EXPECT_EQ(6u, identifier->getParents().size());
    137141        EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable)));
     142        EXPECT_TRUE(contains(identifier->getParents(), Class(Listable)));
    138143        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface)));
    139144        EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
Note: See TracChangeset for help on using the changeset viewer.