Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 1, 2007, 4:24:56 AM (16 years ago)
Author:
landauf
Message:

added comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/core/Iterator.h

    r258 r365  
     1/*!
     2    @file Iterator.h
     3    @brief Definition of the Iterator class.
     4
     5    The Iterator of a given class allows to iterate through an ObjectList, containing all objects of that type.
     6    This is the only way to access the objects in an ObjectList.
     7
     8    Usage:
     9    for (Iterator<class> it = ObjectList<class>::start(); it != 0; ++it)
     10    {
     11        it->someFunction(...);
     12        class* myObject = *it;
     13    }
     14
     15    Warning: Don't delete an object directly through the iterator.
     16*/
     17
    118#ifndef _Iterator_H__
    219#define _Iterator_H__
     
    421namespace orxonox
    522{
     23    //! The iterator allows to iterate through an ObjectList of a given class.
    624    template <class T>
    725    class Iterator
    826    {
    927        public:
     28            /**
     29                @brief Constructor: Sets the element whereon the iterator points to zero.
     30            */
    1031            Iterator()
    1132            {
     
    1334            }
    1435
     36            /**
     37                @brief Constructor: Sets the element whereon the iterator points to a given element.
     38                @param element The element to start with
     39            */
    1540            Iterator(ObjectListElement<T>* element)
    1641            {
     
    1843            }
    1944
     45            /**
     46                @brief Overloading of the ++it operator: Iterator iterates to the next object in the list.
     47                @return The Iterator itself
     48            */
    2049            Iterator<T> operator++()
    2150            {
     
    2453            }
    2554
     55            /**
     56                @brief Overloading of the --it operator: Iterator iterates to the previous object in the list.
     57                @return The Iterator itself
     58            */
    2659            Iterator<T> operator--()
    2760            {
     
    3063            }
    3164
     65            /**
     66                @brief Overloading of the *it operator: returns the pointer to the object.
     67                @return The object the Iterator points at
     68            */
    3269            T* operator*()
    3370            {
     
    3572            }
    3673
     74            /**
     75                @brief Overloading of the it-> operator: returns the pointer to the object.
     76                @return The object the Iterator points at
     77            */
    3778            T* operator->() const
    3879            {
     
    4182            }
    4283
     84            /**
     85                @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.
     86                @return True if the iterator points to an existing object.
     87            */
    4388            operator bool()
    4489            {
     
    4691            }
    4792
     93            /**
     94                @brief Overloading of the (it != int) operator: Used for (it != 0) instead of typecast-operator to bool.
     95                @param compare The integer (must be zero, everything else makes no sense).
     96                @return True if the iterator points to an existing object.
     97            */
    4898            bool operator!=(int compare)
    4999            {
     100                // Comparing with something except zero makes no sense
    50101                if (compare != 0)
    51102                    std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n";
     
    55106
    56107        private:
    57             ObjectListElement<T>* element_;
     108            ObjectListElement<T>* element_;     //!< The element the Iterator points to
    58109    };
    59110}
Note: See TracChangeset for help on using the changeset viewer.