diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-03-01 12:34:41 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-03-01 12:34:41 +0200 |
commit | 2ee97761e5c375e373dbc9b5f96391b22bb3704e (patch) | |
tree | a247d998301a56cc066e34d9107a838ebaa6b275 | |
parent | 5adb99be4d837b439872a94be2f2a36129762585 (diff) |
Add support for using C++11 std::unique_ptr to pass connection factory
-rw-r--r-- | odb/pgsql/database.cxx | 19 | ||||
-rw-r--r-- | odb/pgsql/database.hxx | 25 |
2 files changed, 26 insertions, 18 deletions
diff --git a/odb/pgsql/database.cxx b/odb/pgsql/database.cxx index 445af44..6a65780 100644 --- a/odb/pgsql/database.cxx +++ b/odb/pgsql/database.cxx @@ -17,6 +17,8 @@ namespace odb { namespace pgsql { + using odb::details::transfer_ptr; + database:: database (const string& user, const string& password, @@ -24,14 +26,14 @@ namespace odb const string& host, unsigned int port, const string& extra_conninfo, - auto_ptr<connection_factory> factory) + transfer_ptr<connection_factory> factory) : user_ (user), password_ (password), db_ (db), host_ (host), port_ (port), extra_conninfo_ (extra_conninfo), - factory_ (factory) + factory_ (factory.transfer ()) { ostringstream ss; @@ -71,7 +73,7 @@ namespace odb const string& host, const string& socket_ext, const string& extra_conninfo, - auto_ptr<connection_factory> factory) + transfer_ptr<connection_factory> factory) : user_ (user), password_ (password), db_ (db), @@ -79,7 +81,7 @@ namespace odb port_ (0), socket_ext_ (socket_ext), extra_conninfo_ (extra_conninfo), - factory_ (factory) + factory_ (factory.transfer ()) { ostringstream ss; @@ -113,9 +115,8 @@ namespace odb } database:: - database (const string& conninfo, - auto_ptr<connection_factory> factory) - : port_ (0), conninfo_ (conninfo), factory_ (factory) + database (const string& conninfo, transfer_ptr<connection_factory> factory) + : port_ (0), conninfo_ (conninfo), factory_ (factory.transfer ()) { if (factory_.get () == 0) factory_.reset (new connection_pool_factory ()); @@ -128,8 +129,8 @@ namespace odb char* argv[], bool erase, const string& extra_conninfo, - auto_ptr<connection_factory> factory) - : port_ (0), factory_ (factory) + transfer_ptr<connection_factory> factory) + : port_ (0), factory_ (factory.transfer ()) { using namespace details; diff --git a/odb/pgsql/database.hxx b/odb/pgsql/database.hxx index 89984b3..c3b42f2 100644 --- a/odb/pgsql/database.hxx +++ b/odb/pgsql/database.hxx @@ -8,10 +8,12 @@ #include <odb/pre.hxx> #include <string> -#include <memory> // std::auto_ptr +#include <memory> // std::auto_ptr, std::unique_ptr #include <iosfwd> // std::ostream #include <odb/database.hxx> +#include <odb/details/config.hxx> // ODB_CXX11 +#include <odb/details/transfer-ptr.hxx> #include <odb/pgsql/version.hxx> #include <odb/pgsql/forward.hxx> @@ -36,8 +38,8 @@ namespace odb const std::string& host = "", unsigned int port = 0, const std::string& extra_conninfo = "", - std::auto_ptr<connection_factory> factory = - std::auto_ptr<connection_factory> (0)); + details::transfer_ptr<connection_factory> = + details::transfer_ptr<connection_factory> ()); database (const std::string& user, const std::string& password, @@ -45,13 +47,13 @@ namespace odb const std::string& host = "", const std::string& socket_ext = "", const std::string& extra_conninfo = "", - std::auto_ptr<connection_factory> factory = - std::auto_ptr<connection_factory> (0)); + details::transfer_ptr<connection_factory> = + details::transfer_ptr<connection_factory> ()); explicit database (const std::string& conninfo, - std::auto_ptr<connection_factory> = - std::auto_ptr<connection_factory> (0)); + details::transfer_ptr<connection_factory> = + details::transfer_ptr<connection_factory> ()); // Extract the database parameters from the command line. The // following options are recognized: @@ -72,8 +74,8 @@ namespace odb char* argv[], bool erase = false, const std::string& extra_conninfo = "", - std::auto_ptr<connection_factory> = - std::auto_ptr<connection_factory> (0)); + details::transfer_ptr<connection_factory> = + details::transfer_ptr<connection_factory> ()); static void print_usage (std::ostream&); @@ -173,7 +175,12 @@ namespace odb std::string socket_ext_; std::string extra_conninfo_; std::string conninfo_; + +#ifdef ODB_CXX11 + std::unique_ptr<connection_factory> factory_; +#else std::auto_ptr<connection_factory> factory_; +#endif }; } } |