From 2bf2944a844d002267d3508ce81a2128ccbb8af7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 9 Nov 2015 18:14:37 +0200 Subject: Make database class move-constructible This means it can be returned by value from a function in C++11. --- odb/sqlite/connection.hxx | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'odb/sqlite/connection.hxx') diff --git a/odb/sqlite/connection.hxx b/odb/sqlite/connection.hxx index 7499eb9..5110163 100644 --- a/odb/sqlite/connection.hxx +++ b/odb/sqlite/connection.hxx @@ -30,6 +30,7 @@ namespace odb namespace sqlite { class statement_cache; + class connection_factory; class connection; typedef details::shared_ptr connection_ptr; @@ -76,14 +77,11 @@ namespace odb virtual ~connection (); - connection (database_type&, int extra_flags = 0); - connection (database_type&, sqlite3* handle); + connection (connection_factory&, int extra_flags = 0); + connection (connection_factory&, sqlite3* handle); database_type& - database () - { - return db_; - } + database (); public: virtual transaction_impl* @@ -173,11 +171,6 @@ namespace odb init (); private: - // Needed to break the circular connection-database dependency - // (odb::connection has the odb::database member). - // - database_type& db_; - auto_handle handle_; // Keep statement_cache_ after handle_ so that it is destroyed before @@ -205,6 +198,33 @@ namespace odb friend class active_object; active_object* active_objects_; }; + + class LIBODB_SQLITE_EXPORT connection_factory: + public odb::connection_factory + { + public: + typedef sqlite::database database_type; + + virtual void + database (database_type&); + + database_type& + database () {return *db_;} + + virtual connection_ptr + connect () = 0; + + virtual + ~connection_factory (); + + connection_factory (): db_ (0) {} + + // Needed to break the circular connection_factory-database dependency + // (odb::connection_factory has the odb::database member). + // + protected: + database_type* db_; + }; } } -- cgit v1.1