libpqxx 4.0
basic_connection.hxx
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/basic_connection.hxx
00005  *
00006  *   DESCRIPTION
00007  *      definition of the pqxx::basic_connection class template
00008  *   Instantiations of basic_connection bring connections and policies together
00009  *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/basic_connection instead.
00010  *
00011  * Copyright (c) 2006-2011, Jeroen T. Vermeulen <jtv@xs4all.nl>
00012  *
00013  * See COPYING for copyright license.  If you did not receive a file called
00014  * COPYING with this source code, please notify the distributor of this mistake,
00015  * or contact the author.
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 #ifndef PQXX_H_BASIC_CONNECTION
00020 #define PQXX_H_BASIC_CONNECTION
00021 
00022 #include "pqxx/compiler-public.hxx"
00023 #include "pqxx/compiler-internal-pre.hxx"
00024 
00025 #include <memory>
00026 #include <string>
00027 
00028 #include "pqxx/connection_base"
00029 
00030 #ifdef PQXX_QUIET_DESTRUCTORS
00031 #include "pqxx/errorhandler"
00032 #endif
00033 
00034 
00035 namespace pqxx
00036 {
00037 
00038 // TODO: Also mix in thread synchronization policy here!
00040 
00054 template<typename CONNECTPOLICY> class basic_connection :
00055   public connection_base
00056 {
00057 public:
00058   basic_connection() :
00059     connection_base(m_policy),
00060     m_options(PGSTD::string()),
00061     m_policy(m_options)
00062         { init(); }
00063 
00064   explicit basic_connection(const PGSTD::string &opt) :
00065     connection_base(m_policy), m_options(opt), m_policy(m_options) {init();}
00066 
00067   explicit basic_connection(const char opt[]) :
00068     connection_base(m_policy),
00069     m_options(opt?opt:PGSTD::string()),
00070     m_policy(m_options)
00071         { init(); }
00072 
00073   ~basic_connection() throw ()
00074   {
00075 #ifdef PQXX_QUIET_DESTRUCTORS
00076     quiet_errorhandler quiet(*this);
00077 #endif
00078     close();
00079   }
00080 
00081   const PGSTD::string &options() const throw ()                         //[t1]
00082         {return m_policy.options();}
00083 
00084 private:
00086   PGSTD::string m_options;
00088   CONNECTPOLICY m_policy;
00089 };
00090 
00091 } // namespace
00092 
00093 #include "pqxx/compiler-internal-post.hxx"
00094 
00095 #endif