From 68f96f9213e849d0d7c4cedf3edeaec99743ee27 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 24 Aug 2015 09:51:15 +0200 Subject: New variable architecture --- build/config/utility.cxx | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'build/config/utility.cxx') diff --git a/build/config/utility.cxx b/build/config/utility.cxx index e2afc80..ce723fe 100644 --- a/build/config/utility.cxx +++ b/build/config/utility.cxx @@ -10,32 +10,14 @@ namespace build { namespace config { - // The same as the template except it is a bit more efficient - // when it comes to not creating the default value string - // unnecessarily. - // - pair - required (scope& root, const char* name, const char* def_value) + const value& + optional (scope& root, const variable& var) { - string r; - const variable& var (variable_pool.find (name)); + auto l (root[var]); - if (auto v = root[var]) - { - const string& s (v.as ()); - - if (!v.belongs (*global_scope)) // A value from (some) config.build. - return pair (s, false); - - r = s; - } - else - r = def_value; - - auto v (root.assign (var)); - v = move (r); - - return pair (v.as (), true); + return l.defined () + ? l.belongs (*global_scope) ? (root.assign (var) = *l) : *l + : root.assign (var); // NULL } bool @@ -54,17 +36,14 @@ namespace build } void - append_options (cstrings& args, const list_value& lv, const char* var) + append_options (cstrings& args, const const_strings_value& sv) { - for (const name& n: lv) + if (!sv.empty ()) { - if (n.simple ()) - args.push_back (n.value.c_str ()); - else if (n.directory ()) - args.push_back (n.dir.string ().c_str ()); - else - fail << "expected option instead of " << n << - info << "in variable " << var; + args.reserve (args.size () + sv.size ()); + + for (const string& s: sv) + args.push_back (s.c_str ()); } } } -- cgit v1.1