]> git.tdb.fi Git - builder.git/blob - source/toolchain.cpp
Replace basic for loops with range-based loops or algorithms
[builder.git] / source / toolchain.cpp
1 #include <algorithm>
2 #include <msp/core/maputils.h>
3 #include "tool.h"
4 #include "toolchain.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 Toolchain::~Toolchain()
10 {
11         for(const auto &kvp: tools)
12                 delete kvp.second;
13         for(Toolchain *c: chains)
14                 delete c;
15 }
16
17 void Toolchain::add_tool(Tool *tool)
18 {
19         insert_unique(tools, tool->get_tag(), tool);
20 }
21
22 void Toolchain::add_toolchain(Toolchain *chain)
23 {
24         chains.push_back(chain);
25 }
26
27 bool Toolchain::has_tool(const string &tag) const
28 {
29         if(tools.count(tag))
30                 return true;
31         return any_of(chains.begin(), chains.end(), [&tag](Toolchain *tc){ return tc->has_tool(tag); });
32 }
33
34 Tool &Toolchain::get_tool(const string &tag) const
35 {
36         if(!tools.count(tag))
37         {
38                 for(const Toolchain *c: chains)
39                         if(c->has_tool(tag))
40                                 return c->get_tool(tag);
41         }
42
43         return *get_item(tools, tag);
44 }
45
46 Tool *Toolchain::get_tool_for_suffix(const string &suffix, bool aux) const
47 {
48         for(const auto &kvp: tools)
49                 if(kvp.second->accepts_suffix(suffix, aux))
50                         return kvp.second;
51
52         for(const Toolchain *c: chains)
53                 if(Tool *tool = c->get_tool_for_suffix(suffix, aux))
54                         return tool;
55
56         return 0;
57 }