MyGUI: MyGUI_Enumerator.h Source File

MyGUI 3.2.2

MyGUI_Enumerator.h
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #ifndef MYGUI_ENUMERATOR_H_
8 #define MYGUI_ENUMERATOR_H_
9
10 #include <assert.h>
11
12 namespace MyGUI
13 {
14
47 template<typename T>
48 class Enumerator
49 {
50 private:
51 Enumerator()
52 {
53 }
54
55 public:
56 explicit Enumerator(const T& _container) :
57 m_first(true),
58 m_current(_container.begin()),
59 m_end(_container.end())
60 {
61 }
62
63 Enumerator(typename T::const_iterator _first, typename T::const_iterator _end) :
64 m_first(true),
65 m_current(_first),
66 m_end(_end)
67 {
68 }
69
70 bool next()
71 {
72 if (m_current == m_end)
73 return false;
74 else if (m_first)
75 {
76 m_first = false;
77 return true;
78 }
79 ++ m_current;
80 if (m_current == m_end)
81 return false;
82 return true;
83 }
84
85 typename T::const_reference operator->() const
86 {
87 assert(m_current != m_end);
88 return (*m_current);
89 }
90
91 typename T::const_reference current()
92 {
93 assert(m_current != m_end);
94 return (*m_current);
95 }
96
97 private:
98 bool m_first;
99 typename T::const_iterator m_current;
100 typename T::const_iterator m_end;
101 };
102
103 } // namespace MyGUI
104
105 #endif // MYGUI_ENUMERATOR_H_
MyGUI::Enumerator::Enumerator
Enumerator(const T &_container)
Definition: MyGUI_Enumerator.h:56
MyGUI::Enumerator::current
T::const_reference current()
Definition: MyGUI_Enumerator.h:91
MyGUI::Enumerator::Enumerator
Enumerator(typename T::const_iterator _first, typename T::const_iterator _end)
Definition: MyGUI_Enumerator.h:63
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:48
MyGUI::Enumerator::operator->
T::const_reference operator->() const
Definition: MyGUI_Enumerator.h:85
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::Enumerator::next
bool next()
Definition: MyGUI_Enumerator.h:70