diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-03-05 11:59:00 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-03-05 11:59:00 +0200 |
commit | cd44a367fd73293b1c8edc36aa61667ca020a2eb (patch) | |
tree | 1e4ce550a525e23fb7c8c29f18ddda31b61bf066 /odb/relational/schema-source.hxx | |
parent | 2528431334b0c8aa07c85ec798be5fc9eb5b2add (diff) |
Add support for generating schema creation code into separate C++ file
Diffstat (limited to 'odb/relational/schema-source.hxx')
-rw-r--r-- | odb/relational/schema-source.hxx | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/odb/relational/schema-source.hxx b/odb/relational/schema-source.hxx new file mode 100644 index 0000000..a72b55b --- /dev/null +++ b/odb/relational/schema-source.hxx @@ -0,0 +1,68 @@ +// file : odb/relational/schema-source.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v3; see accompanying LICENSE file + +#ifndef ODB_RELATIONAL_SCHEMA_SOURCE_HXX +#define ODB_RELATIONAL_SCHEMA_SOURCE_HXX + +#include <odb/diagnostics.hxx> + +#include <odb/relational/context.hxx> +#include <odb/relational/schema.hxx> + +namespace relational +{ + namespace schema_source + { + struct class_: traversal::class_, virtual context + { + typedef class_ base; + + virtual void + traverse (type& c) + { + if (class_file (c) != unit.file () || !object (c) || abstract (c)) + return; + + context::top_object = context::cur_object = &c; + + os << "// " << class_name (c) << endl + << "//" << endl + << endl; + + schema_->traverse (c); + + context::top_object = context::cur_object = 0; + } + + private: + instance<schema::cxx_object> schema_; + }; + + struct include: virtual context + { + typedef include base; + + virtual void + generate () + { + extra_pre (); + os << "#include <odb/schema-catalog-impl.hxx>" << endl; + extra_post (); + os << endl; + } + + virtual void + extra_pre () + { + } + + virtual void + extra_post () + { + } + }; + } +} + +#endif // ODB_RELATIONAL_SCHEMA_SOURCE_HXX |