summaryrefslogtreecommitdiff
path: root/lib/dbRecordSet.h
blob: e430e589884f2c5eaa8de0e02ba6ccecb868206c (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
42
43
44
45
46
#ifndef MYGRATE_DBRECORDSET_H
#define MYGRATE_DBRECORDSET_H

#include <dbTypes.h>
#include <memory>

namespace MyGrate {
	class RecordSet;

	class RowView {
	public:
		RowView(const RecordSet * rs, std::size_t rw = 0);

		DbValue operator[](std::size_t col) const;

		template<typename S, std::size_t N, std::size_t O = 0>
		auto
		create() const
		{
			return create<S, O>(std::make_index_sequence<N> {});
		}

		template<typename S, std::size_t O, std::size_t... I> auto create(std::index_sequence<I...>) const
		{
			return std::make_unique<S>((*this)[I + O]...);
		}

	private:
		const RecordSet * recordSet;
		std::size_t row;
	};

	class RecordSet {
	public:
		virtual ~RecordSet() = default;

		virtual std::size_t rows() const = 0;
		virtual std::size_t columns() const = 0;
		virtual DbValue at(std::size_t, std::size_t) const = 0;
		RowView operator[](std::size_t row) const;
		DbValue operator*() const;
	};
	using RecordSetPtr = std::unique_ptr<RecordSet>;
}

#endif