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