Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 9, 2013, 12:27:05 AM (11 years ago)
Author:
landauf
Message:

fixed bug: Listable::setContext didn't work properly with sub-contexts (contexts whose root-context is != NULL)

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

Legend:

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

    r9610 r9627  
    8080    void Listable::setContext(Context* context)
    8181    {
     82        std::vector<ObjectListBaseElement*> copy = this->elements_;
     83        this->elements_.clear();
     84
     85        for (size_t i = 0; i < copy.size(); ++i)
     86        {
     87            copy[i]->changeContext(this->context_, context);
     88            delete copy[i];
     89        }
     90
    8291        this->context_ = context;
    83         for (size_t i = 0; i < this->elements_.size(); ++i)
    84             this->elements_[i]->changeContext(context);
    8592    }
    8693
  • code/branches/core6/src/libraries/core/object/ObjectListBase.h

    r9608 r9627  
    6060            virtual ~ObjectListBaseElement() { this->removeFromList(); }
    6161
    62             virtual void changeContext(Context* context) = 0;
     62            virtual void changeContext(Context* oldContext, Context* newContext) = 0;
    6363
    6464            ObjectListBaseElement* next_;       //!< The next element in the list
     
    8282            ObjectListElement(T* object) : ObjectListBaseElement(static_cast<Listable*>(object)), object_(object) {}
    8383
    84             virtual void changeContext(Context* context)
     84            virtual void changeContext(Context* oldContext, Context* newContext)
    8585            {
     86                // add object to new context, but only if this element belongs exactly to the old context (and not to a sub-context to avoid re-adding objects
     87                // multiple times if they are in multiple contexts)
     88                if (oldContext->getObjectList<T>() == this->list_)
     89                    newContext->addObject(this->object_);
     90
     91                // remove from old list
    8692                this->removeFromList();
    87                 context->getObjectList<T>()->addElement(this);
    8893            }
    8994
Note: See TracChangeset for help on using the changeset viewer.