MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_Enumerator.h
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_ENUMERATOR_H__
23 #define __MYGUI_ENUMERATOR_H__
24
25 #include <assert.h>
26
27 namespace MyGUI
28 {
29
62 template<typename T>
63 class Enumerator
64 {
65 private:
66 Enumerator()
67 {
68 }
69
70 public:
71 explicit Enumerator(const T& _container) :
72 m_first(true),
73 m_current(_container.begin()),
74 m_end(_container.end())
75 {
76 }
77
78 Enumerator(typename T::const_iterator _first, typename T::const_iterator _end) :
79 m_first(true),
80 m_current(_first),
81 m_end(_end)
82 {
83 }
84
85 bool next()
86 {
87 if (m_current == m_end)
88 return false;
89 else if (m_first)
90 {
91 m_first = false;
92 return true;
93 }
94 ++ m_current;
95 if (m_current == m_end)
96 return false;
97 return true;
98 }
99
100 typename T::const_reference operator->() const
101 {
102 assert(m_current != m_end);
103 return (*m_current);
104 }
105
106 typename T::const_reference current()
107 {
108 assert(m_current != m_end);
109 return (*m_current);
110 }
111
112 private:
113 bool m_first;
114 typename T::const_iterator m_current;
115 typename T::const_iterator m_end;
116 };
117
118 } // namespace MyGUI
119
120 #endif // __MYGUI_ENUMERATOR_H__
MyGUI::Enumerator::operator->
T::const_reference operator->() const
Definition: MyGUI_Enumerator.h:100
MyGUI::Enumerator::Enumerator
Enumerator(const T &_container)
Definition: MyGUI_Enumerator.h:71
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:63
MyGUI::Enumerator::next
bool next()
Definition: MyGUI_Enumerator.h:85
MyGUI::Enumerator::Enumerator
Enumerator(typename T::const_iterator _first, typename T::const_iterator _end)
Definition: MyGUI_Enumerator.h:78
MyGUI::Enumerator::current
T::const_reference current()
Definition: MyGUI_Enumerator.h:106