#include "package.h"
#include "plugin.h"
#include "sharedlibrary.h"
-#include "sourcepackage.h"
#include "task.h"
#include "virtualtarget.h"
#include "config.h"
#include "logger.h"
#include "packagemanager.h"
+#include "sourcepackage.h"
#include "target.h"
#include "toolchain.h"
#include "virtualfilesystem.h"
class FileTarget;
class Package;
class Plugin;
-class SourcePackage;
/**
This class ties everything else together. It also contains code for loading
std::vector<LoadedPlugin> plugins;
PackageManager package_manager;
+ SourcePackage::ComponentRegistry component_registry;
Architecture native_arch;
Architecture *current_arch = 0;
void load_plugins();
PackageManager &get_package_manager() { return package_manager; }
+ SourcePackage::ComponentRegistry &get_component_registry() { return component_registry; }
template<typename F>
void call_plugins(F) const;
add("source_tarball", &Loader::source_archive);
add("tarball", &Loader::tarball);
add("version", &Loader::version);
+
+ p.builder.get_component_registry().invoke_all(*this);
}
void SourcePackage::Loader::finish()
}
}
-template<typename C, typename... Args>
-void SourcePackage::Loader::component(Args... args, const string &n)
-{
- if(any_of(obj.components.begin(), obj.components.end(), [&n](const Component *c){ return c->get_name()==n; }))
- throw key_error(n);
- C *comp = new C(obj, n, args...);
- load_sub(*comp);
- obj.components.push_back(comp);
-}
-
void SourcePackage::Loader::build_info()
{
load_sub(obj.build_info);
#ifndef SOURCEPACKAGE_H_
#define SOURCEPACKAGE_H_
+#include <algorithm>
#include <stdexcept>
#include <string>
+#include <msp/core/typeregistry.h>
#include "buildinfo.h"
#include "cache.h"
#include "component.h"
public:
class Loader: public Msp::DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>, public FeatureConditional
{
+ friend class SourcePackage;
+
private:
+ template<typename T>
+ struct AddComponent
+ {
+ void operator()(const std::string &n, Loader &l) const { l.add(n, &Loader::component<T>); }
+ };
+
const Config::InputOptions *options;
public:
void version(const std::string &);
};
+ using ComponentRegistry = Msp::TypeRegistry<Loader::AddComponent, Loader &>;
+
private:
std::string version;
std::string interface_version;
void save_caches() override;
};
+
+template<typename C, typename... Args>
+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