MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #ifndef __MYGUI_ENUMERATOR_H__ 00023 #define __MYGUI_ENUMERATOR_H__ 00024 00025 #include <assert.h> 00026 00027 namespace MyGUI 00028 { 00029 00062 template<typename T> 00063 class Enumerator 00064 { 00065 private: 00066 Enumerator() 00067 { 00068 } 00069 00070 public: 00071 explicit Enumerator(const T& _container) : 00072 m_first(true), 00073 m_current(_container.begin()), 00074 m_end(_container.end()) 00075 { 00076 } 00077 00078 Enumerator(typename T::const_iterator _first, typename T::const_iterator _end) : 00079 m_first(true), 00080 m_current(_first), 00081 m_end(_end) 00082 { 00083 } 00084 00085 bool next() 00086 { 00087 if (m_current == m_end) 00088 return false; 00089 else if (m_first) 00090 { 00091 m_first = false; 00092 return true; 00093 } 00094 ++ m_current; 00095 if (m_current == m_end) 00096 return false; 00097 return true; 00098 } 00099 00100 typename T::const_reference operator->() const 00101 { 00102 assert(m_current != m_end); 00103 return (*m_current); 00104 } 00105 00106 typename T::const_reference current() 00107 { 00108 assert(m_current != m_end); 00109 return (*m_current); 00110 } 00111 00112 private: 00113 bool m_first; 00114 typename T::const_iterator m_current; 00115 typename T::const_iterator m_end; 00116 }; 00117 00118 } // namespace MyGUI 00119 00120 #endif // __MYGUI_ENUMERATOR_H__