Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 25, 2013, 9:08:42 PM (11 years ago)
Author:
landauf
Message:

merged core6 back to trunk

Location:
code/trunk
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/object/Iterator.h

    r9573 r9667  
    5656#include "core/CorePrereqs.h"
    5757
    58 #include "core/class/Identifier.h"
    5958#include "ObjectListBase.h"
     59#include "IteratorBase.h"
    6060
    6161namespace orxonox
     
    7070    */
    7171    template <class T>
    72     class Iterator
     72    class Iterator : public IteratorBase<T, Iterator<T> >
    7373    {
    7474        public:
     
    7676                @brief Constructor: Sets the element, whereon the iterator points, to zero.
    7777            */
    78             inline Iterator()
    79             {
    80                 this->element_ = 0;
    81                 this->list_ = 0;
    82             }
     78            inline Iterator() : IteratorBase<T, Iterator<T> >(NULL) {}
    8379
    8480            /**
    85                 @brief Constructor: Sets this element to the exported element.
    86                 @param exp The exported element
     81                @brief Constructor: Sets this element to a given element
     82                @param element The element
    8783            */
    88             inline Iterator(const ObjectListBase::Export& exp)
    89             {
    90                 this->element_ = exp.element_;
    91                 this->list_ = exp.list_;
    92                 this->list_->registerIterator(this);
    93             }
     84            inline Iterator(ObjectListBaseElement* element) : IteratorBase<T, Iterator<T> >(element) {}
    9485
    9586            /**
     
    9788                @param other The other Iterator
    9889            */
    99             inline Iterator(const Iterator<T>& other)
    100             {
    101                 this->element_ = other.element_;
    102                 this->list_ = other.list_;
    103                 this->list_->registerIterator(this);
    104             }
    105 
    106             /**
    107                 @brief Constructor: Sets this element to a given element
    108                 @param element The element
    109             */
    110             template <class O>
    111             inline Iterator(ObjectListElement<O>* element)
    112             {
    113                 this->element_ = element;
    114                 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    115                 this->list_->registerIterator(this);
    116             }
    117 
    118             /**
    119                 @brief Constructor: Sets this element to the element an ObjectListIterator.
    120                 @param other The ObjectListIterator
    121             */
    122             template <class O>
    123             inline Iterator(const ObjectListIterator<O>& other)
    124             {
    125                 this->element_ = other.element_;
    126                 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    127                 this->list_->registerIterator(this);
    128             }
    129 
    130             /**
    131                 @brief Unregisters the Iterator from the ObjectList.
    132             */
    133             inline ~Iterator()
    134             {
    135                 this->list_->unregisterIterator(this);
    136             }
    137 
    138             /**
    139                 @brief Assigns an exported element.
    140                 @param exp The exported element
    141             */
    142             inline Iterator<T>& operator=(const ObjectListBase::Export& exp)
    143             {
    144                 if (this->list_)
    145                     this->list_->unregisterIterator(this);
    146 
    147                 this->element_ = exp.element_;
    148                 this->list_ = exp.list_;
    149                 this->list_->registerIterator(this);
    150 
    151                 return (*this);
    152             }
    153 
    154             /**
    155                 @brief Assigns the element of another Iterator.
    156                 @param other The other Iterator
    157             */
    158             inline Iterator<T>& operator=(const Iterator<T>& other)
    159             {
    160                 if (this->list_)
    161                     this->list_->unregisterIterator(this);
    162 
    163                 this->element_ = other.element_;
    164                 this->list_ = other.list_;
    165                 this->list_->registerIterator(this);
    166 
    167                 return (*this);
    168             }
     90            inline Iterator(const Iterator<T>& other) : IteratorBase<T, Iterator<T> >(other) {}
    16991
    17092            /**
     
    17294                @param element The element
    17395            */
    174             template <class O>
    175             inline Iterator<T>& operator=(ObjectListElement<O>* element)
     96            inline Iterator<T>& operator=(ObjectListBaseElement* element)
    17697            {
    177                 if (this->list_)
    178                     this->list_->unregisterIterator(this);
    179 
    180                 this->element_ = element;
    181                 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    182                 this->list_->registerIterator(this);
    183 
     98                this->setElement(element);
    18499                return (*this);
    185             }
    186 
    187             /**
    188                 @brief Assigns the element of an ObjectListIterator.
    189                 @param other The ObjectListIterator
    190             */
    191             template <class O>
    192             inline Iterator<T>& operator=(const ObjectListIterator<O>& other)
    193             {
    194                 if (this->list_)
    195                     this->list_->unregisterIterator(this);
    196 
    197                 this->element_ = other.element_;
    198                 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    199                 this->list_->registerIterator(this);
    200 
    201                 return (*this);
    202             }
    203 
    204             /**
    205                 @brief Overloading of the ++it operator: Iterator points to the next object in the list.
    206                 @return The Iterator itself
    207             */
    208             inline const Iterator<T>& operator++()
    209             {
    210                 this->element_ = this->element_->next_;
    211                 return *this;
    212             }
    213 
    214             /**
    215                 @brief Overloading of the it++ operator: Iterator points to the next object in the list.
    216                 @return The Iterator itself
    217             */
    218             inline Iterator<T> operator++(int)
    219             {
    220                 Iterator<T> copy = *this;
    221                 this->element_ = this->element_->next_;
    222                 return copy;
    223             }
    224 
    225             /**
    226                 @brief Overloading of the --it operator: Iterator points to the previous object in the list.
    227                 @return The Iterator itself
    228             */
    229             inline const Iterator<T>& operator--()
    230             {
    231                 this->element_ = this->element_->prev_;
    232                 return *this;
    233             }
    234 
    235             /**
    236                 @brief Overloading of the it-- operator: Iterator points to the previous object in the list.
    237                 @return The Iterator itself
    238             */
    239             inline Iterator<T> operator--(int i)
    240             {
    241                 Iterator<T> copy = *this;
    242                 this->element_ = this->element_->prev_;
    243                 return copy;
    244100            }
    245101
     
    261117                return orxonox_cast<T*>(this->element_->objectBase_);
    262118            }
    263 
    264             /**
    265                 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.
    266                 @return True if the Iterator points to an existing object.
    267             */
    268             inline operator bool() const
    269             {
    270                 return (this->element_ != 0);
    271             }
    272 
    273             /**
    274                 @brief Overloading of the == operator to compare with another Iterator.
    275                 @param compare The other Iterator
    276                 @return True if the iterators point to the same element
    277             */
    278             inline bool operator==(const Iterator<T>& compare) const
    279             {
    280                 return (this->element_ == compare.element_);
    281             }
    282 
    283             /**
    284                 @brief Overloading of the != operator to compare with another Iterator.
    285                 @param compare The other Iterator
    286                 @return True if the iterators point to different elements
    287             */
    288             inline bool operator!=(const Iterator<T>& compare) const
    289             {
    290                 return (this->element_ != compare.element_);
    291             }
    292 
    293             /**
    294                 @brief Increments the Iterator if it points at the given object.
    295                 @param object The object to compare with
    296             */
    297             inline void incrementIfEqual(Listable* object)
    298             {
    299                 if (this->element_ && this->element_->objectBase_ == object)
    300                     this->operator++();
    301             }
    302 
    303         protected:
    304             ObjectListBaseElement* element_;       //!< The element the Iterator points at
    305             ObjectListBase* list_;                 //!< The list wherein the element is
    306119    };
    307120}
Note: See TracChangeset for help on using the changeset viewer.