libpqxx
basic_connection.hxx
1 
13 #ifndef PQXX_H_BASIC_CONNECTION
14 #define PQXX_H_BASIC_CONNECTION
15 
16 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/compiler-internal-pre.hxx"
18 
19 #include <cstddef>
20 #include <memory>
21 #include <string>
22 
23 #include "pqxx/connection_base.hxx"
24 
25 
26 namespace pqxx
27 {
28 
30 
45 template<typename CONNECTPOLICY> class basic_connection_base :
46  public connection_base
47 {
48 public:
50  connection_base(m_policy),
51  m_options(std::string{}),
52  m_policy(m_options)
53  { init(); }
54 
57  explicit basic_connection_base(const std::string &opt) :
58  connection_base(m_policy),
59  m_options(opt),
60  m_policy(m_options)
61  {init();}
62 
64  explicit basic_connection_base(const char opt[]) :
65  basic_connection_base(opt ? std::string{opt} : std::string{}) {}
66 
67  explicit basic_connection_base(std::nullptr_t) : basic_connection_base() {}
68 
70  { close(); }
71 
72  const std::string &options() const noexcept //[t01]
73  {return m_policy.options();}
74 
75 private:
77  std::string m_options;
79  CONNECTPOLICY m_policy;
80 };
81 
82 
84 
88 template<typename CONNECTPOLICY> struct basic_connection :
89  basic_connection_base<CONNECTPOLICY>
90 {
91  PQXX_DEPRECATED basic_connection() =default;
92  PQXX_DEPRECATED explicit basic_connection(const std::string &opt) :
93  basic_connection(opt) {}
94  PQXX_DEPRECATED explicit basic_connection(const char opt[]) :
95  basic_connection(opt) {}
96 
97  PQXX_DEPRECATED explicit basic_connection(std::nullptr_t) :
98  basic_connection() {}
99 
101 };
102 
103 } // namespace
104 
105 #include "pqxx/compiler-internal-post.hxx"
106 
107 #endif
void init()
Definition: connection_base.cxx:93
Concrete connection type template.
Definition: basic_connection.hxx:88
const std::string & options() const noexcept
Definition: basic_connection.hxx:72
~basic_connection_base() noexcept
Definition: basic_connection.hxx:69
STL namespace.
Base-class template for all libpqxx connection types.
Definition: basic_connection.hxx:45
connection_base abstract base class; represents a connection to a database.
Definition: connection_base.hxx:139
basic_connection_base(const std::string &opt)
Definition: basic_connection.hxx:57
basic_connection(const char opt[])
Definition: basic_connection.hxx:94
basic_connection_base()
Definition: basic_connection.hxx:49
basic_connection(std::nullptr_t)
Definition: basic_connection.hxx:97
void close() noexcept
Definition: connection_base.cxx:866
basic_connection_base(std::nullptr_t)
Definition: basic_connection.hxx:67
basic_connection_base(const char opt[])
See: basic_connection(const std::string &opt)
Definition: basic_connection.hxx:64
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
basic_connection(const std::string &opt)
Definition: basic_connection.hxx:92