X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flib%2Fsourcepackage.h;h=d458c9094208c9c86ff4755bb34d9bb47aa6d3b7;hb=c5d6d6d6d76189b9b2937295709b85654780e9db;hp=d37ecf4a8a7e356d3d1b45f4566df605c8b77093;hpb=36078a036ecf771ce0f020338f7e812c08a37479;p=builder.git diff --git a/source/lib/sourcepackage.h b/source/lib/sourcepackage.h index d37ecf4..d458c90 100644 --- a/source/lib/sourcepackage.h +++ b/source/lib/sourcepackage.h @@ -1,8 +1,10 @@ #ifndef SOURCEPACKAGE_H_ #define SOURCEPACKAGE_H_ +#include #include #include +#include #include "buildinfo.h" #include "cache.h" #include "component.h" @@ -12,7 +14,6 @@ #include "package.h" #include "toolchain.h" -class Builder; class BuildType; class FileTarget; class SourceArchiveComponent; @@ -25,7 +26,15 @@ class SourcePackage: public Package public: class Loader: public Msp::DataFile::DerivedObjectLoader, public FeatureConditional { + friend class SourcePackage; + private: + template + struct AddComponent + { + void operator()(const std::string &n, Loader &l) const { l.add(n, &Loader::component); } + }; + const Config::InputOptions *options; public: @@ -44,6 +53,8 @@ public: void version(const std::string &); }; + using ComponentRegistry = Msp::TypeRegistry; + private: std::string version; std::string interface_version; @@ -88,4 +99,15 @@ private: void save_caches() override; }; + +template +void SourcePackage::Loader::component(Args... args, const std::string &n) +{ + if(std::any_of(obj.components.begin(), obj.components.end(), [&n](const Component *c){ return c->get_name()==n; })) + throw Msp::key_error(n); + C *comp = new C(obj, n, args...); + load_sub(*comp); + obj.components.push_back(comp); +} + #endif