blob: e37c2b5011476e163df5b42edd2c679768f3bca3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// file : build/config/utility.txx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// 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)
{
const T* r (nullptr);
const variable& var (variable_pool.find (name));
auto v (root[var]);
if (v.defined ())
{
if (v.belongs (*global_scope))
root.assign (var) = v;
r = v.null () ? nullptr : &v.as<const T&> ();
}
else
root.assign (var) = nullptr;
return r;
}
}
}
|