aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-31 23:44:42 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-12-05 20:29:15 +0100
commit79142cbbe1d5145a18950f4a955e2f2b1878576b (patch)
tree3fcefd9c689549776d438c1df53fdb569ba055e1 /src/libexpr
parent0d118ef0c95d5b2ba306372c97526cd2aaaac679 (diff)
Bindings: Add convenience method for requiring an attribute
(cherry picked from commit fb692e5f7b34def8cf590298036ab63e40747062)
Diffstat (limited to 'src/libexpr')
-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_]; }