libpqxx  5.0
basic_connection.hxx
1 /*-------------------------------------------------------------------------
2  *
3  * FILE
4  * pqxx/basic_connection.hxx
5  *
6  * DESCRIPTION
7  * definition of the pqxx::basic_connection class template
8  * Instantiations of basic_connection bring connections and policies together
9  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/basic_connection instead.
10  *
11  * Copyright (c) 2006-2015, Jeroen T. Vermeulen <jtv@xs4all.nl>
12  *
13  * See COPYING for copyright license. If you did not receive a file called
14  * COPYING with this source code, please notify the distributor of this mistake,
15  * or contact the author.
16  *
17  *-------------------------------------------------------------------------
18  */
19 #ifndef PQXX_H_BASIC_CONNECTION
20 #define PQXX_H_BASIC_CONNECTION
21 
22 #include "pqxx/compiler-public.hxx"
23 #include "pqxx/compiler-internal-pre.hxx"
24 
25 #include <memory>
26 #include <string>
27 
28 #include "pqxx/connection_base"
29 
30 
31 namespace pqxx
32 {
33 
34 // TODO: Also mix in thread synchronization policy here!
36 
50 template<typename CONNECTPOLICY> class basic_connection :
51  public connection_base
52 {
53 public:
55  connection_base(m_policy),
56  m_options(std::string()),
57  m_policy(m_options)
58  { init(); }
59 
60  explicit basic_connection(const std::string &opt) :
61  connection_base(m_policy), m_options(opt), m_policy(m_options) {init();}
62 
63  explicit basic_connection(const char opt[]) :
64  connection_base(m_policy),
65  m_options(opt?opt:std::string()),
66  m_policy(m_options)
67  { init(); }
68 
69  ~basic_connection() PQXX_NOEXCEPT { close(); }
70 
71  const std::string &options() const PQXX_NOEXCEPT //[t1]
72  {return m_policy.options();}
73 
74 private:
76  std::string m_options;
78  CONNECTPOLICY m_policy;
79 };
80 
81 } // namespace
82 
83 #include "pqxx/compiler-internal-post.hxx"
84 
85 #endif
connection_base abstract base class; represents a connection to a database.
Definition: connection_base.hxx:149
The ultimate template that defines a connection type.
Definition: basic_connection.hxx:50
const std::string & options() const PQXX_NOEXCEPT
Definition: basic_connection.hxx:71
basic_connection(const std::string &opt)
Definition: basic_connection.hxx:60
basic_connection()
Definition: basic_connection.hxx:54
void close() PQXX_NOEXCEPT
Definition: connection_base.cxx:883
basic_connection(const char opt[])
Definition: basic_connection.hxx:63
~basic_connection() PQXX_NOEXCEPT
Definition: basic_connection.hxx:69
void init()
Definition: connection_base.cxx:142