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/header.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'odb/header.cxx') diff --git a/odb/header.cxx b/odb/header.cxx index 0a01311..2155ed8 100644 --- a/odb/header.cxx +++ b/odb/header.cxx @@ -60,9 +60,10 @@ traverse_object (type& c) { using semantics::data_member; - data_member* id (id_member (c)); + data_member_path* id (id_member (c)); + data_member* idf (id ? id->front () : 0); bool auto_id (id && auto_ (*id)); - bool base_id (id && &id->scope () != &c); // Comes from base. + bool base_id (id && &idf->scope () != &c); // Comes from base. data_member* opt (context::optimistic (c)); @@ -157,8 +158,7 @@ traverse_object (type& c) { if (base_id) { - semantics::class_& b ( - dynamic_cast (id->scope ())); + semantics::class_& b (dynamic_cast (idf->scope ())); string const& type (class_fq_name (b)); os << "typedef object_traits< " << type << " >::id_type id_type;"; -- cgit v1.1