MyGUI_Enumerator.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_ENUMERATOR_H_
#define MYGUI_ENUMERATOR_H_
#include <cassert>
namespace MyGUI
{
template<typename T>
class Enumerator
{
public:
explicit Enumerator(const T& _container) :
m_first(true),
m_current(_container.begin()),
m_end(_container.end())
{
}
Enumerator(typename T::const_iterator _first, typename T::const_iterator _end) :
m_first(true),
m_current(_first),
m_end(_end)
{
}
bool next()
{
if (m_current == m_end)
return false;
if (m_first)
{
m_first = false;
return true;
}
++m_current;
return m_current != m_end;
}
typename T::const_reference operator->() const
{
assert(m_current != m_end);
return (*m_current);
}
typename T::const_reference current()
{
assert(m_current != m_end);
return (*m_current);
}
private:
bool m_first;
typename T::const_iterator m_current;
typename T::const_iterator m_end;
};
} // namespace MyGUI
#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