aboutsummaryrefslogtreecommitdiff
path: root/build/config/utility.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'build/config/utility.cxx')
-rw-r--r--build/config/utility.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/build/config/utility.cxx b/build/config/utility.cxx
new file mode 100644
index 0000000..8b26239
--- /dev/null
+++ b/build/config/utility.cxx
@@ -0,0 +1,41 @@
+// file : build/config/utility.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <build/config/utility>
+
+using namespace std;
+
+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<const string&, bool>
+ required (scope& root, const char* name, const char* def_value)
+ {
+ string r;
+ const variable& var (variable_pool.find (name));
+
+ if (auto v = root[var])
+ {
+ const string& s (v.as<const string&> ());
+
+ if (!v.belongs (*global_scope)) // A value from (some) config.build.
+ return pair<const string&, bool> (s, false);
+
+ r = s;
+ }
+ else
+ r = def_value;
+
+ auto v (root.assign (var));
+ v = move (r);
+
+ return pair<const string&, bool> (v.as<const string&> (), true);
+ }
+ }
+}