diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-09 10:03:32 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-10 18:46:45 +0200 |
commit | 5ebd62ec778bc8c9540e2379e764ac52c060adfc (patch) | |
tree | b751e62fe12599ee1a2553dc9331a03c8c957252 /odb/relational/schema.hxx | |
parent | 8295d4bd02946b7bdbff2a9cfa7763232e2d2fd0 (diff) |
Generate embedded schema in single function instead of one per object
Diffstat (limited to 'odb/relational/schema.hxx')
-rw-r--r-- | odb/relational/schema.hxx | 263 |
1 files changed, 0 insertions, 263 deletions
diff --git a/odb/relational/schema.hxx b/odb/relational/schema.hxx index 2cff998..1152175 100644 --- a/odb/relational/schema.hxx +++ b/odb/relational/schema.hxx @@ -1488,269 +1488,6 @@ namespace relational { } }; - - // - // C++ output. - // - - struct cxx_emitter: emitter, virtual context - { - typedef cxx_emitter base; - - void - pass (unsigned short p) - { - empty_ = true; - pass_ = p; - new_pass_ = true; - - if (pass_ == 1) - empty_passes_ = 0; // New set of passes. - - // Assume this pass is empty. - // - empty_passes_++; - } - - // Did this pass produce anything? - // - bool - empty () const - { - return empty_; - } - - virtual void - pre () - { - first_ = true; - } - - virtual void - line (const string& l) - { - if (l.empty ()) - return; // Ignore empty lines. - - if (first_) - { - first_ = false; - - // If this line starts a new pass, then output the switch/case - // blocks. - // - if (new_pass_) - { - new_pass_ = false; - empty_ = false; - empty_passes_--; // This pass is not empty. - - // Output case statements for empty preceeding passes, if any. - // - if (empty_passes_ != 0) - { - unsigned short s (pass_ - empty_passes_); - - if (s == 1) - os << "switch (pass)" - << "{"; - else - os << "return true;" // One more pass. - << "}"; - - for (; s != pass_; ++s) - os << "case " << s << ":" << endl; - - os << "{"; - empty_passes_ = 0; - } - - if (pass_ == 1) - os << "switch (pass)" - << "{"; - else - os << "return true;" // One more pass. - << "}"; - - os << "case " << pass_ << ":" << endl - << "{"; - } - - os << "db.execute ("; - } - else - os << strlit (line_ + '\n') << endl; - - line_ = l; - } - - virtual void - post () - { - if (!first_) // Ignore empty statements. - os << strlit (line_) << ");"; - } - - private: - std::string line_; - bool first_; - bool empty_; - bool new_pass_; - unsigned short pass_; - unsigned short empty_passes_; // Number of preceding empty passes. - }; - - struct cxx_object: virtual context - { - typedef cxx_object base; - - //@@ (im)-perfect forwarding. - // - static schema_format format_embedded; - - cxx_object () - : stream_ (*emitter_), - drop_model_ (*emitter_, stream_, format_embedded), - drop_table_ (*emitter_, stream_, format_embedded), - create_model_ (*emitter_, stream_, format_embedded), - create_table_ (*emitter_, stream_, format_embedded) - { - init (); - } - - cxx_object (cxx_object const&) - : root_context (), //@@ -Wextra - context (), - stream_ (*emitter_), - drop_model_ (*emitter_, stream_, format_embedded), - drop_table_ (*emitter_, stream_, format_embedded), - create_model_ (*emitter_, stream_, format_embedded), - create_table_ (*emitter_, stream_, format_embedded) - { - init (); - } - - void - init () - { - drop_model_ >> drop_names_; - drop_names_ >> drop_table_; - - create_model_ >> create_names_; - create_names_ >> create_table_; - } - - void - traverse (semantics::class_& c) - { - typedef sema_rel::model::names_iterator iterator; - - iterator begin (c.get<iterator> ("model-range-first")); - iterator end (c.get<iterator> ("model-range-last")); - - if (begin == model->names_end ()) - return; // This class doesn't have any model entities (e.g., - // a second class mapped to the same table). - - ++end; // Transform the range from [begin, end] to [begin, end). - - string const& type (class_fq_name (c)); - string traits ("access::object_traits_impl< " + type + ", id_" + - db.string () + " >"); - - // create_schema () - // - os << "bool " << traits << "::" << endl - << "create_schema (database& db, unsigned short pass, bool drop)" - << "{" - << "ODB_POTENTIALLY_UNUSED (db);" - << "ODB_POTENTIALLY_UNUSED (pass);" - << "ODB_POTENTIALLY_UNUSED (drop);" - << endl; - - // Drop. - // - if (!options.omit_drop ()) - { - bool close (false); - - os << "if (drop)" - << "{"; - - for (unsigned short pass (1); pass < 3; ++pass) - { - emitter_->pass (pass); - drop_model_->pass (pass); - drop_table_->pass (pass); - - drop_model_->traverse (begin, end); - - close = close || !emitter_->empty (); - } - - if (close) // Close the last case and the switch block. - os << "return false;" - << "}" // case - << "}"; // switch - - os << "}"; - } - - // Create. - // - if (!options.omit_create ()) - { - bool close (false); - - if (options.omit_drop ()) - os << "if (!drop)"; - else - os << "else"; - - os << "{"; - - for (unsigned short pass (1); pass < 3; ++pass) - { - emitter_->pass (pass); - create_model_->pass (pass); - create_table_->pass (pass); - - create_model_->traverse (begin, end); - - close = close || !emitter_->empty (); - } - - if (close) // Close the last case and the switch block. - os << "return false;" - << "}" // case - << "}"; // switch - - os << "}"; - } - - os << "return false;" - << "}"; - - os << "static const schema_catalog_entry" << endl - << "schema_catalog_entry_" << flat_name (type) << "_ (" << endl - << "id_" << db << "," << endl - << strlit (options.schema_name ()[db]) << "," << endl - << "&" << traits << "::create_schema);" - << endl; - } - - private: - instance<cxx_emitter> emitter_; - emitter_ostream stream_; - - trav_rel::qnames drop_names_; - instance<drop_model> drop_model_; - instance<drop_table> drop_table_; - - trav_rel::qnames create_names_; - instance<create_model> create_model_; - instance<create_table> create_table_; - }; } } |