aboutsummaryrefslogtreecommitdiff
path: root/odb/context.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-04-25 18:32:22 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-04-25 19:27:36 +0200
commit84d9c3f57c35cf9e99e89eeeb6cc4f1c52c3f5a2 (patch)
tree6467dcafcb98ada1695f27af90ba10966f2dcafb /odb/context.cxx
parent2f1d254fb49e8cc8bd9ea2137758614e5825eaed (diff)
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.
Diffstat (limited to 'odb/context.cxx')
-rw-r--r--odb/context.cxx24
1 files changed, 15 insertions, 9 deletions
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);