00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MYGUI_ENUMERATOR_H__
00024 #define __MYGUI_ENUMERATOR_H__
00025
00026 #include <assert.h>
00027
00028 namespace MyGUI
00029 {
00030
00063 template<typename T>
00064 class Enumerator
00065 {
00066 private:
00067 Enumerator() { }
00068
00069 public:
00070 explicit Enumerator(const T& _container) :
00071 m_first(true),
00072 m_current(_container.begin()),
00073 m_end(_container.end())
00074 {
00075 }
00076
00077 Enumerator(typename T::const_iterator _first, typename T::const_iterator _end) :
00078 m_first(true),
00079 m_current(_first),
00080 m_end(_end)
00081 {
00082 }
00083
00084 bool next()
00085 {
00086 if (m_current == m_end) return false;
00087 else if (m_first)
00088 {
00089 m_first = false;
00090 return true;
00091 }
00092 ++ m_current;
00093 if (m_current == m_end) return false;
00094 return true;
00095 }
00096
00097 typename T::const_reference operator->() const { assert(m_current != m_end); return (*m_current); }
00098 typename T::const_reference current() { assert(m_current != m_end); return (*m_current); }
00099
00100 private:
00101 bool m_first;
00102 typename T::const_iterator m_current;
00103 typename T::const_iterator m_end;
00104 };
00105
00106 }
00107
00108 #endif // __MYGUI_ENUMERATOR_H__