Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 26/7/2004 00003 author: Paul D Turner 00004 00005 purpose: Defines interface for base iterator class 00006 *************************************************************************/ 00007 /*************************************************************************** 00008 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining 00011 * a copy of this software and associated documentation files (the 00012 * "Software"), to deal in the Software without restriction, including 00013 * without limitation the rights to use, copy, modify, merge, publish, 00014 * distribute, sublicense, and/or sell copies of the Software, and to 00015 * permit persons to whom the Software is furnished to do so, subject to 00016 * the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be 00019 * included in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00023 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00024 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00025 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00026 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00027 * OTHER DEALINGS IN THE SOFTWARE. 00028 ***************************************************************************/ 00029 /************************************************************************* 00030 This is based somewhat on MapIterator in the Ogre library (www.ogre3d.org) 00031 *************************************************************************/ 00032 #ifndef _CEGUIIteratorBase_h_ 00033 #define _CEGUIIteratorBase_h_ 00034 00035 #include "CEGUI/Base.h" 00036 00037 00038 // Start of CEGUI namespace section 00039 namespace CEGUI 00040 { 00045 template<typename T, typename V = typename T::value_type> 00046 class ConstBaseIterator 00047 { 00048 public: 00049 typedef V value_type; 00050 00061 ConstBaseIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) : 00062 d_currIter(start_iter), 00063 d_startIter(start_iter), 00064 d_endIter(end_iter) 00065 { 00066 } 00067 00068 00073 virtual ~ConstBaseIterator(void) 00074 { 00075 } 00076 00077 00082 ConstBaseIterator(const ConstBaseIterator<T, V>& org) : 00083 d_currIter(org.d_currIter), 00084 d_startIter(org.d_startIter), 00085 d_endIter(org.d_endIter) 00086 { 00087 } 00088 00089 00094 ConstBaseIterator<T, V>& operator=(const ConstBaseIterator<T, V>& rhs) 00095 { 00096 d_currIter = rhs.d_currIter; 00097 d_startIter = rhs.d_startIter; 00098 d_endIter = rhs.d_endIter; 00099 00100 return *this; 00101 } 00102 00103 00108 virtual value_type getCurrentValue(void) const = 0; 00109 00110 00115 bool isAtEnd(void) const 00116 { 00117 return d_currIter == d_endIter; 00118 } 00119 00120 00125 bool isAtStart(void) const 00126 { 00127 return d_currIter == d_startIter; 00128 } 00129 00134 bool operator==(const ConstBaseIterator<T, V>& rhs) const 00135 { 00136 return d_currIter == rhs.d_currIter; 00137 } 00138 00139 00144 bool operator!=(const ConstBaseIterator<T, V>& rhs) const 00145 { 00146 return !operator==(rhs); 00147 } 00148 00149 00154 value_type operator*() const 00155 { 00156 return getCurrentValue(); 00157 } 00158 00159 00164 void toStart(void) 00165 { 00166 d_currIter = d_startIter; 00167 } 00168 00169 00174 void toEnd(void) 00175 { 00176 d_currIter = d_endIter; 00177 } 00178 00179 00180 protected: 00181 /************************************************************************* 00182 No default construction available 00183 *************************************************************************/ 00184 ConstBaseIterator(void) {} 00185 00186 /************************************************************************* 00187 Implementation Data 00188 *************************************************************************/ 00189 typename T::const_iterator d_currIter; 00190 typename T::const_iterator d_startIter; 00191 typename T::const_iterator d_endIter; 00192 }; 00193 00195 template<class T> 00196 class ConstMapIterator : public ConstBaseIterator<T, typename T::mapped_type> 00197 { 00198 public: 00199 ConstMapIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) : 00200 ConstBaseIterator<T, typename T::mapped_type>(start_iter, end_iter) 00201 {} 00202 00203 typename ConstBaseIterator<T, typename T::mapped_type>::value_type 00204 getCurrentValue() const 00205 { 00206 return this->d_currIter->second; 00207 } 00208 00213 typename T::key_type getCurrentKey() const 00214 { 00215 return this->d_currIter->first; 00216 } 00217 00225 ConstMapIterator<T>& operator++() 00226 { 00227 if (ConstBaseIterator<T, typename T::mapped_type>::d_currIter != ConstBaseIterator<T, typename T::mapped_type>::d_endIter) 00228 ++ConstBaseIterator<T, typename T::mapped_type>::d_currIter; 00229 00230 return *this; 00231 } 00232 00240 ConstMapIterator<T>& operator--() 00241 { 00242 if (ConstBaseIterator<T, typename T::mapped_type>::d_currIter != ConstBaseIterator<T, typename T::mapped_type>::d_startIter) 00243 --ConstBaseIterator<T, typename T::mapped_type>::d_currIter; 00244 00245 return *this; 00246 } 00247 00255 ConstMapIterator<T> operator++(int) 00256 { 00257 ConstMapIterator<T> tmp = *this; 00258 ++*this; 00259 00260 return tmp; 00261 } 00262 00270 ConstMapIterator<T> operator--(int) 00271 { 00272 ConstMapIterator<T> tmp = *this; 00273 --*this; 00274 00275 return tmp; 00276 } 00277 00278 protected: 00279 /************************************************************************* 00280 No default construction available 00281 *************************************************************************/ 00282 ConstMapIterator(void) {} 00283 }; 00284 00286 template<class T> 00287 class ConstVectorIterator : public ConstBaseIterator<T> 00288 { 00289 public: 00290 ConstVectorIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) : 00291 ConstBaseIterator<T>(start_iter, end_iter) 00292 {} 00293 00294 typename ConstBaseIterator<T>::value_type 00295 getCurrentValue() const 00296 { 00297 return *this->d_currIter; 00298 } 00299 00307 ConstVectorIterator<T>& operator++() 00308 { 00309 if (ConstBaseIterator<T, typename T::value_type>::d_currIter != ConstBaseIterator<T, typename T::value_type>::d_endIter) 00310 ++ConstBaseIterator<T, typename T::value_type>::d_currIter; 00311 00312 return *this; 00313 } 00314 00322 ConstVectorIterator<T>& operator--() 00323 { 00324 if (ConstBaseIterator<T, typename T::value_type>::d_currIter != ConstBaseIterator<T, typename T::value_type>::d_startIter) 00325 --ConstBaseIterator<T, typename T::value_type>::d_currIter; 00326 00327 return *this; 00328 } 00329 00337 ConstVectorIterator<T> operator++(int) 00338 { 00339 ConstVectorIterator<T> tmp = *this; 00340 ++*this; 00341 00342 return tmp; 00343 } 00344 00352 ConstVectorIterator<T> operator--(int) 00353 { 00354 ConstVectorIterator<T> tmp = *this; 00355 --*this; 00356 00357 return tmp; 00358 } 00359 00360 protected: 00361 /************************************************************************* 00362 No default construction available 00363 *************************************************************************/ 00364 ConstVectorIterator(void) {} 00365 }; 00366 00367 } // End of CEGUI namespace section 00368 00369 00370 #endif // end of guard _CEGUIIteratorBase_h_