From 80b868be1e7c249daa714b0c7a5f87694edb8664 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 3 Jul 2015 18:23:51 +0200 Subject: 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 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). --- odb/common.cxx | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'odb/common.cxx') 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); -- cgit v1.1