Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 9, 2008, 4:35:38 AM (16 years ago)
Author:
landauf
Message:

big change in ObjectList: separated the class into a non-template base and a template wrapper for the base. this also changes the Iterator, there is now a non-template IteratorBase. this brings much more flexibility, like iterating through all objects of a given identifier without knowing the type. however this needs a dynamic_cast, which isn't quite optimal, but I think there are much worser things than that out there. ;)

there isn't much you have to know about this, except there is no more ObjectList<myClass>::start() function but a ObjectList<myClass>::begin() to be more STLish. another thing: ObjectList<myClass>::end() points now to the element _after_ the last element, so it's possible to iterate in a for-loop until (it != ObjectList<myClass>::end()). the reason is the same as above. however, (it) as a boolean still works perfectly fine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/MetaObjectList.cc

    r1505 r1574  
    3333
    3434#include "MetaObjectList.h"
     35#include "Debug.h"
    3536
    3637namespace orxonox
    3738{
     39    // ###############################
     40    // ###  MetaObjectListElement  ###
     41    // ###############################
     42    /**
     43        @brief Destructor: Removes the ObjectListBaseElement from the ObjectListBase by linking next_ and prev_ of the ObjectListBaseElement.
     44    */
     45    MetaObjectListElement::~MetaObjectListElement()
     46    {
     47        COUT(5) << "*** MetaObjectList: Removing Object from " << this->list_->getIdentifier()->getName() << "-list." << std::endl;
     48        this->list_->notifyIterators(this->element_);
     49
     50        if (this->element_->next_)
     51            this->element_->next_->prev_ = this->element_->prev_;
     52        else
     53            this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list
     54
     55        if (this->element_->prev_)
     56            this->element_->prev_->next_ = this->element_->next_;
     57        else
     58            this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list
     59
     60        delete this->element_;
     61    }
     62
     63
     64    // ###############################
     65    // ###     MetaObjectList      ###
     66    // ###############################
    3867    /**
    3968        @brief Constructor: Sets first_ to zero.
     
    4978    MetaObjectList::~MetaObjectList()
    5079    {
    51         BaseMetaObjectListElement* temp;
     80        MetaObjectListElement* temp;
    5281        while (this->first_)
    5382        {
     
    5786        }
    5887    }
     88
     89    /**
     90        @brief Adds an ObjectList and an element of that list to the MetaObjectList.
     91        @param list The ObjectList wherein the element is
     92        @param element The element wherein the object is
     93    */
     94    void MetaObjectList::add(ObjectListBase* list, ObjectListBaseElement* element)
     95    {
     96        MetaObjectListElement* temp = this->first_;
     97        this->first_ = new MetaObjectListElement(list, element);
     98        this->first_->next_ = temp;
     99    }
    59100}
Note: See TracChangeset for help on using the changeset viewer.