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/pragma.cxx | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'odb/pragma.cxx') diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 549a0f6..046140e 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -1893,12 +1893,50 @@ handle_pragma (cxx_lexer& l, } else if (p == "id") { + // id[(member-path)] + // + // Make sure we've got the correct declaration type. // if (decl && !check_spec_decl_type (decl, decl_name, p, loc)) return; + string name; + tt = l.next (tl, &tn); + if (tt == CPP_OPEN_PAREN) + { + if (l.next (tl, &tn) != CPP_NAME) + { + error (l) << "data member name expected in db pragma " << p + << endl; + return; + } + + name = tl; + + for (tt = l.next (tl, &tn); tt == CPP_DOT; tt = l.next (tl, &tn)) + { + if (l.next (tl, &tn) != CPP_NAME) + { + error (l) << "name expected after '.' in db pragma " << p << endl; + return; + } + + name += '.'; + name += tl; + } + + if (tt != CPP_CLOSE_PAREN) + { + error (l) << "')' expected at the end of db pragma " << p << endl; + return; + } + + tt = l.next (tl, &tn); + } + + val = name; } else if (p == "no_id") { -- cgit v1.1