diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-03 18:23:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-03 18:23:51 +0200 |
commit | 80b868be1e7c249daa714b0c7a5f87694edb8664 (patch) | |
tree | d8e0dd6eca09d33d70224f7289ae096a0976cd6b /odb/common.cxx | |
parent | 89ba09f073b103953c53e63bd78f644973d9154e (diff) |
Implement nested id support
Now the 'id' specifier can optionally include the data member path
to the id inside the composite value. For example:
#pragma db id(first)
std::pair<int, int> p;
Note that one somewhat counter-intuitive aspect of this new feature
is that the whole member marked with id ('p' in the above example)
and not just the actual id member ('p.first' in the above example)
is treated as readonly.
Such nested id also cannot be automatically assigned (auto specifier).
Diffstat (limited to 'odb/common.cxx')
-rw-r--r-- | odb/common.cxx | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/odb/common.cxx b/odb/common.cxx index 8dc995d..6d341b8 100644 --- a/odb/common.cxx +++ b/odb/common.cxx @@ -288,6 +288,42 @@ traverse_post (semantics::nameable&) } void object_columns_base:: +traverse (semantics::data_member& m) +{ + traverse_pre (m); + + semantics::type& t (utype (m)); + semantics::class_* c (object_pointer (t)); + semantics::type* rt (c == 0 ? &t : &utype (*id_member (*c))); + + root_ = &m; + + // It would seem natural to add m to member_path_ so that we don't + // have these two cases. However, for member path to work correctly + // with readonly() we also have to have corresponding member_scope, + // which is a whole different level of complexity. + // + root_id_ = member_path_.empty () + ? context::id (m) + : context::id (member_path_) != 0; + root_op_ = (c != 0); + root_null_ = context::null (m); + + + if (root_op_) + traverse_pointer (m, *c); + else + traverse_member (m, *rt); + + if (!first_ && composite_wrapper (*rt)) + flush (); + + root_ = 0; + + traverse_post (m); +} + +void object_columns_base:: traverse (semantics::data_member& m, semantics::type& t, std::string const& kp, @@ -305,7 +341,7 @@ traverse (semantics::data_member& m, semantics::type* rt (c == 0 ? &t : &utype (*id_member (*c))); root_ = &m; - root_id_ = (kp.empty () ? context::id (m) : kp == "id"); + root_id_ = (kp == "id"); root_op_ = (c != 0); root_null_ = context::null (m, kp); |