aboutsummaryrefslogtreecommitdiff
path: root/build/scope
blob: 58f7933a8871bb050a15c0991d0fdd1455712b30 (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
// file      : build/scope -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD_SCOPE
#define BUILD_SCOPE

#include <build/path>
#include <build/path-map>
#include <build/prerequisite>

namespace build
{
  class scope
  {
  public:
    typedef build::path path_type;

    const path_type&
    path () const {return i_->first;} // Absolute and normalized.

  private:
    friend class scope_map;

    typedef path_map<scope>::const_iterator iterator;

    scope () = default;

    void
    init (const iterator& i) {i_ = i;}

  public:
    prerequisite_set prerequisites;

  private:
    iterator i_;
  };

  class scope_map: path_map<scope>
  {
  public:
    scope&
    operator[] (const path& k)
    {
      auto i (emplace (k, scope ()));
      auto& r (i.first->second);

      if (i.second)
        r.init (i.first);

      return r;
    }
  };

  extern scope_map scopes;
}

#endif // BUILD_SCOPE