#ifndef CONTAINERITERATOR_H
#define CONTAINERITERATOR_H

#include <iHaveSubTasks.h>
#include <boost/foreach.hpp>
#include "objectRowState.h"

template <typename T>
class ContainerIterator : public IHaveSubTasks {
	public:
		ContainerIterator(const T * con) :
			SourceObject(__PRETTY_FUNCTION__),
			IHaveSubTasks(NULL),
			binder(boost::bind(&BindColumns<typename T::value_type>, _1, _2)),
			container(con)
		{
		}

		void execute(ExecContext * ec) const
		{
			ObjectRowState<typename T::value_type> rs;
			BOOST_FOREACH(const auto & i, *container) {
				binder(rs, i);
				rs.process(boost::bind(&ContainerIterator::executeChildren, this, ec));
			}
		}

	private:
		boost::function<void(RowState &, const typename T::value_type &)> binder;
		const T * container;
		
		void executeChildren(ExecContext * ec) const
		{
			BOOST_FOREACH(const Tasks::value_type & sq, normal) {
				sq->execute(ec);
			}
		}
};

#endif