Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 30, 2013, 10:40:48 PM (11 years ago)
Author:
landauf
Message:

implemented method to change the context of a Listable. the object will then be added to the object lists of the new context

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

Legend:

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

    r9606 r9608  
    4747    /*static*/ Context* Context::getRootContext()
    4848    {
    49         static Context rootContext(NULL);
     49        static Context rootContext;
    5050        return &rootContext;
    5151    }
  • code/branches/core6/src/libraries/core/object/Context.h

    r9606 r9608  
    3939#include <vector>
    4040
    41 #include "ObjectListBase.h"
    42 
    4341namespace orxonox
    4442{
     
    4846            static Context* getRootContext();
    4947
    50             Context(Context* context);
     48            Context(Context* context = NULL);
    5149            virtual ~Context();
    5250
  • code/branches/core6/src/libraries/core/object/Listable.cc

    r9606 r9608  
    6464        this->elements_.clear();
    6565    }
     66
     67    /**
     68     * @brief Changes the context.
     69     * The object is removed from the current context and added to the new one. This also applies to all object lists the object is registered in.
     70     */
     71    void Listable::setContext(Context* context)
     72    {
     73        this->context_ = context;
     74        for (size_t i = 0; i < this->elements_.size(); ++i)
     75            this->elements_[i]->changeContext(context);
     76    }
     77
    6678}
  • code/branches/core6/src/libraries/core/object/Listable.h

    r9606 r9608  
    5757            void unregisterObject();
    5858
    59             inline void setContext(Context* context)
    60                 { this->context_ = context; }
     59            void setContext(Context* context);
    6160            inline Context* getContext() const
    6261                { return this->context_; }
  • code/branches/core6/src/libraries/core/object/ObjectListBase.cc

    r9606 r9608  
    4141namespace orxonox
    4242{
    43     ObjectListBaseElement::~ObjectListBaseElement()
     43    // ###############################
     44    // ###  ObjectListBaseElement  ###
     45    // ###############################
     46    void ObjectListBaseElement::removeFromList()
    4447    {
    4548        if (this->list_)
     
    4750    }
    4851
     52    // ###############################
     53    // ###     ObjectListBase      ###
     54    // ###############################
    4955    /**
    5056        @brief Constructor: Sets default values.
  • code/branches/core6/src/libraries/core/object/ObjectListBase.h

    r9606 r9608  
    4242#include "core/CorePrereqs.h"
    4343#include <vector>
     44#include "Context.h"
    4445
    4546namespace orxonox
     
    5758            */
    5859            ObjectListBaseElement(Listable* object) : next_(0), prev_(0), objectBase_(object), list_(0) {}
    59             ~ObjectListBaseElement();
     60            virtual ~ObjectListBaseElement() { this->removeFromList(); }
     61
     62            virtual void changeContext(Context* context) = 0;
    6063
    6164            ObjectListBaseElement* next_;       //!< The next element in the list
     
    6366            Listable* objectBase_;              //!< The object
    6467            ObjectListBase* list_;              //!< The list
     68
     69        protected:
     70            void removeFromList();
    6571    };
    6672
     
    7581        public:
    7682            ObjectListElement(T* object) : ObjectListBaseElement(static_cast<Listable*>(object)), object_(object) {}
     83
     84            virtual void changeContext(Context* context)
     85            {
     86                this->removeFromList();
     87                context->getObjectList<T>()->addElement(this);
     88            }
     89
    7790            T* object_;              //!< The object
    7891    };
Note: See TracChangeset for help on using the changeset viewer.