aboutsummaryrefslogtreecommitdiff
path: root/build/config/utility.txx
blob: 06cb2eb1403479311422003c7ca1cef5586fd8bb (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
// file      : build/config/utility.txx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <build/scope>

namespace build
{
  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;
    }
  }
}