From 84d9c3f57c35cf9e99e89eeeb6cc4f1c52c3f5a2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 25 Apr 2011 18:32:22 +0200 Subject: Add support for mapping to database types based on type aliases This allows us to, for example, always map size_t to 64-bit type. The current implementation does not work for containers. It is not clear whether it will be possible to make it work using the GCC AST. --- odb/context.cxx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'odb/context.cxx') diff --git a/odb/context.cxx b/odb/context.cxx index d281090..00edd8d 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -264,23 +264,29 @@ column_type (semantics::data_member& m, string const& kp) string context:: database_type_impl (semantics::type& t, - string const& type, + semantics::names* hint, 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. + type_map_type::const_iterator end (data_->type_map_.end ()), i (end); + + // First check the hinted name. This allows us to handle things like + // size_t which is nice to map to the same type irrespective of the + // actual type. Since this type can be an alias for the one we are + // interested in, go into nested hints. // - if (!type.empty ()) - return type; + for (; hint != 0 && i == end; hint = hint->hint ()) + { + i = data_->type_map_.find (t.fq_name (hint)); + } - // Don't use the name hint here so that we get the primary name (e.g., + // If the hinted name didn't work, try the primary name (e.g., // ::std::string) instead of a user typedef (e.g., my_string). // - string const& name (t.fq_name ()); - type_map_type::const_iterator i (data_->type_map_.find (name)); + if (i == end) + i = data_->type_map_.find (t.fq_name ()); - if (i != data_->type_map_.end ()) + if (i != end) { string r (ctx.count ("id") ? i->second.id_type : i->second.type); -- cgit v1.1