aboutsummaryrefslogtreecommitdiff
path: root/odb/database.cxx
diff options
context:
space:
mode:
authorMichael Shepanski <michael@codesynthesis.com>2014-10-30 15:21:32 +1100
committerMichael Shepanski <michael@codesynthesis.com>2014-10-31 08:39:49 +1100
commit1f217e38f7507758da1d33d46e675e801621aa38 (patch)
treebad382ee315a820ec08bd2a83eaece12ac8169e3 /odb/database.cxx
parent31af5a488f2be9f4059e159492d4fe62f25a895a (diff)
Allow lambdas & std::functions as query factories with C++-98 builds of libodb
Diffstat (limited to 'odb/database.cxx')
-rw-r--r--odb/database.cxx32
1 files changed, 32 insertions, 0 deletions
diff --git a/odb/database.cxx b/odb/database.cxx
index 5578abd..0279acd 100644
--- a/odb/database.cxx
+++ b/odb/database.cxx
@@ -49,4 +49,36 @@ namespace odb
schema_version_seq_++;
}
}
+
+ bool database::
+ call_query_factory (const char* name, connection_type& c) const
+ {
+ query_factory_map::const_iterator i (query_factory_map_.find (name));
+
+ if (i == query_factory_map_.end ())
+ i = query_factory_map_.find (""); // Wildcard factory.
+
+ if (i == query_factory_map_.end ())
+ return false;
+
+ const query_factory_wrapper& fw (i->second);
+ if (fw.std_function == 0)
+ fw.function (name, c);
+ else
+ {
+ typedef void (*caller) (const void*, const char*, connection_type&);
+ reinterpret_cast<caller> (fw.function) (fw.std_function, name, c);
+ }
+
+ return true;
+ }
+
+ void database::
+ query_factory (const char* name, query_factory_wrapper w)
+ {
+ if (w)
+ query_factory_map_[name] = w; // Destructive copy assignment (move).
+ else
+ query_factory_map_.erase (name);
+ }
}