diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-09 20:19:17 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-09 20:19:17 +0200 |
commit | 9072761e0c9486cc3d1265a1c1e2b39db8e68bf7 (patch) | |
tree | 1e284d8088e51a962bd285b02f8096ed088463ee /odb/context.hxx | |
parent | dfba83f1ef3b5856d36dc29da0b6e02f51bc36b3 (diff) |
Make sure we can use same type as both container and simple value
Diffstat (limited to 'odb/context.hxx')
-rw-r--r-- | odb/context.hxx | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/odb/context.hxx b/odb/context.hxx index 10210a3..3be05a9 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -333,27 +333,28 @@ public: return 0; } - static bool - container (semantics::type& t) - { - return t.count ("container-kind"); - } - - // As above but also "sees through" wrappers. Returns the actual - // container type or NULL if not a container. + // Check if a data member is a container. "Sees through" wrappers and + // returns the actual container type or NULL if not a container. + // + // We require data member as input instead of the type because the + // same type (e.g., vector<char>) can be used for both container + // and simple value members. // static semantics::type* - container_wrapper (semantics::type& t) + container (semantics::data_member& m) { - if (container (t)) - return &t; - else if (semantics::type* wt = wrapper (t)) - { - wt = &utype (*wt); - return container (*wt) ? wt : 0; - } - else + // The same type can be used as both a container and a simple value. + // If the member has defines the database type, then it is the latter. + // + if (m.count ("type") || m.count ("id-type")) return 0; + + semantics::type* t (&utype (m)); + + if (semantics::type* wt = wrapper (*t)) + t = &utype (*wt); + + return t->count ("container-kind") ? t : 0; } static semantics::class_* @@ -620,7 +621,7 @@ public: if (m.count ("unordered")) return true; - if (semantics::type* c = container_wrapper (utype (m))) + if (semantics::type* c = container (m)) return c->count ("unordered"); return false; |