aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-31 23:44:42 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-06-03 09:27:03 +0200
commitfb692e5f7b34def8cf590298036ab63e40747062 (patch)
tree67e9513031abbf732fb80e7161d766749d9cd38e
parenta2f86ac647e460f10381c01432b3f07e2bc6db24 (diff)
Bindings: Add convenience method for requiring an attribute
-rw-r--r--src/libexpr/attr-set.hh8
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_]; }