diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-08-24 09:51:15 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-08-24 14:52:43 +0200 |
commit | 68f96f9213e849d0d7c4cedf3edeaec99743ee27 (patch) | |
tree | 271913d74c906971cac555319f5e14d0c66e0c16 /build/config/utility.txx | |
parent | 0d5234f4aefd3cc5b5948cc1b9dd009e50046f5e (diff) |
New variable architecture
Diffstat (limited to 'build/config/utility.txx')
-rw-r--r-- | build/config/utility.txx | 64 |
1 files changed, 11 insertions, 53 deletions
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 <utility> // move() - #include <build/scope> -#include <build/variable> namespace build { namespace config { template <typename T> - std::pair<const T&, bool> - 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<const T&> ()); - - if (!v.belongs (*global_scope)) // A value from (some) config.build. - return std::pair<const T&, bool> (s, false); - - r = s; - } - else - r = def_value; - - auto v (root.assign (var)); - v = std::move (r); - - return std::pair<const T&, bool> (v.as<const T&> (), true); - } - - template <typename T> - const T* - optional (scope& root, const char* name) + std::pair<std::reference_wrapper<const value>, 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<std::reference_wrapper<const value>, 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<const T&> (); + return l.belongs (*global_scope) + ? result (root.assign (var) = *l, true) + : result (*l, false); } else - root.assign (var) = nullptr; - - return r; - } - - template <typename T> - void - append_options (cstrings& args, T& s, const char* var) - { - if (auto val = s[var]) - append_options (args, val.template as<const list_value&> (), var); + return result (root.assign (var) = def_value, true); } template <typename T> 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<const list_value&> ()) + for (const std::string& s: as<strings> (*l)) { - if (n.simple () && n.value == option) + if (s == option) return true; } } |