diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-17 19:38:26 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-17 19:38:26 +0100 |
commit | d22eea2fd6130b431bc11694410775b993c5ab7a (patch) | |
tree | bfa00edd5135dcbee8bffe7d9ddd25c6cc0697a6 /lib/dbRecordSet.cpp | |
parent | Change m4 quoting for genstmt (diff) | |
download | mygrate-d22eea2fd6130b431bc11694410775b993c5ab7a.tar.bz2 mygrate-d22eea2fd6130b431bc11694410775b993c5ab7a.tar.xz mygrate-d22eea2fd6130b431bc11694410775b993c5ab7a.zip |
Make RecordSet foreach ready
Diffstat (limited to 'lib/dbRecordSet.cpp')
-rw-r--r-- | lib/dbRecordSet.cpp | 39 |
1 files changed, 39 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()}; + } } |