From: Mikko Rasa Date: Fri, 24 May 2013 15:37:48 +0000 (+0300) Subject: Make toolchains hierarchial X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8a2579d4b8e510405402ec316d53a509152aa6ea;p=builder.git Make toolchains hierarchial This enables eventual tool plugins to give out all of their tools in one bundle. --- diff --git a/source/toolchain.cpp b/source/toolchain.cpp index 9d23403..953fe11 100644 --- a/source/toolchain.cpp +++ b/source/toolchain.cpp @@ -9,6 +9,8 @@ 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; } void Toolchain::add_tool(Tool *tool) @@ -16,8 +18,30 @@ void Toolchain::add_tool(Tool *tool) insert_unique(tools, tool->get_tag(), tool); } +void Toolchain::add_toolchain(Toolchain *chain) +{ + chains.push_back(chain); +} + +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; +} + 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); + } + return *get_item(tools, tag); } @@ -27,5 +51,9 @@ Tool *Toolchain::get_tool_for_suffix(const string &suffix, bool aux) const if(i->second->accepts_suffix(suffix, aux)) return i->second; + for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i) + if(Tool *tool = (*i)->get_tool_for_suffix(suffix, aux)) + return tool; + return 0; } diff --git a/source/toolchain.h b/source/toolchain.h index 572e42f..8449680 100644 --- a/source/toolchain.h +++ b/source/toolchain.h @@ -1,6 +1,7 @@ #ifndef TOOLCHAIN_H_ #define TOOLCHAIN_H_ +#include #include #include @@ -13,13 +14,17 @@ class Toolchain { private: typedef std::map ToolMap; + typedef std::list ToolchainList; ToolMap tools; + ToolchainList chains; public: ~Toolchain(); void add_tool(Tool *); + void add_toolchain(Toolchain *); + bool has_tool(const std::string &) const; Tool &get_tool(const std::string &) const; Tool *get_tool_for_suffix(const std::string &, bool = false) const; };