aboutsummaryrefslogtreecommitdiff
path: root/build/rule-map
blob: 883800b8d7c97e40f71b70c5200980b8d6b05440 (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
// file      : build/rule-map -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD_RULE_MAP
#define BUILD_RULE_MAP

#include <map>
#include <vector>
#include <string>
#include <typeindex>
#include <functional>     // reference_wrapper

#include <butl/prefix-map>

#include <build/types>
#include <build/operation>

namespace build
{
  class rule;

  using target_type_rule_map = std::map<
    std::type_index,              // Target type.
    butl::prefix_map<std::string, // Rule hint.
                     std::reference_wrapper<rule>, '.'>>;

  // This is an "indexed map" with (operation_id - 1) being the
  // index.
  //
  class rule_map: public std::vector<target_type_rule_map>
  {
  public:
    template <typename T>
    void
    insert (operation_id oid, const char* hint, rule& r)
    {
      if (oid > size ())
        resize (oid < 3 ? 3 : oid); // 3 is the number of builtin operations.

      (*this)[oid - 1][typeid (T)].emplace (hint, r);
    }
  };
}

#endif // BUILD_RULE_MAP