summaryrefslogtreecommitdiff
path: root/p2pvr/lib/containerCreator.h
blob: 289ac9ecce7985194c5ef389978e363682baa1d7 (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
#ifndef CONTAINERCREATOR_H
#define CONTAINERCREATOR_H

#include <boost/function.hpp>
#include <Ice/Handle.h>
#include "objectRowState.h"

template <typename T, typename V, typename P = IceInternal::Handle<V>>
class ContainerCreator {
	public:
		ContainerCreator(T & c) : container(c) { }

		void populate(
				boost::function<bool()> fetch,
				boost::function<VariableType(unsigned int)> get,
				unsigned int columnCount)
		{
			while (fetch()) {
				auto v = P(new V);
				container.push_back(v);
				ObjectRowState<P> rs;
				if (rs.fields.size() != columnCount) {
					throw std::runtime_error("Incorrent column count");
				}
				for (unsigned int c = 0; c < columnCount; c++) {
					rs.fields[c] = get(c);
				}
				UnbindColumns<P>(rs, v);
			}
		}
	private:
		T & container;
};

#endif