lintel 0.2.0
Loading...
Searching...
No Matches
Arguments.h
Go to the documentation of this file.
1#ifndef LINTEL_ARGUMENTS_H
2#define LINTEL_ARGUMENTS_H
3
4#include <map>
5#include <ostream>
6#include <string>
7#include <vector>
8
13
14namespace lintel {
15namespace db {
20 {
21 private:
22 std::string m_value;
23 std::string m_name;
24 db::ConnectionType m_connectionType;
25
26 public:
32 Argument(std::string value, std::string name);
33
35 [[nodiscard]] const std::string &getValue() const;
36
38 [[nodiscard]] const std::string &getName() const;
39
45
52 template<typename TYPE> TYPE getValue() const
53 {
54 switch (m_connectionType) {
61 default:
62 // Reached for an enumerator outside ConnectionType::Value, e.g. from a corrupt or
63 // foreign configuration. Without this the function ran off its end (undefined
64 // behaviour, CodeQL cpp/missing-return).
65 throw db::SQLException("Unknown connection type " + std::to_string(static_cast<int>(m_connectionType)));
66 }
67 }
68
70 friend std::ostream &operator<<(std::ostream &os, const db::Argument &argument);
71 };
72
77 {
78 private:
79 // members
80 std::vector<Argument> m_arguments;
81 std::map<std::string, Argument> m_argumentsMap;
82 ConnectionType m_connectionType;
83
84 // iterator classes
88 class Iterator
89 : public std::iterator<std::random_access_iterator_tag, Argument, std::ptrdiff_t, Argument *, Argument &>
90 {
91 private:
92 Arguments &m_arguments;
93 std::size_t m_pos;
94
95 public:
101 explicit Iterator(Arguments &arguments, bool end = false)
102 : m_arguments(arguments), m_pos(end ? static_cast<std::size_t>(m_arguments.size()) : 0)
103 {}
104
105 Iterator &operator++()
106 {
107 ++m_pos;
108 return *this;
109 }
110
111 const Iterator operator++(int)
112 {
113 Iterator tmp = *this;
114 ++m_pos;
115 return tmp;
116 }
117
118 bool operator==(Iterator other) const { return m_pos == other.m_pos; }
119
120 bool operator!=(Iterator other) const { return !(*this == other); }
121
122 reference operator*() { return m_arguments.of(m_pos); }
123 };
124
128 class ConstIterator
129 : public std::
130 iterator<std::random_access_iterator_tag, Argument, std::ptrdiff_t, const Argument *, const Argument &>
131 {
132 private:
133 const Arguments &m_arguments;
134 std::size_t m_pos;
135
136 public:
142 explicit ConstIterator(const Arguments &arguments, bool end = false)
143 : m_arguments(arguments), m_pos(end ? static_cast<std::size_t>(m_arguments.size()) : 0)
144 {}
145
146 ConstIterator &operator++()
147 {
148 ++m_pos;
149 return *this;
150 }
151
152 const ConstIterator operator++(int)
153 {
154 ConstIterator tmp = *this;
155 ++m_pos;
156 return tmp;
157 }
158
159 bool operator==(ConstIterator other) const { return m_pos == other.m_pos; }
160
161 bool operator!=(ConstIterator other) const { return !(*this == other); }
162
163 reference operator*() const { return m_arguments.of(m_pos); }
164 };
165
166 public:
172
175
177 [[nodiscard]] std::size_t size() const;
178
180 [[nodiscard]] bool empty() const;
181
187 Argument &of(std::size_t iterator);
188
194 [[nodiscard]] const Argument &of(std::size_t iterator) const;
195
201 [[nodiscard]] const Argument &of(const std::string &name) const;
202
204 Iterator begin() { return Iterator(*this); }
205
207 Iterator end() { return Iterator(*this, true); }
208
210 [[nodiscard]] ConstIterator begin() const { return ConstIterator(*this); }
211
213 [[nodiscard]] ConstIterator end() const { return ConstIterator(*this, true); }
214 };
215};// namespace db
216
217}// namespace lintel
218#endif// LINTEL_ARGUMENTS_H
static T deserializeFromString(const std::string &string)
Definition StringifyService.h:39
Definition Arguments.h:20
const std::string & getValue() const
const std::string & getName() const
void setConnectionType(ConnectionType connectionType)
TYPE getValue() const
Definition Arguments.h:52
friend std::ostream & operator<<(std::ostream &os, const db::Argument &argument)
Argument(std::string value, std::string name)
Definition Arguments.h:77
std::size_t size() const
Iterator end()
Definition Arguments.h:207
Iterator begin()
Definition Arguments.h:204
ConstIterator begin() const
Definition Arguments.h:210
Argument & of(std::size_t iterator)
const Argument & of(std::size_t iterator) const
const Argument & of(const std::string &name) const
ConstIterator end() const
Definition Arguments.h:213
void add(Argument &argument)
Arguments(ConnectionType connectionType)
Definition ConnectionType.h:15
@ SQLite
Definition ConnectionType.h:18
@ PostgreSQL
Definition ConnectionType.h:18
@ UNDEFINED
Definition ConnectionType.h:18
Definition SQLException.h:11
Definition Serialization.h:34
Definition Serialization.h:38
Definition BaseFeature.h:6
constexpr std::string_view type_name()
Definition TypeName.h:9