From 3bf99419d41768c889c0ce04841815e8880d3f97 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 --- libcommon/common/common.cxx | 69 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) (limited to 'libcommon') diff --git a/libcommon/common/common.cxx b/libcommon/common/common.cxx index 29e3eed..10c8ba2 100644 --- a/libcommon/common/common.cxx +++ b/libcommon/common/common.cxx @@ -3,6 +3,7 @@ // license : GNU GPL v2; see accompanying LICENSE file #include // std::exit +#include // std::move #include #include @@ -79,21 +80,44 @@ create_database (int& argc, auto_ptr db; #if defined(DATABASE_MYSQL) + +#ifdef HAVE_CXX11 + unique_ptr f; +#else auto_ptr f; +#endif if (max_connections != 0) f.reset (new mysql::connection_pool_factory (max_connections)); - db.reset (new mysql::database (argc, argv, false, "", 0, f)); + db.reset (new mysql::database (argc, argv, false, "", 0, +#ifdef HAVE_CXX11 + move (f) +#else + f +#endif + )); + #elif defined(DATABASE_SQLITE) + +#ifdef HAVE_CXX11 + unique_ptr f; +#else auto_ptr f; +#endif if (max_connections != 0) f.reset (new sqlite::connection_pool_factory (max_connections)); db.reset ( new sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, true, f)); + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, true, +#ifdef HAVE_CXX11 + move (f) +#else + f +#endif + )); // Create the database schema. Due to bugs in SQLite foreign key // support for DDL statements, we need to temporarily disable @@ -111,15 +135,33 @@ create_database (int& argc, c->execute ("PRAGMA foreign_keys=ON"); } + #elif defined(DATABASE_PGSQL) + +#ifdef HAVE_CXX11 + unique_ptr f; +#else auto_ptr f; +#endif if (max_connections != 0) f.reset (new pgsql::connection_pool_factory (max_connections)); - db.reset (new pgsql::database (argc, argv, false, "", f)); + db.reset (new pgsql::database (argc, argv, false, "", +#ifdef HAVE_CXX11 + move (f) +#else + f +#endif + )); + #elif defined(DATABASE_ORACLE) + +#ifdef HAVE_CXX11 + unique_ptr f; +#else auto_ptr f; +#endif if (max_connections != 0) f.reset (new oracle::connection_pool_factory (max_connections)); @@ -127,15 +169,32 @@ create_database (int& argc, // Set client database character set and client national character set // to UTF-8. // - db.reset (new oracle::database (argc, argv, false, 873, 873, 0, f)); + db.reset (new oracle::database (argc, argv, false, 873, 873, 0, +#ifdef HAVE_CXX11 + move (f) +#else + f +#endif + )); #elif defined(DATABASE_MSSQL) + +#ifdef HAVE_CXX11 + unique_ptr f; +#else auto_ptr f; +#endif if (max_connections != 0) f.reset (new mssql::connection_pool_factory (max_connections)); - db.reset (new mssql::database (argc, argv, false, "", 0, f)); + db.reset (new mssql::database (argc, argv, false, "", 0, +#ifdef HAVE_CXX11 + move (f) +#else + f +#endif + )); #endif return db; -- cgit v1.1