aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-01 12:34:41 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-01 12:34:41 +0200
commit7c2b5d2cb3eb6df8a8d45c509794ff177f6d4523 (patch)
treeabd3e4fb575f93cf0586367dc05b02adbbd15616
parentc073adb85f1f28c0f052530ff58f3ff27d5c5141 (diff)
Add support for using C++11 std::unique_ptr to pass connection factory
-rw-r--r--odb/mysql/database.cxx26
-rw-r--r--odb/mysql/database.hxx34
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<connection_factory> factory)
+ transfer_ptr<connection_factory> 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<connection_factory> factory)
+ transfer_ptr<connection_factory> 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<connection_factory> factory)
+ transfer_ptr<connection_factory> 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<connection_factory> factory)
+ transfer_ptr<connection_factory> 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<connection_factory> factory)
+ transfer_ptr<connection_factory> 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<connection_factory> factory)
+ transfer_ptr<connection_factory> 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 <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/mysql/mysql.hxx>
#include <odb/mysql/version.hxx>
@@ -42,8 +44,8 @@ namespace odb
const char* socket = 0,
const char* charset = 0,
unsigned long client_flags = 0,
- std::auto_ptr<connection_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& passwd,
@@ -53,8 +55,8 @@ namespace odb
const std::string* socket = 0,
const std::string& charset = "",
unsigned long client_flags = 0,
- std::auto_ptr<connection_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* passwd,
@@ -64,8 +66,8 @@ namespace odb
const std::string* socket = 0,
const std::string& charset = "",
unsigned long client_flags = 0,
- std::auto_ptr<connection_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& passwd,
@@ -75,8 +77,8 @@ namespace odb
const std::string& socket,
const std::string& charset = "",
unsigned long client_flags = 0,
- std::auto_ptr<connection_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* passwd,
@@ -86,8 +88,8 @@ namespace odb
const std::string& socket,
const std::string& charset = "",
unsigned long client_flags = 0,
- 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:
@@ -110,13 +112,12 @@ namespace odb
bool erase = false,
const std::string& charset = "",
unsigned long client_flags = 0,
- 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&);
-
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<connection_factory> factory_;
+#else
std::auto_ptr<connection_factory> factory_;
+#endif
};
}
}