diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-01 11:56:33 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-01 11:56:33 +0200 |
commit | bb2358220adfe274b54d9b155205b60ddfe625c6 (patch) | |
tree | f8822c33ff25a0a9058ce92ce3a8716343a399f0 /odb/schema-catalog.cxx | |
parent | 1233c11bf05cc3a039afa548faf06f3610f24269 (diff) |
Add support for embedded database schemas
New options: --schema-format, --default-schema. New example: schema/embedded.
Diffstat (limited to 'odb/schema-catalog.cxx')
-rw-r--r-- | odb/schema-catalog.cxx | 67 |
1 files changed, 67 insertions, 0 deletions
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 <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include <map> +#include <vector> + +#include <odb/exceptions.hxx> +#include <odb/schema-catalog.hxx> +#include <odb/schema-catalog-impl.hxx> + +using namespace std; + +namespace odb +{ + typedef void (*create_function) (database&); + typedef vector<create_function> create_functions; + struct schema_catalog_impl: map<string, create_functions> {}; + + 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); + } +} |