diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-05-31 23:44:42 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-06-03 09:27:03 +0200 |
commit | fb692e5f7b34def8cf590298036ab63e40747062 (patch) | |
tree | 67e9513031abbf732fb80e7161d766749d9cd38e | |
parent | a2f86ac647e460f10381c01432b3f07e2bc6db24 (diff) |
Bindings: Add convenience method for requiring an attribute
-rw-r--r-- | src/libexpr/attr-set.hh | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libexpr/attr-set.hh b/src/libexpr/attr-set.hh index 6c5fb21ad..d6af99912 100644 --- a/src/libexpr/attr-set.hh +++ b/src/libexpr/attr-set.hh @@ -72,6 +72,14 @@ public: return {}; } + Attr & need(const Symbol & name, const Pos & pos = noPos) + { + auto a = get(name); + if (!a) + throw Error("attribute '%s' missing, at %s", name, pos); + return **a; + } + iterator begin() { return &attrs[0]; } iterator end() { return &attrs[size_]; } |