Program Listing for File ComponentExporter.hpp
↰ Return to documentation for file (engine/include/Cacao/ComponentExporter.hpp
)
#pragma once
#include "DllHelper.hpp"
#include "Resource.hpp"
#include <functional>
#include <memory>
#include <typeindex>
namespace Cacao {
class Script;
class Component;
class CACAO_API ComponentExporter : public Resource, std::enable_shared_from_this<ComponentExporter> {
public:
const std::type_index type;
template<typename T>
requires std::is_base_of_v<Component, T> && (!std::is_same_v<Script, T>)
static ComponentExporter Create(std::function<std::shared_ptr<T>> factory, const std::string& addr) {
return ComponentExporter(addr, typeid(T), [factory]() { return std::static_pointer_cast<Component>(factory()); });
}
std::shared_ptr<Component> Instantiate();
private:
ComponentExporter(const std::string& addr, std::type_index tp, std::function<std::shared_ptr<Component>()> f)
: Resource(addr), type(tp), factory(f) {}
const std::function<std::shared_ptr<Component>()> factory;
};
}