Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 31, 2015, 11:50:17 PM (9 years ago)
Author:
landauf
Message:

fixed range based for-loop: ObjectList now returns an iterator
added tests and refactored construction of Iterator/IteratorBase/ObjectListIterator

Location:
code/branches/cpp11_v2/src/libraries/core/object
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/object/Iterator.h

    r10624 r10736  
    7979
    8080            /**
    81                 @brief Constructor: Sets this element to a given element
    82                 @param element The element
    83             */
    84             inline Iterator(ObjectListBaseElement* element) : IteratorBase<T, Iterator<T> >(element) {}
    85 
    86             /**
    8781                @brief Constructor: Sets this element to the element of another Iterator.
    8882                @param other The other Iterator
    8983            */
    90             inline Iterator(const IteratorBase<T, Iterator<T> >& other) : IteratorBase<T, Iterator<T> >(other) {}
     84            template <class OT, class OI>
     85            inline Iterator(const IteratorBase<OT, OI>& other) : IteratorBase<T, Iterator<T> >(other) {}
    9186
    9287            /**
  • code/branches/cpp11_v2/src/libraries/core/object/IteratorBase.h

    r10624 r10736  
    5454        BOOST_STATIC_ASSERT((boost::is_base_of<Listable, T>::value));
    5555
    56         protected:
     56        public:
    5757            /**
    5858                @brief Constructor: Sets the element, whereon the iterator points, to the given element.
    59                 This constructor is protected and only for internal usage (don't mess with the BaseElements directly).
    60             */
    61             inline IteratorBase(ObjectListBaseElement* element = NULL)
     59            */
     60            inline IteratorBase(ObjectListElement<T>* element = NULL)
    6261            {
    6362                this->element_ = element;
     
    6564            }
    6665
    67 
    68         public:
    69             /**
    70                 @brief Constructor: Sets the element, whereon the iterator points, to the given element.
    71             */
    72             inline IteratorBase(ObjectListElement<T>* element)
    73             {
    74                 this->element_ = element;
    75                 this->registerIterator();
    76             }
    77 
    7866            /**
    7967                @brief Constructor: Sets the element, whereon the iterator points, to the given element of another type.
    8068                The element's type O must be a derivative of the Iterator's type T.
    8169            */
    82             template <class O>
    83             inline IteratorBase(ObjectListElement<O>* element)
    84             {
    85                 (void)static_cast<T*>((O*)NULL); // Check type: The element's type O must be a derivative of the Iterator's type T.
    86                 this->element_ = element;
    87                 this->registerIterator();
    88             }
    89 
    90             /**
    91                 @brief Constructor: Sets this element to the element of another Iterator.
    92                 @param other The other Iterator
    93             */
    94             inline IteratorBase(const IteratorBase& other)
    95             {
    96                 this->element_ = other.element_;
     70            template <class OT, class OI>
     71            inline IteratorBase(const IteratorBase<OT, OI>& other)
     72            {
     73                this->element_ = other.getElement();
    9774                this->registerIterator();
    9875            }
     
    205182                if (this->element_ == element)
    206183                    this->operator++();
     184            }
     185
     186            inline ObjectListBaseElement* getElement() const
     187            {
     188                return this->element_;
    207189            }
    208190
  • code/branches/cpp11_v2/src/libraries/core/object/ObjectList.h

    r10624 r10736  
    8484
    8585            /// Returns an Iterator to the first element in the list (for the root context).
    86             inline static ObjectListElement<T>* begin()
     86            inline static ObjectListIterator<T> begin()
    8787            {   return begin(Context::getRootContext());   }
    8888            /// Returns an Iterator to the first element in the list.
    89             inline static ObjectListElement<T>* begin(Context* context)
     89            inline static ObjectListIterator<T> begin(Context* context)
    9090            {
    9191                ObjectListBase* list = context->getObjectList<T>();
     
    9494
    9595            /// Returns an Iterator to the element after the last element in the list (for the root context).
    96             inline static ObjectListElement<T>* end()
     96            inline static ObjectListIterator<T> end()
    9797            {   return end(Context::getRootContext());   }
    9898            /// Returns an Iterator to the element after the last element in the list.
    99             inline static ObjectListElement<T>* end(Context* context)
     99            inline static ObjectListIterator<T> end(Context* context)
    100100            {
    101101                ObjectListBase* list = context->getObjectList<T>();
     
    104104
    105105            /// Returns an Iterator to the last element in the list (for the root context).
    106             inline static ObjectListElement<T>* rbegin()
     106            inline static ObjectListIterator<T> rbegin()
    107107            {   return rbegin(Context::getRootContext());   }
    108108            /// Returns an Iterator to the last element in the list.
    109             inline static ObjectListElement<T>* rbegin(Context* context)
     109            inline static ObjectListIterator<T> rbegin(Context* context)
    110110            {
    111111                ObjectListBase* list = context->getObjectList<T>();
     
    114114
    115115            /// Returns an Iterator to the element before the first element in the list (for the root context).
    116             inline static ObjectListElement<T>* rend()
     116            inline static ObjectListIterator<T> rend()
    117117            {   return rend(Context::getRootContext());   }
    118118            /// Returns an Iterator to the element before the first element in the list.
    119             inline static ObjectListElement<T>* rend(Context* context)
     119            inline static ObjectListIterator<T> rend(Context* context)
    120120            {
    121121                ObjectListBase* list = context->getObjectList<T>();
  • code/branches/cpp11_v2/src/libraries/core/object/ObjectListBase.h

    r10733 r10736  
    9393            }
    9494
    95             operator T*()
    96             {
    97                 return object_;
    98             }
    99 
    10095            T* object_;              //!< The object
    10196    };
  • code/branches/cpp11_v2/src/libraries/core/object/ObjectListIterator.h

    r10624 r10736  
    8686                @param other The other ObjectListIterator
    8787            */
    88             inline ObjectListIterator(const IteratorBase<T, ObjectListIterator<T> >& other) : IteratorBase<T, ObjectListIterator<T> >(other) {}
     88            template <class OI>
     89            inline ObjectListIterator(const IteratorBase<T, OI>& other) : IteratorBase<T, ObjectListIterator<T> >(other) {}
    8990
    9091            /**
Note: See TracChangeset for help on using the changeset viewer.