diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-09 18:14:37 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-09 18:14:37 +0200 |
commit | 2bf2944a844d002267d3508ce81a2128ccbb8af7 (patch) | |
tree | 32732629cdd48b789242e6a8dc1673c593f6fb8f /odb/sqlite/connection.hxx | |
parent | 857fabab0c537a286e8a39503bf987029669d854 (diff) |
Make database class move-constructible
This means it can be returned by value from a function in C++11.
Diffstat (limited to 'odb/sqlite/connection.hxx')
-rw-r--r-- | odb/sqlite/connection.hxx | 42 |
1 files changed, 31 insertions, 11 deletions
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> 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<sqlite3> 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_; + }; } } |