libpqxx  4.0.1
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-2011, 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 #ifdef PQXX_QUIET_DESTRUCTORS
31 #include "pqxx/errorhandler"
32 #endif
33 
34 
35 namespace pqxx
36 {
37 
38 // TODO: Also mix in thread synchronization policy here!
40 
54 template<typename CONNECTPOLICY> class basic_connection :
55  public connection_base
56 {
57 public:
59  connection_base(m_policy),
60  m_options(PGSTD::string()),
61  m_policy(m_options)
62  { init(); }
63 
64  explicit basic_connection(const PGSTD::string &opt) :
65  connection_base(m_policy), m_options(opt), m_policy(m_options) {init();}
66 
67  explicit basic_connection(const char opt[]) :
68  connection_base(m_policy),
69  m_options(opt?opt:PGSTD::string()),
70  m_policy(m_options)
71  { init(); }
72 
73  ~basic_connection() throw ()
74  {
75 #ifdef PQXX_QUIET_DESTRUCTORS
76  quiet_errorhandler quiet(*this);
77 #endif
78  close();
79  }
80 
81  const PGSTD::string &options() const throw () //[t1]
82  {return m_policy.options();}
83 
84 private:
86  PGSTD::string m_options;
88  CONNECTPOLICY m_policy;
89 };
90 
91 } // namespace
92 
93 #include "pqxx/compiler-internal-post.hxx"
94 
95 #endif