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/pragma.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/pragma.cxx')
-rw-r--r-- | odb/pragma.cxx | 38 |
1 files changed, 38 insertions, 0 deletions
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") { |