From 51419aca9c4bcc056ee87d5aa26fe3076f4593ef Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Mar 2011 10:04:20 +0200 Subject: Move to new "virtual functions in context" model --- odb/context.cxx | 17 ++++++++++------- odb/context.hxx | 36 ++++++++++++++++++++++++------------ odb/relational/mysql/context.cxx | 12 ++++++------ odb/relational/mysql/context.hxx | 12 ++++++------ odb/type-processor.cxx | 10 +++++----- 5 files changed, 51 insertions(+), 36 deletions(-) diff --git a/odb/context.cxx b/odb/context.cxx index 944756a..b98a27d 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -269,12 +269,15 @@ column_type (semantics::data_member& m, string const& kp) : indirect_value (m, kp + "-column-type"); } -string context::data:: -column_type_impl (semantics::type& t, - string const& type, - semantics::context& ctx, - column_type_flags f) const +string context:: +database_type_impl (semantics::type& t, + string const& type, + semantics::context& ctx, + column_type_flags f) { + // @@ If I handle additional qualifiers (e.g., NOT NULL, AUTO_INCREMENT) + // separately, then I won't need to pass custom type anymore. + // if (!type.empty ()) return type; @@ -282,9 +285,9 @@ column_type_impl (semantics::type& t, // ::std::string) instead of a user typedef (e.g., my_string). // string const& name (t.fq_name ()); - type_map_type::const_iterator i (type_map_.find (name)); + type_map_type::const_iterator i (data_->type_map_.find (name)); - if (i != type_map_.end ()) + if (i != data_->type_map_.end ()) { string r (ctx.count ("id") ? i->second.id_type : i->second.type); diff --git a/odb/context.hxx b/odb/context.hxx index d8c457b..23eb457 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -361,6 +361,8 @@ public: typedef std::map type_map_type; + // Per-database customizable functionality. + // protected: typedef unsigned short column_type_flags; @@ -374,6 +376,28 @@ protected: // static column_type_flags const ctf_object_id_ref = 0x02; + // Return empty string if there is no mapping. The second argument + // is the custom type or empty string if it is not specified. + // + string + database_type (semantics::type& t, + string const& type, + semantics::context& c, + column_type_flags f) + { + return current ().database_type_impl (t, type, c, f); + } + + // The default implementation uses the type map (populated by the database- + // specific context implementation) to come up with a mapping. + // + virtual string + database_type_impl (semantics::type&, + string const& type, + semantics::context&, + column_type_flags); + +protected: struct data { virtual @@ -386,18 +410,6 @@ protected: semantics::class_* object_; - // Per-database customizable functionality. - // - public: - // Return empty string if there is no mapping. The second argument - // is the custom type or empty string if it is not specified. - // - virtual string - column_type_impl (semantics::type&, - string const& type, - semantics::context&, - column_type_flags) const; - keyword_set_type keyword_set_; type_map_type type_map_; }; diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index 014aa7d..3fc09d2 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -218,13 +218,13 @@ namespace relational // SQL type parsing. // - string context::data:: - column_type_impl (semantics::type& t, - string const& type, - semantics::context& ctx, - column_type_flags f) const + string context:: + database_type_impl (semantics::type& t, + string const& type, + semantics::context& ctx, + column_type_flags f) { - string r (::context::data::column_type_impl (t, type, ctx, f)); + string r (::context::database_type_impl (t, type, ctx, f)); if (!r.empty () && ctx.count ("auto") && (f & ctf_object_id_ref) == 0) r += " AUTO_INCREMENT"; diff --git a/odb/relational/mysql/context.hxx b/odb/relational/mysql/context.hxx index b1de84c..4141a4a 100644 --- a/odb/relational/mysql/context.hxx +++ b/odb/relational/mysql/context.hxx @@ -94,16 +94,16 @@ namespace relational virtual string quote_id_impl (string const&) const; + protected: + virtual string + database_type_impl (semantics::type&, + string const& type, + semantics::context&, + column_type_flags); private: struct data: base_context::data { data (std::ostream& os): base_context::data (os) {} - - virtual string - column_type_impl (semantics::type&, - string const& type, - semantics::context&, - column_type_flags) const; }; private: diff --git a/odb/type-processor.cxx b/odb/type-processor.cxx index af6ab3d..ebead7b 100644 --- a/odb/type-processor.cxx +++ b/odb/type-processor.cxx @@ -130,15 +130,15 @@ namespace if (null_pointer (m)) f |= ctf_default_null; - type = data_->column_type_impl (idt, type, id, f); + type = database_type (idt, type, id, f); } else { string orig (type); - type = data_->column_type_impl (t, orig, m, ctf_none); + type = database_type (t, orig, m, ctf_none); if (m.count ("id")) - ref_type = data_->column_type_impl (t, orig, m, ctf_object_id_ref); + ref_type = database_type (t, orig, m, ctf_object_id_ref); } if (!type.empty ()) @@ -217,10 +217,10 @@ namespace if (null_pointer (m, prefix)) f |= ctf_default_null; - type = data_->column_type_impl (idt, type, id, f); + type = database_type (idt, type, id, f); } else - type = data_->column_type_impl (t, type, m, ctf_none); + type = database_type (t, type, m, ctf_none); if (!type.empty ()) { -- cgit v1.1