diff options
-rw-r--r-- | lib/dbRecordSet.cpp | 39 | ||||
-rw-r--r-- | lib/dbRecordSet.h | 8 |
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/dbRecordSet.cpp b/lib/dbRecordSet.cpp index 3754130..d5e55f0 100644 --- a/lib/dbRecordSet.cpp +++ b/lib/dbRecordSet.cpp @@ -1,4 +1,5 @@ #include "dbRecordSet.h" +#include "helpers.h" namespace MyGrate { RowView::RowView(const RecordSet * rs, std::size_t rw) : recordSet {rs}, row {rw} { } @@ -9,6 +10,32 @@ namespace MyGrate { return recordSet->at(row, col); } + bool + RowView::operator==(const RowView & that) const + { + verify<std::logic_error>(this->recordSet == that.recordSet, "Cannot iterator between RecordSets"); + return this->row == that.row; + } + + RowView & + RowView::operator++() + { + row++; + return *this; + } + + const RowView & + RowView::operator*() const + { + return *this; + } + + std::size_t + RowView::currentRow() const + { + return row; + } + RowView RecordSet::operator[](std::size_t row) const { @@ -20,4 +47,16 @@ namespace MyGrate { { return at(0, 0); } + + RowView + RecordSet::begin() const + { + return {this, 0}; + } + + RowView + RecordSet::end() const + { + return {this, rows()}; + } } diff --git a/lib/dbRecordSet.h b/lib/dbRecordSet.h index e430e58..a9da882 100644 --- a/lib/dbRecordSet.h +++ b/lib/dbRecordSet.h @@ -25,6 +25,11 @@ namespace MyGrate { return std::make_unique<S>((*this)[I + O]...); } + bool operator==(const RowView &) const; + RowView & operator++(); + const RowView & operator*() const; + std::size_t currentRow() const; + private: const RecordSet * recordSet; std::size_t row; @@ -39,6 +44,9 @@ namespace MyGrate { virtual DbValue at(std::size_t, std::size_t) const = 0; RowView operator[](std::size_t row) const; DbValue operator*() const; + + RowView begin() const; + RowView end() const; }; using RecordSetPtr = std::unique_ptr<RecordSet>; } |