From bb2358220adfe274b54d9b155205b60ddfe625c6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 1 Mar 2011 11:56:33 +0200 Subject: Add support for embedded database schemas New options: --schema-format, --default-schema. New example: schema/embedded. --- odb/schema-catalog.cxx | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 odb/schema-catalog.cxx (limited to 'odb/schema-catalog.cxx') diff --git a/odb/schema-catalog.cxx b/odb/schema-catalog.cxx new file mode 100644 index 0000000..5332cce --- /dev/null +++ b/odb/schema-catalog.cxx @@ -0,0 +1,67 @@ +// file : odb/schema-catalog.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include + +#include +#include +#include + +using namespace std; + +namespace odb +{ + typedef void (*create_function) (database&); + typedef vector create_functions; + struct schema_catalog_impl: map {}; + + schema_catalog_impl* schema_catalog_init::catalog = 0; + size_t schema_catalog_init::count = 0; + + void schema_catalog:: + create_schema (database& db, const string& name) + { + const schema_catalog_impl& c (*schema_catalog_init::catalog); + + schema_catalog_impl::const_iterator i (c.find (name)); + + if (i == c.end ()) + throw unknown_schema (name); + + const create_functions& fs (i->second); + + for (create_functions::const_iterator j (fs.begin ()), e (fs.end ()); + j != e; ++j) + (*j) (db); + } + + // schema_catalog_init + // + schema_catalog_init:: + schema_catalog_init () + { + if (count == 0) + catalog = new schema_catalog_impl; + + ++count; + } + + schema_catalog_init:: + ~schema_catalog_init () + { + if (--count == 0) + delete catalog; + } + + // schema_catalog_entry + // + schema_catalog_entry:: + schema_catalog_entry (const char* name, create_function entry) + { + schema_catalog_impl& c (*schema_catalog_init::catalog); + c[name].push_back (entry); + } +} -- cgit v1.1