lintel 0.2.0
Loading...
Searching...
No Matches
Result.h
Go to the documentation of this file.
1#ifndef LINTEL_RESULT_H
2#define LINTEL_RESULT_H
3
4#include <iterator>
5#include <string>
6
11
12namespace lintel {
13namespace db {
18 class Result
19 {
20 private:
21 std::shared_ptr<postgresql::Result> m_result = nullptr;
22 std::shared_ptr<sqlite::Result> m_resultSQLite = nullptr;
23
24 public:
29 : public std::iterator<std::random_access_iterator_tag, Arguments, std::ptrdiff_t, Arguments *, Arguments &>
30 {
31 private:
32 Result &m_result;
33 std::size_t m_pos;
34
35 public:
41 explicit Iterator(Result &result, bool end = false)
42 : m_result(result), m_pos(end ? static_cast<std::size_t>(m_result.getSize()) : 0)
43 {}
44
46 {
47 ++m_pos;
48 return *this;
49 }
50
52 {
53 Iterator tmp = *this;
54 ++m_pos;
55 return tmp;
56 }
57
58 bool operator==(Iterator other) const { return m_pos == other.m_pos; }
59
60 bool operator!=(Iterator other) const { return !(*this == other); }
61
62 reference operator*() { return m_result.of(m_pos); }
63 };
64
69 : public std::
70 iterator<std::random_access_iterator_tag, Arguments, std::ptrdiff_t, const Arguments *, const Arguments &>
71 {
72 private:
73 const Result &m_result;
74 std::size_t m_pos;
75
76 public:
82 explicit ConstIterator(const Result &result, bool end = false)
83 : m_result(result), m_pos(end ? static_cast<std::size_t>(m_result.getSize()) : 0)
84 {}
85
87 {
88 ++m_pos;
89 return *this;
90 }
91
93 {
94 ConstIterator tmp = *this;
95 ++m_pos;
96 return tmp;
97 }
98
99 bool operator==(ConstIterator other) const { return m_pos == other.m_pos; }
100
101 bool operator!=(ConstIterator other) const { return !(*this == other); }
102
103 reference operator*() const { return m_result.of(m_pos); }
104 };
105
107 Iterator begin() { return Iterator(*this); }
108
110 Iterator end() { return Iterator(*this, true); }
111
113 ConstIterator begin() const { return ConstIterator(*this); }
114
116 ConstIterator end() const { return ConstIterator(*this, true); }
117
119 Result() = default;
120
123
128 explicit Result(std::shared_ptr<postgresql::Result> result);
129
134 explicit Result(std::shared_ptr<sqlite::Result> result);
135
142 [[nodiscard]] std::string getValue(int row, int attribute) const;
143
149 [[nodiscard]] Arguments &of(std::size_t pos);
150
156 [[nodiscard]] const Arguments &of(std::size_t pos) const;
157
160
162 [[nodiscard]] int getSize() const;
163 };
164}// namespace db
165
166}// namespace lintel
167#endif// LINTEL_RESULT_H
Definition Arguments.h:77
Definition Result.h:71
bool operator!=(ConstIterator other) const
Definition Result.h:101
reference operator*() const
Definition Result.h:103
bool operator==(ConstIterator other) const
Definition Result.h:99
ConstIterator & operator++()
Definition Result.h:86
ConstIterator(const Result &result, bool end=false)
Definition Result.h:82
ConstIterator operator++(int)
Definition Result.h:92
Definition Result.h:30
Iterator operator++(int)
Definition Result.h:51
Iterator(Result &result, bool end=false)
Definition Result.h:41
bool operator!=(Iterator other) const
Definition Result.h:60
bool operator==(Iterator other) const
Definition Result.h:58
reference operator*()
Definition Result.h:62
Iterator & operator++()
Definition Result.h:45
Definition Result.h:19
const Arguments & of(std::size_t pos) const
Iterator end()
Definition Result.h:110
Result(std::shared_ptr< sqlite::Result > result)
Arguments & of(std::size_t pos)
Iterator begin()
Definition Result.h:107
ConstIterator end() const
Definition Result.h:116
int getSize() const
ConstIterator begin() const
Definition Result.h:113
std::string getValue(int row, int attribute) const
Result(std::shared_ptr< postgresql::Result > result)
int getNumOfAttributes() const
Definition BaseFeature.h:6
constexpr std::string_view type_name()
Definition TypeName.h:9