]> git.tdb.fi Git - builder.git/blobdiff - source/toolchain.cpp
Replace basic for loops with range-based loops or algorithms
[builder.git] / source / toolchain.cpp
index 953fe1147a660df9f429f7a8f7e9f7cef2f709bc..8790c83dca0737e186a868900cc8d2665343484b 100644 (file)
@@ -1,3 +1,4 @@
+#include <algorithm>
 #include <msp/core/maputils.h>
 #include "tool.h"
 #include "toolchain.h"
@@ -7,10 +8,10 @@ using namespace Msp;
 
 Toolchain::~Toolchain()
 {
-       for(ToolMap::iterator i=tools.begin(); i!=tools.end(); ++i)
-               delete i->second;
-       for(ToolchainList::iterator i=chains.begin(); i!=chains.end(); ++i)
-               delete *i;
+       for(const auto &kvp: tools)
+               delete kvp.second;
+       for(Toolchain *c: chains)
+               delete c;
 }
 
 void Toolchain::add_tool(Tool *tool)
@@ -27,19 +28,16 @@ bool Toolchain::has_tool(const string &tag) const
 {
        if(tools.count(tag))
                return true;
-       for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
-               if((*i)->has_tool(tag))
-                       return true;
-       return false;
+       return any_of(chains.begin(), chains.end(), [&tag](Toolchain *tc){ return tc->has_tool(tag); });
 }
 
 Tool &Toolchain::get_tool(const string &tag) const
 {
        if(!tools.count(tag))
        {
-               for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
-                       if((*i)->has_tool(tag))
-                               return (*i)->get_tool(tag);
+               for(const Toolchain *c: chains)
+                       if(c->has_tool(tag))
+                               return c->get_tool(tag);
        }
 
        return *get_item(tools, tag);
@@ -47,12 +45,12 @@ Tool &Toolchain::get_tool(const string &tag) const
 
 Tool *Toolchain::get_tool_for_suffix(const string &suffix, bool aux) const
 {
-       for(ToolMap::const_iterator i=tools.begin(); i!=tools.end(); ++i)
-               if(i->second->accepts_suffix(suffix, aux))
-                       return i->second;
+       for(const auto &kvp: tools)
+               if(kvp.second->accepts_suffix(suffix, aux))
+                       return kvp.second;
 
-       for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
-               if(Tool *tool = (*i)->get_tool_for_suffix(suffix, aux))
+       for(const Toolchain *c: chains)
+               if(Tool *tool = c->get_tool_for_suffix(suffix, aux))
                        return tool;
 
        return 0;