PixelLightAPI  .
ConstIterator.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: ConstIterator.h                                *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_CONTAINER_CONSTITERATOR_H__
00024 #define __PLCORE_CONTAINER_CONSTITERATOR_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Namespace                                             ]
00030 //[-------------------------------------------------------]
00031 namespace PLCore {
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Forward declarations                                  ]
00036 //[-------------------------------------------------------]
00037 template <class ValueType> class IteratorImpl;
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    Constant iterator class
00046 *
00047 *  @remarks
00048 *    If an iterator is used, the iterable (for instance 'Map', 'Container' or 'Heap') the iterator
00049 *    is operating on should not be manipulated by adding/removing new elements because this may
00050 *    produce undefined behavior! Is highly recommended to keep the iterator in the smallest possible
00051 *    local scope and to never keep an iterator as for instance pointer over a long time.
00052 *
00053 *  @note
00054 *    - An iterator is similar to a "for each loop"
00055 */
00056 template <class ValueType>
00057 class ConstIterator {
00058 
00059 
00060     //[-------------------------------------------------------]
00061     //[ Public functions                                      ]
00062     //[-------------------------------------------------------]
00063     public:
00064         /**
00065         *  @brief
00066         *    Constructor
00067         *
00068         *  @param[in] cIteratorImpl
00069         *    Reference to the iterator specific implementation
00070         */
00071         ConstIterator(IteratorImpl<ValueType> &cIteratorImpl);
00072 
00073         /**
00074         *  @brief
00075         *    Copy constructor
00076         *
00077         *  @param[in] cIterator
00078         *    Source to copy from
00079         */
00080         ConstIterator(const ConstIterator<ValueType> &cIterator);
00081 
00082         /**
00083         *  @brief
00084         *    Destructor
00085         */
00086         ~ConstIterator<ValueType>();
00087 
00088         /**
00089         *  @brief
00090         *    Copy operator
00091         *
00092         *  @param[in] cIterator
00093         *    Source to copy from
00094         *
00095         *  @return
00096         *    Reference to this instance
00097         */
00098         ConstIterator<ValueType> &operator =(const ConstIterator<ValueType> &cIterator);
00099 
00100         /**
00101         *  @brief
00102         *    Checks whether the iterator can return a next element
00103         *
00104         *  @return
00105         *    'true' if the iterator can return a next element, else 'false'
00106         */
00107         bool HasNext() const;
00108 
00109         /**
00110         *  @brief
00111         *    Returns the next element
00112         *
00113         *  @return
00114         *    Reference to the next element, reference to the 'Null'-object on error
00115         */
00116         const ValueType &Next();
00117 
00118         /**
00119         *  @brief
00120         *    Returns the next element
00121         *
00122         *  @return
00123         *    Reference to the next element, reference to the 'Null'-object on error
00124         */
00125         const ValueType &operator ++();
00126 
00127         /**
00128         *  @brief
00129         *    Checks whether the iterator can return a previous element
00130         *
00131         *  @return
00132         *    'true' if the iterator can return a previous element, else 'false'
00133         */
00134         bool HasPrevious() const;
00135 
00136         /**
00137         *  @brief
00138         *    Returns the previous element
00139         *
00140         *  @return
00141         *    Reference to the previous element, reference to the 'Null'-object on error
00142         */
00143         const ValueType &Previous();
00144 
00145         /**
00146         *  @brief
00147         *    Returns the previous element
00148         *
00149         *  @return
00150         *    Reference to the previous element, reference to the 'Null'-object on error
00151         */
00152         const ValueType &operator --();
00153 
00154 
00155     //[-------------------------------------------------------]
00156     //[ Private functions                                     ]
00157     //[-------------------------------------------------------]
00158     private:
00159         /**
00160         *  @brief
00161         *    Checks whether the current internal iterator implementation is 'shared' and splits it if so
00162         */
00163         void UniqueImplementation();
00164 
00165 
00166     //[-------------------------------------------------------]
00167     //[ Private data                                          ]
00168     //[-------------------------------------------------------]
00169     private:
00170         IteratorImpl<ValueType> *m_pIteratorImpl;   /**< Pointer to the iterator specific implementation, always valid */
00171 
00172 
00173 };
00174 
00175 
00176 //[-------------------------------------------------------]
00177 //[ Namespace                                             ]
00178 //[-------------------------------------------------------]
00179 } // PLCore
00180 
00181 
00182 //[-------------------------------------------------------]
00183 //[ Implementation                                        ]
00184 //[-------------------------------------------------------]
00185 #include "PLCore/Container/ConstIterator.inl"
00186 
00187 
00188 #endif // __PLCORE_CONTAINER_CONSTITERATOR_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:52
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported