MyGUI: MyGUI_Enumerator.h Source File

MyGUI 3.4.3

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 <cassert>
11
12namespace MyGUI
13{
14
46
47 template<typename T>
48 class Enumerator
49 {
50 public:
51 explicit Enumerator(const T& _container) :
52 m_first(true),
53 m_current(_container.begin()),
54 m_end(_container.end())
55 {
56 }
57
58 Enumerator(typename T::const_iterator _first, typename T::const_iterator _end) :
59 m_first(true),
60 m_current(_first),
61 m_end(_end)
62 {
63 }
64
65 bool next()
66 {
67 if (m_current == m_end)
68 return false;
69 if (m_first)
70 {
71 m_first = false;
72 return true;
73 }
74 ++m_current;
75 return m_current != m_end;
76 }
77
78 typename T::const_reference operator->() const
79 {
80 assert(m_current != m_end);
81 return (*m_current);
82 }
83
84 typename T::const_reference current()
85 {
86 assert(m_current != m_end);
87 return (*m_current);
88 }
89
90 private:
91 bool m_first;
92 typename T::const_iterator m_current;
93 typename T::const_iterator m_end;
94 };
95
96} // namespace MyGUI
97
98#endif // MYGUI_ENUMERATOR_H_
MyGUI::Enumerator::Enumerator
Enumerator(const T &_container)
Definition MyGUI_Enumerator.h:51
MyGUI::Enumerator::current
T::const_reference current()
Definition MyGUI_Enumerator.h:84
MyGUI::Enumerator::Enumerator
Enumerator(typename T::const_iterator _first, typename T::const_iterator _end)
Definition MyGUI_Enumerator.h:58
MyGUI::Enumerator::next
bool next()
Definition MyGUI_Enumerator.h:65
MyGUI::Enumerator::operator->
T::const_reference operator->() const
Definition MyGUI_Enumerator.h:78
MyGUI
Definition MyGUI_ActionController.h:15