Dmitigr Pgfe  1.1beta
The modern C++ API to PostgreSQL
sql_vector.hpp
1 // -*- C++ -*-
2 // Copyright (C) Dmitry Igrishin
3 // For conditions of distribution and use, see files LICENSE.txt or pgfe.hpp
4 
5 #ifndef DMITIGR_PGFE_SQL_VECTOR_HPP
6 #define DMITIGR_PGFE_SQL_VECTOR_HPP
7 
8 #include "dmitigr/pgfe/sql_string.hpp"
9 #include "dmitigr/pgfe/types_fwd.hpp"
10 #include "dmitigr/pgfe/internal/dll.hxx"
11 
12 #include <memory>
13 #include <optional>
14 #include <string>
15 #include <type_traits>
16 #include <vector>
17 
18 namespace dmitigr::pgfe {
19 
27 class Sql_vector {
28 public:
32  virtual ~Sql_vector() = default;
33 
36 
40  static DMITIGR_PGFE_API std::unique_ptr<Sql_vector> APIENTRY make();
41 
64  static DMITIGR_PGFE_API std::unique_ptr<Sql_vector> APIENTRY make(const std::string& input);
65 
69  static DMITIGR_PGFE_API std::unique_ptr<Sql_vector> APIENTRY make(std::vector<std::unique_ptr<Sql_string>>&& v);
70 
74  virtual std::unique_ptr<Sql_vector> clone() const = 0;
75 
77 
78  // ---------------------------------------------------------------------------
79 
82 
86  virtual std::size_t sql_string_count() const = 0;
87 
91  virtual bool has_sql_strings() const = 0;
92 
97  virtual bool has_sql_string(const std::string& extra_name, const std::string& extra_value,
98  const std::size_t offset = 0, const std::size_t extra_offset = 0) const = 0;
99 
116  virtual std::optional<std::size_t> sql_string_index(const std::string& extra_name, const std::string& extra_value,
117  std::size_t offset = 0, std::size_t extra_offset = 0) const = 0;
118 
125  virtual std::size_t sql_string_index_throw(const std::string& extra_name, const std::string& extra_value,
126  std::size_t offset = 0, std::size_t extra_offset = 0) const = 0;
127 
136  virtual Sql_string* sql_string(std::size_t index) = 0;
137 
141  virtual const Sql_string* sql_string(std::size_t index) const = 0;
142 
155  virtual Sql_string* sql_string(const std::string& extra_name, const std::string& extra_value,
156  std::size_t offset = 0, std::size_t extra_offset = 0) = 0;
157 
161  virtual const Sql_string* sql_string(const std::string& extra_name, const std::string& extra_value,
162  std::size_t offset = 0, std::size_t extra_offset = 0) const = 0;
163 
165 
166  // --------------------------------------------------------------------------
167 
170 
180  virtual void set_sql_string(std::size_t index, std::unique_ptr<Sql_string>&& sql_string) = 0;
181 
188  template<typename ... Types>
189  void set_sql_string(std::size_t index, Types&& ... args)
190  {
191  set_sql_string(index, Sql_string::make(std::forward<Types>(args)...));
192  }
193 
202  virtual void append_sql_string(std::unique_ptr<Sql_string>&& sql_string) = 0;
203 
207  template<typename ... Types>
208  void append_sql_string(Types&& ... args)
209  {
210  append_sql_string(Sql_string::make(std::forward<Types>(args)...));
211  }
212 
222  virtual void insert_sql_string(std::size_t index, std::unique_ptr<Sql_string>&& sql_string) = 0;
223 
227  template<typename ... Types>
228  void insert_sql_string(std::size_t index, Types&& ... args)
229  {
230  static_assert(sizeof ... (args) != 1 || !std::is_same_v<std::tuple_element_t<0, std::tuple<Types ...>>, std::nullptr_t>,
231  "A SQL string must not be null");
232  insert_sql_string(index, Sql_string::make(std::forward<Types>(args)...));
233  }
234 
241  virtual void remove_sql_string(std::size_t index) = 0;
242 
244 
245  // ---------------------------------------------------------------------------
246 
249 
253  virtual std::string to_string() const = 0;
254 
258  virtual std::vector<std::unique_ptr<Sql_string>> to_vector() const = 0;
259 
266  virtual std::vector<std::unique_ptr<Sql_string>> move_to_vector() = 0;
267 
269 
270 private:
271  friend detail::iSql_vector;
272 
273  Sql_vector() = default;
274 };
275 
276 } // namespace dmitigr::pgfe
277 
278 #endif // DMITIGR_PGFE_SQL_VECTOR_HPP
virtual bool has_sql_strings() const =0
static DMITIGR_PGFE_API std::unique_ptr< Sql_vector > APIENTRY make()
Makes an empty SQL vector.
virtual std::vector< std::unique_ptr< Sql_string > > move_to_vector()=0
virtual bool has_sql_string(const std::string &extra_name, const std::string &extra_value, const std::size_t offset=0, const std::size_t extra_offset=0) const =0
virtual std::unique_ptr< Sql_vector > clone() const =0
void insert_sql_string(std::size_t index, Types &&... args)
Definition: sql_vector.hpp:228
virtual std::size_t sql_string_count() const =0
Public API.
Definition: array_conversions.hpp:12
virtual void insert_sql_string(std::size_t index, std::unique_ptr< Sql_string > &&sql_string)=0
Inserts new SQL string to this vector.
virtual void remove_sql_string(std::size_t index)=0
Removes SQL string from the vector.
Represents preparsed SQL strings.
Definition: sql_string.hpp:39
virtual std::size_t sql_string_index_throw(const std::string &extra_name, const std::string &extra_value, std::size_t offset=0, std::size_t extra_offset=0) const =0
Similar to sql_string_index(const std::string&, const std::string&, std::size_t, std::size_t) except ...
virtual std::vector< std::unique_ptr< Sql_string > > to_vector() const =0
void set_sql_string(std::size_t index, Types &&... args)
Definition: sql_vector.hpp:189
virtual ~Sql_vector()=default
The destructor.
static DMITIGR_PGFE_API std::unique_ptr< Sql_string > APIENTRY make(const std::string &input)
Constructs the new sql string.
virtual std::string to_string() const =0
virtual std::optional< std::size_t > sql_string_index(const std::string &extra_name, const std::string &extra_value, std::size_t offset=0, std::size_t extra_offset=0) const =0
virtual void set_sql_string(std::size_t index, std::unique_ptr< Sql_string > &&sql_string)=0
Sets the SQL string at the given index.
Represents a vector of SQL strings and useful operations on it.
Definition: sql_vector.hpp:27
virtual void append_sql_string(std::unique_ptr< Sql_string > &&sql_string)=0
Appends the SQL string to this vector.
virtual Sql_string * sql_string(std::size_t index)=0
void append_sql_string(Types &&... args)
Definition: sql_vector.hpp:208