summaryrefslogtreecommitdiff
path: root/p2pvr/util/containerIterator.h
blob: 2b610557e4c38a43c5b38f6bfc18ef243556ff2b (plain)
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
#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