Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9606 for code


Ignore:
Timestamp:
Mar 30, 2013, 7:26:54 PM (12 years ago)
Author:
landauf
Message:

object lists are now stored in a Context object instead of Identifiers

Location:
code/branches/core6
Files:
11 edited

Legend:

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

    r9563 r9606  
    849849        // If there is a first subclass, move the object-iterator to the first object of this class. Else go to the end
    850850        if (this->subclassIterator_ != this->subclasses_.end())
    851             this->objectIterator_ = this->subclassIterator_->first->getObjects()->begin();
     851            this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin();
    852852        else
    853853            this->objectIterator_ = ObjectList<BaseObject>::end();
     
    881881                    // Check if there really is a next class. If yes, move the object-iterator to the first object
    882882                    if (this->subclassIterator_ != this->subclasses_.end())
    883                         this->objectIterator_ = this->subclassIterator_->first->getObjects()->begin();
     883                        this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin();
    884884                    else
    885885                        return (*this);
  • code/branches/core6/src/libraries/core/class/Identifier.cc

    r9602 r9606  
    5252        : classID_(IdentifierManager::classIDCounter_s++)
    5353    {
    54         this->objects_ = new ObjectListBase();
    55 
    5654        this->bCreatedOneObject_ = false;
    5755        this->bSetName_ = false;
     
    7068    Identifier::~Identifier()
    7169    {
    72         delete this->objects_;
    73 
    7470        if (this->factory_)
    7571            delete this->factory_;
  • code/branches/core6/src/libraries/core/class/Identifier.h

    r9602 r9606  
    5757
    5858    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-list
    63     int count;
    64     for (Iterator<MyClass> it = objects.begin(); it != objects.end(); ++it)     // iterate through the objects
    65         ++count;
    66     orxout() << count << endl;                                                  // prints "2" because we created 2 instances of MyClass so far
    6759
    6860
     
    9183#include "util/Output.h"
    9284#include "core/object/ObjectList.h"
    93 #include "core/object/ObjectListBase.h"
     85#include "core/object/Listable.h"
     86#include "core/object/Context.h"
    9487#include "IdentifierManager.h"
    9588#include "Super.h"
     
    126119            /// Returns the unique ID of the class.
    127120            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_; }
    131121
    132122            /// Sets the Factory.
     
    231221            /// Returns the direct children of the class the Identifier belongs to.
    232222            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; }
    233 
    234             ObjectListBase* objects_;                                      //!< The list of all objects of this class
    235223
    236224        private:
     
    424412     */
    425413    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);
    430417    }
    431418
  • code/branches/core6/src/libraries/core/object/Context.cc

    r9591 r9606  
    3333
    3434#include "Context.h"
     35#include "core/class/Identifier.h"
    3536
    3637namespace orxonox
     
    4950        return &rootContext;
    5051    }
     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    }
    5162}
  • code/branches/core6/src/libraries/core/object/Context.h

    r9591 r9606  
    3737#include "core/CorePrereqs.h"
    3838
     39#include <vector>
     40
     41#include "ObjectListBase.h"
     42
    3943namespace orxonox
    4044{
     
    4246    {
    4347        public:
     48            static Context* getRootContext();
     49
    4450            Context(Context* context);
    4551            virtual ~Context();
     
    4854                { return this->parentContext_; }
    4955
    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            }
    5170
    5271        private:
    5372            Context* parentContext_;
     73            std::vector<ObjectListBase*> objectLists_;
    5474    };
    5575}
  • code/branches/core6/src/libraries/core/object/Listable.cc

    r9597 r9606  
    3434#include "Listable.h"
    3535#include "ObjectListBase.h"
     36#include "Context.h"
    3637
    3738namespace orxonox
     
    4243    Listable::Listable()
    4344    {
     45        this->context_ = Context::getRootContext();
    4446        this->elements_.reserve(6);
    4547    }
  • code/branches/core6/src/libraries/core/object/Listable.h

    r9597 r9606  
    4949    class _CoreExport Listable : virtual public Identifiable
    5050    {
    51         template <class T>
    52         friend class ClassIdentifier;
     51        friend class Context;
    5352
    5453        public:
     
    5857            void unregisterObject();
    5958
     59            inline void setContext(Context* context)
     60                { this->context_ = context; }
     61            inline Context* getContext() const
     62                { return this->context_; }
     63
    6064        private:
     65            Context* context_;                             //!< The object will register itself in the object lists of this context
    6166            std::vector<ObjectListBaseElement*> elements_; //!< The corresponding ObjectListElements in all object lists the object is registered in
    6267    };
  • code/branches/core6/src/libraries/core/object/ObjectList.h

    r9604 r9606  
    4949#include "ObjectListBase.h"
    5050#include "ObjectListIterator.h"
     51#include "Context.h"
    5152
    5253namespace orxonox
     
    7172            inline static size_t size()
    7273            {
    73                 return ClassIdentifier<T>::getIdentifier()->getObjects()->size();
     74                return Context::getRootContext()->getObjectList<T>()->size();
    7475            }
    7576
     
    7778            inline static ObjectListElement<T>* begin()
    7879            {
    79                 ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
     80                ObjectListBase* list = Context::getRootContext()->getObjectList<T>();
    8081                return static_cast<ObjectListElement<T>*>(list->begin());
    8182            }
     
    8485            inline static ObjectListElement<T>* end()
    8586            {
    86                 ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
     87                ObjectListBase* list = Context::getRootContext()->getObjectList<T>();
    8788                return static_cast<ObjectListElement<T>*>(list->end());
    8889            }
     
    9192            inline static ObjectListElement<T>* rbegin()
    9293            {
    93                 ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
     94                ObjectListBase* list = Context::getRootContext()->getObjectList<T>();
    9495                return static_cast<ObjectListElement<T>*>(list->rbegin());
    9596            }
     
    9899            inline static ObjectListElement<T>* rend()
    99100            {
    100                 ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
     101                ObjectListBase* list = Context::getRootContext()->getObjectList<T>();
    101102                return static_cast<ObjectListElement<T>*>(list->rend());
    102103            }
  • code/branches/core6/src/libraries/core/object/ObjectListBase.cc

    r9604 r9606  
    8989        }
    9090
     91        if (element->objectBase_)
     92            orxout(verbose, context::object_list) << "Added object to " << element->objectBase_->getIdentifier()->getName() << "-list." << endl;
     93
    9194        if (!this->last_)
    9295        {
  • code/branches/core6/src/libraries/core/object/ObjectListBase.h

    r9604 r9606  
    124124
    125125            /// 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_; }
    127127            /// 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; }
    129129            /// 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_; }
    131131            /// 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; }
    133133
    134134            inline void registerRemovalListener(ObjectListElementRemovalListener* listener) { this->listeners_.push_back(listener); }
  • code/branches/core6/test/core/object/ListableTest.cc

    r9605 r9606  
    5454    TEST(ListableTest, RemovesFromObjectList)
    5555    {
     56        EXPECT_EQ(0u, ObjectList<ListableTest>::size());
    5657        {
    5758            ListableTest test;
     
    6465    TEST(ListableTest, RemovesFromAllObjectLists)
    6566    {
     67        EXPECT_EQ(0u, ObjectList<ListableTest>::size());
     68        EXPECT_EQ(0u, ObjectList<ListableSubclassTest>::size());
    6669        {
    6770            ListableSubclassTest test;
Note: See TracChangeset for help on using the changeset viewer.