iterTrav.h 998 Bytes
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

#ifndef __ITERATORIZE__
#define __ITERATORIZE__
/**
 * template classs that add iterator to Traversor
 * to allow the use of c++11 syntax for (auto d : v)
 */
template <typename TRAV>
class Iteratorize: public TRAV
{
public:
	typedef typename TRAV::MapType MAP;
	typedef typename TRAV::IterType ITER;
	typedef typename TRAV::ParamType PARAM;

	Iteratorize(const MAP& map, PARAM p):
		TRAV(map,p),m_begin(this,TRAV::begin()),m_end(this,TRAV::end())
	{}


	class iterator
	{
		Iteratorize<TRAV>* m_ptr;
		ITER m_index;

	public:

		inline iterator(Iteratorize<TRAV>* p, ITER i): m_ptr(p),m_index(i){}

		inline iterator& operator++()
		{
			m_index = m_ptr->next();
			return *this;
		}

		inline ITER& operator*()
		{
			return m_index;
		}

		inline bool operator!=(const iterator& it)
		{
			return m_index.dart != it.m_index.dart;
		}

	};

	inline iterator begin()
	{
		return m_begin;
	}

	inline iterator end()
	{
		return m_end;
	}

protected:
	iterator m_begin;
	iterator m_end;
};

#endif