From ba637925b32e85c22c9dc81820e407ebdacfe5f7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Jan 2020 07:19:43 +0200 Subject: Add scope::{insert_rule,var_pool}() convenience functions --- libbuild2/scope.hxx | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/libbuild2/scope.hxx b/libbuild2/scope.hxx index 2ed8f18..655a1a0 100644 --- a/libbuild2/scope.hxx +++ b/libbuild2/scope.hxx @@ -181,6 +181,14 @@ namespace build2 return vars.assign (ctx.var_pool.rw (*this).insert (move (name))); } + template + T& + assign (string name, T&& val) + { + value& v (assign (move (name)) = forward (val)); + return v.as (); + } + // Return a value suitable for appending. If the variable does not // exist in this scope's map, then outer scopes are searched for // the same variable. If found then a new variable with the found @@ -289,6 +297,22 @@ namespace build2 public: rule_map rules; + template + void + insert_rule (action_id a, const char* hint, const rule& r) + { + rules.insert (a, hint, r); + } + + template + void + insert_rule (meta_operation_id mid, operation_id oid, + const char* hint, + const rule& r) + { + rules.insert (mid, oid, hint, r); + } + // Operation callbacks. // // An entity (module, core) can register a function that will be called @@ -374,9 +398,9 @@ namespace build2 template T* - lookup_module (const string& name) const + find_module (const string& name) const { - return root_extra->modules.lookup (name); + return root_extra->modules.find_module (name); } public: @@ -389,6 +413,12 @@ namespace build2 return const_cast (*this); } + variable_pool& + var_pool () + { + return ctx.var_pool.rw (*this); + } + private: friend class parser; friend class scope_map; -- cgit v1.1