From 1f217e38f7507758da1d33d46e675e801621aa38 Mon Sep 17 00:00:00 2001 From: Michael Shepanski Date: Thu, 30 Oct 2014 15:21:32 +1100 Subject: Allow lambdas & std::functions as query factories with C++-98 builds of libodb --- odb/database.hxx | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'odb/database.hxx') diff --git a/odb/database.hxx b/odb/database.hxx index 91d8e94..4e59aaf 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -15,7 +15,9 @@ #include // std::size_t #ifdef ODB_CXX11 -# include // std::function +# include // std::move +# include // std::function +# include // std::enable_if, std::is_convertible #endif #include @@ -30,6 +32,7 @@ #include #include #include +#include namespace odb { @@ -44,7 +47,6 @@ namespace odb // Object persistence API. // public: - // Make the object persistent. // template @@ -281,19 +283,31 @@ namespace odb public: typedef odb::connection connection_type; -#ifdef ODB_CXX11 - typedef - std::function - query_factory_type; + typedef void query_factory_type (const char* name, connection_type&); + typedef query_factory_type* query_factory_ptr; + typedef details::function_wrapper< + query_factory_type> query_factory_wrapper; + +#ifndef ODB_CXX11 + void + query_factory (const char* name, query_factory_ptr); #else - typedef void (*query_factory_type) (const char*, connection_type&); + template + typename std::enable_if< + std::is_convertible< + F, std::function>::value, void>::type + query_factory (const char* name, F f) + { + query_factory (name, query_factory_wrapper (std::move (f))); + } #endif - void - query_factory (const char* name, query_factory_type); + bool + call_query_factory (const char* name, connection_type&) const; - query_factory_type - lookup_query_factory (const char* name) const; + private: + void + query_factory (const char* name, query_factory_wrapper); // Native database statement execution. // @@ -480,7 +494,7 @@ namespace odb protected: typedef - std::map + std::map query_factory_map; typedef std::map schema_version_map; -- cgit v1.1