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.txx | 64 +++++++++--------------------------------------- 1 file changed, 11 insertions(+), 53 deletions(-) (limited to 'build/config/utility.txx') diff --git a/build/config/utility.txx b/build/config/utility.txx index cffdecf..943d308 100644 --- a/build/config/utility.txx +++ b/build/config/utility.txx @@ -2,79 +2,37 @@ // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include // move() - #include -#include namespace build { namespace config { template - std::pair - required (scope& root, const char* name, const T& def_value) - { - T r; - const variable& var (variable_pool.find (name)); - - if (auto v = root[var]) - { - const T& s (v.as ()); - - if (!v.belongs (*global_scope)) // A value from (some) config.build. - return std::pair (s, false); - - r = s; - } - else - r = def_value; - - auto v (root.assign (var)); - v = std::move (r); - - return std::pair (v.as (), true); - } - - template - const T* - optional (scope& root, const char* name) + std::pair, bool> + required (scope& root, const variable& var, const T& def_value) { - const T* r (nullptr); - const variable& var (variable_pool.find (name)); + using result = std::pair, bool>; - auto v (root[var]); - - if (v.defined ()) + if (auto l = root[var]) { - if (v.belongs (*global_scope)) - root.assign (var) = v; - - r = v.null () ? nullptr : &v.as (); + return l.belongs (*global_scope) + ? result (root.assign (var) = *l, true) + : result (*l, false); } else - root.assign (var) = nullptr; - - return r; - } - - template - void - append_options (cstrings& args, T& s, const char* var) - { - if (auto val = s[var]) - append_options (args, val.template as (), var); + return result (root.assign (var) = def_value, true); } template bool find_option (const char* option, T& s, const char* var) { - if (auto val = s[var]) + if (auto l = s[var]) { - for (const name& n: val.template as ()) + for (const std::string& s: as (*l)) { - if (n.simple () && n.value == option) + if (s == option) return true; } } -- cgit v1.1