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/ObjectListIterator.h

    r9573 r9667  
    5858#include "core/class/Identifier.h"
    5959#include "ObjectList.h"
     60#include "IteratorBase.h"
    6061
    6162namespace orxonox
     
    6768    */
    6869    template <class T>
    69     class ObjectListIterator
     70    class ObjectListIterator : public IteratorBase<T, ObjectListIterator<T> >
    7071    {
    71         template <class I>
    72         friend class Iterator;
    73 
    7472        public:
    7573            /**
    7674                @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero.
    7775            */
    78             inline ObjectListIterator()
    79             {
    80                 this->element_ = 0;
    81                 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
    82             }
     76            inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >(NULL) {}
    8377
    8478            /**
     
    8680                @param element The element to start with
    8781            */
    88             inline ObjectListIterator(ObjectListElement<T>* element)
    89             {
    90                 this->element_ = element;
    91                 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
    92             }
     82            inline ObjectListIterator(ObjectListElement<T>* element) : IteratorBase<T, ObjectListIterator<T> >(element) {}
    9383
    9484            /**
     
    9686                @param other The other ObjectListIterator
    9787            */
    98             inline ObjectListIterator(const ObjectListIterator<T>& other)
    99             {
    100                 this->element_ = other.element_;
    101                 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
    102             }
    103 
    104             /**
    105                 @brief Unregisters the ObjectListIterator from the ObjectList.
    106             */
    107             inline ~ObjectListIterator()
    108             {
    109                 ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterObjectListIterator(this);
    110             }
    111 
    112             /**
    113                 @brief Assigns an ObjectListElement.
    114                 @param element The ObjectListElement
    115             */
    116             inline ObjectListIterator<T>& operator=(ObjectListElement<T>* element)
    117             {
    118                 this->element_ = element;
    119                 return (*this);
    120             }
    121 
    122             /**
    123                 @brief Assigns the element of another ObjectListIterator.
    124                 @param other The other ObjectListIterator
    125             */
    126             inline ObjectListIterator<T>& operator=(const ObjectListIterator<T>& other)
    127             {
    128                 this->element_ = other.element_;
    129                 return (*this);
    130             }
    131 
    132             /**
    133                 @brief Overloading of the ++it operator: ObjectListIterator points to the next object in the list.
    134                 @return The ObjectListIterator itself
    135             */
    136             inline const ObjectListIterator<T>& operator++()
    137             {
    138                 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
    139                 return *this;
    140             }
    141 
    142             /**
    143                 @brief Overloading of the it++ operator: ObjectListIterator points to the next object in the list.
    144                 @return The ObjectListIterator itself
    145             */
    146             inline ObjectListIterator<T> operator++(int)
    147             {
    148                 ObjectListIterator<T> copy = *this;
    149                 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
    150                 return copy;
    151             }
    152 
    153             /**
    154                 @brief Overloading of the --it operator: ObjectListIterator points to the previous object in the list.
    155                 @return The ObjectListIterator itself
    156             */
    157             inline const ObjectListIterator<T>& operator--()
    158             {
    159                 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
    160                 return *this;
    161             }
    162 
    163             /**
    164                 @brief Overloading of the it-- operator: ObjectListIterator points to the previous object in the list.
    165                 @return The ObjectListIterator itself
    166             */
    167             inline ObjectListIterator<T> operator--(int i)
    168             {
    169                 ObjectListIterator<T> copy = *this;
    170                 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
    171                 return copy;
    172             }
     88            inline ObjectListIterator(const IteratorBase<T, ObjectListIterator<T> >& other) : IteratorBase<T, ObjectListIterator<T> >(other) {}
    17389
    17490            /**
     
    17894            inline T* operator*() const
    17995            {
    180                 return this->element_->object_;
     96                return static_cast<ObjectListElement<T>*>(this->element_)->object_;
    18197            }
    18298
     
    187103            inline T* operator->() const
    188104            {
    189                 return this->element_->object_;
     105                return static_cast<ObjectListElement<T>*>(this->element_)->object_;
    190106            }
    191 
    192             /**
    193                 @brief Overloading of the typecast-operator to bool: returns true if the ObjectListIterator points to an existing object.
    194                 @return True if the ObjectListIterator points to an existing object.
    195             */
    196             inline operator bool() const
    197             {
    198                 return (this->element_ != 0);
    199             }
    200 
    201             /**
    202                 @brief Overloading of the == operator to compare with another ObjectListIterator.
    203                 @param compare The other ObjectListIterator
    204                 @return True if the ObjectListIterator point to the same element
    205             */
    206             inline bool operator==(const ObjectListIterator<T>& compare) const
    207             {
    208                 return (this->element_ == compare.element_);
    209             }
    210 
    211             /**
    212                 @brief Overloading of the != operator to compare with another ObjectListIterator.
    213                 @param compare The other ObjectListIterator
    214                 @return True if the ObjectListIterator point to different elements
    215             */
    216             inline bool operator!=(const ObjectListIterator<T>& compare) const
    217             {
    218                 return (this->element_ != compare.element_);
    219             }
    220 
    221             /**
    222                 @brief Increments the ObjectListIterator if it points at the given object.
    223                 @param object The object to compare with
    224             */
    225             inline void incrementIfEqual(Listable* object)
    226             {
    227                 if (this->element_ && this->element_->objectBase_ == object)
    228                     this->operator++();
    229             }
    230 
    231         private:
    232             ObjectListElement<T>* element_;        //!< The element the iterator points at
    233107    };
    234108}
Note: See TracChangeset for help on using the changeset viewer.