From 7c2b5d2cb3eb6df8a8d45c509794ff177f6d4523 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 1 Mar 2012 12:34:41 +0200 Subject: Add support for using C++11 std::unique_ptr to pass connection factory --- odb/mysql/database.cxx | 26 ++++++++++++++------------ odb/mysql/database.hxx | 34 ++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/odb/mysql/database.cxx b/odb/mysql/database.cxx index 8fb8597..03401d9 100644 --- a/odb/mysql/database.cxx +++ b/odb/mysql/database.cxx @@ -17,6 +17,8 @@ namespace odb { namespace mysql { + using odb::details::transfer_ptr; + database:: ~database () { @@ -31,7 +33,7 @@ namespace odb const char* socket, const char* charset, unsigned long client_flags, - auto_ptr factory) + transfer_ptr factory) : user_ (user ? user : ""), passwd_str_ (passwd ? passwd : ""), passwd_ (passwd ? passwd_str_.c_str () : 0), @@ -42,7 +44,7 @@ namespace odb socket_ (socket ? socket_str_.c_str () : 0), charset_ (charset == 0 ? "" : charset), client_flags_ (client_flags), - factory_ (factory) + factory_ (factory.transfer ()) { if (factory_.get () == 0) factory_.reset (new connection_pool_factory ()); @@ -59,7 +61,7 @@ namespace odb const string* socket, const string& charset, unsigned long client_flags, - auto_ptr factory) + transfer_ptr factory) : user_ (user), passwd_str_ (passwd), passwd_ (passwd_str_.c_str ()), @@ -70,7 +72,7 @@ namespace odb socket_ (socket ? socket_str_.c_str () : 0), charset_ (charset), client_flags_ (client_flags), - factory_ (factory) + factory_ (factory.transfer ()) { if (factory_.get () == 0) factory_.reset (new connection_pool_factory ()); @@ -87,7 +89,7 @@ namespace odb const string* socket, const string& charset, unsigned long client_flags, - auto_ptr factory) + transfer_ptr factory) : user_ (user), passwd_str_ (passwd ? *passwd : ""), passwd_ (passwd ? passwd_str_.c_str () : 0), @@ -98,7 +100,7 @@ namespace odb socket_ (socket ? socket_str_.c_str () : 0), charset_ (charset), client_flags_ (client_flags), - factory_ (factory) + factory_ (factory.transfer ()) { if (factory_.get () == 0) factory_.reset (new connection_pool_factory ()); @@ -115,7 +117,7 @@ namespace odb const string& socket, const string& charset, unsigned long client_flags, - auto_ptr factory) + transfer_ptr factory) : user_ (user), passwd_str_ (passwd), passwd_ (passwd_str_.c_str ()), @@ -126,7 +128,7 @@ namespace odb socket_ (socket_str_.c_str ()), charset_ (charset), client_flags_ (client_flags), - factory_ (factory) + factory_ (factory.transfer ()) { if (factory_.get () == 0) factory_.reset (new connection_pool_factory ()); @@ -143,7 +145,7 @@ namespace odb const string& socket, const string& charset, unsigned long client_flags, - auto_ptr factory) + transfer_ptr factory) : user_ (user), passwd_str_ (passwd ? *passwd : ""), passwd_ (passwd ? passwd_str_.c_str () : 0), @@ -154,7 +156,7 @@ namespace odb socket_ (socket_str_.c_str ()), charset_ (charset), client_flags_ (client_flags), - factory_ (factory) + factory_ (factory.transfer ()) { if (factory_.get () == 0) factory_.reset (new connection_pool_factory ()); @@ -168,12 +170,12 @@ namespace odb bool erase, const string& charset, unsigned long client_flags, - auto_ptr factory) + transfer_ptr factory) : passwd_ (0), socket_ (0), charset_ (charset), client_flags_ (client_flags), - factory_ (factory) + factory_ (factory.transfer ()) { using namespace details; diff --git a/odb/mysql/database.hxx b/odb/mysql/database.hxx index f495820..0f729eb 100644 --- a/odb/mysql/database.hxx +++ b/odb/mysql/database.hxx @@ -8,10 +8,12 @@ #include #include -#include // std::auto_ptr +#include // std::auto_ptr, std::unique_ptr #include // std::ostream #include +#include // ODB_CXX11 +#include #include #include @@ -42,8 +44,8 @@ namespace odb const char* socket = 0, const char* charset = 0, unsigned long client_flags = 0, - std::auto_ptr = - std::auto_ptr (0)); + details::transfer_ptr = + details::transfer_ptr ()); database (const std::string& user, const std::string& passwd, @@ -53,8 +55,8 @@ namespace odb const std::string* socket = 0, const std::string& charset = "", unsigned long client_flags = 0, - std::auto_ptr = - std::auto_ptr (0)); + details::transfer_ptr = + details::transfer_ptr ()); database (const std::string& user, const std::string* passwd, @@ -64,8 +66,8 @@ namespace odb const std::string* socket = 0, const std::string& charset = "", unsigned long client_flags = 0, - std::auto_ptr = - std::auto_ptr (0)); + details::transfer_ptr = + details::transfer_ptr ()); database (const std::string& user, const std::string& passwd, @@ -75,8 +77,8 @@ namespace odb const std::string& socket, const std::string& charset = "", unsigned long client_flags = 0, - std::auto_ptr = - std::auto_ptr (0)); + details::transfer_ptr = + details::transfer_ptr ()); database (const std::string& user, const std::string* passwd, @@ -86,8 +88,8 @@ namespace odb const std::string& socket, const std::string& charset = "", unsigned long client_flags = 0, - std::auto_ptr = - std::auto_ptr (0)); + details::transfer_ptr = + details::transfer_ptr ()); // Extract the database parameters from the command line. The // following options are recognized: @@ -110,13 +112,12 @@ namespace odb bool erase = false, const std::string& charset = "", unsigned long client_flags = 0, - std::auto_ptr = - std::auto_ptr (0)); + details::transfer_ptr = + details::transfer_ptr ()); static void print_usage (std::ostream&); - public: const char* user () const @@ -212,7 +213,12 @@ namespace odb const char* socket_; std::string charset_; unsigned long client_flags_; + +#ifdef ODB_CXX11 + std::unique_ptr factory_; +#else std::auto_ptr factory_; +#endif }; } } -- cgit v1.1