aboutsummaryrefslogtreecommitdiff
path: root/build2/config/utility.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-05 11:55:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-05 11:55:15 +0200
commit9fb791e9fad6c63fc1dac49f4d05ae63b8a3db9b (patch)
treed60322d4382ca5f97b676c5abe2e39524f35eab4 /build2/config/utility.txx
parentf159b1dac68c8714f7ba71ca168e3b695891aad9 (diff)
Rename build directory/namespace to build2
Diffstat (limited to 'build2/config/utility.txx')
-rw-r--r--build2/config/utility.txx45
1 files changed, 45 insertions, 0 deletions
diff --git a/build2/config/utility.txx b/build2/config/utility.txx
new file mode 100644
index 0000000..c88a34f
--- /dev/null
+++ b/build2/config/utility.txx
@@ -0,0 +1,45 @@
+// file : build2/config/utility.txx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <build2/scope>
+
+namespace build2
+{
+ namespace config
+ {
+ template <typename T>
+ std::pair<std::reference_wrapper<const value>, bool>
+ required (scope& root, const variable& var, const T& def_value, bool ovr)
+ {
+ using result = std::pair<std::reference_wrapper<const value>, bool>;
+
+ if (auto l = root[var])
+ {
+ if (l.belongs (*global_scope))
+ return result (root.assign (var) = *l, true);
+
+ if (!ovr || l.belongs (root))
+ return result (*l, false);
+ }
+
+ return result (root.assign (var) = def_value, true);
+ }
+
+ template <typename T>
+ bool
+ find_option (const char* option, T& s, const char* var)
+ {
+ if (auto l = s[var])
+ {
+ for (const std::string& s: as<strings> (*l))
+ {
+ if (s == option)
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+}