Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9661 for code/branches/core6


Ignore:
Timestamp:
Aug 24, 2013, 6:38:55 PM (11 years ago)
Author:
landauf
Message:

Listable is now responsible for creating and deleting ObjectListElements

Location:
code/branches/core6
Files:
5 edited

Legend:

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

    r9649 r9661  
    6464            inline void addObject(T* object)
    6565            {
    66                 ObjectListBaseElement* element = this->getObjectList<T>()->add(object);
     66                ObjectListBaseElement* element = Listable::createObjectListElement(object);
     67                this->getObjectList<T>()->addElement(element);
    6768                object->elements_.push_back(element);
    6869                if (this->getParentContext())
  • code/branches/core6/src/libraries/core/object/Listable.cc

    r9651 r9661  
    7777    {
    7878        for (size_t i = 0; i < this->elements_.size(); ++i)
    79             delete this->elements_[i];
     79            Listable::deleteObjectListElement(this->elements_[i]);
    8080        this->elements_.clear();
    8181    }
     
    9494        {
    9595            copy[i]->changeContext(this->context_, context);
    96             delete copy[i];
     96            Listable::deleteObjectListElement(copy[i]);
    9797        }
    9898
     
    100100    }
    101101
     102    /* static */ void Listable::deleteObjectListElement(ObjectListBaseElement* element)
     103    {
     104        delete element;
     105    }
    102106}
  • code/branches/core6/src/libraries/core/object/Listable.h

    r9610 r9661  
    6363
    6464        private:
     65            template <class T>
     66            static ObjectListElement<T>* createObjectListElement(T* object)
     67            {
     68                return new ObjectListElement<T>(object);
     69            }
     70
     71            static void deleteObjectListElement(ObjectListBaseElement* element);
     72
    6573            Context* context_;                             //!< The object will register itself in the object lists of this context
    6674            std::vector<ObjectListBaseElement*> elements_; //!< The corresponding ObjectListElements in all object lists the object is registered in
  • code/branches/core6/src/libraries/core/object/ObjectListBase.h

    r9627 r9661  
    128128            ~ObjectListBase();
    129129
    130             template <class T>
    131             inline ObjectListBaseElement* add(T* object)
    132             {
    133                 ObjectListBaseElement* element = new ObjectListElement<T>(object);
    134                 this->addElement(element);
    135                 return element;
    136             }
    137 
    138130            void addElement(ObjectListBaseElement* element);
    139131            void removeElement(ObjectListBaseElement* element);
  • code/branches/core6/test/core/object/ObjectListBaseTest.cc

    r9608 r9661  
    4343    {
    4444        ObjectListBase list;
    45         list.add(static_cast<Listable*>(NULL));
     45        list.addElement(new ObjectListElement<Listable>(NULL));
    4646        EXPECT_EQ(1u, list.size());
    4747    }
Note: See TracChangeset for help on using the changeset viewer.