From 51ac5d2007f1caf6bc6e65b485ba896357696654 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Jun 2021 00:59:03 +0100 Subject: Add RecordSet RowView This represents a view into a recordset by row number and provides easy access to values in a column by index and the ability to create a new object instance by N columns which are passed to the object's constructor. --- lib/dbRecordSet.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/dbRecordSet.h') diff --git a/lib/dbRecordSet.h b/lib/dbRecordSet.h index 9bddc01..5bd6967 100644 --- a/lib/dbRecordSet.h +++ b/lib/dbRecordSet.h @@ -5,6 +5,31 @@ #include namespace MyGrate { + class RecordSet; + + class RowView { + public: + RowView(const RecordSet * rs, std::size_t rw = 0); + + DbValue operator[](std::size_t col) const; + + template> + auto + create() const + { + return create(Indices {}); + } + + template auto create(std::index_sequence) const + { + return std::make_unique((*this)[I]...); + } + + private: + const RecordSet * recordSet; + std::size_t row; + }; + class RecordSet { public: virtual ~RecordSet() = default; @@ -12,6 +37,7 @@ namespace MyGrate { 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; }; using RecordSetPtr = std::unique_ptr; } -- cgit v1.2.3