6#include <unordered_map>
9#include "core/reflect.h"
10#include "system/script/behavior.h"
12namespace Vkm::Engine {
20class BehaviorRegistry {
22 using Factory = std::function<std::unique_ptr<Behavior>()>;
25 ~BehaviorRegistry() =
default;
27 BehaviorRegistry(
const BehaviorRegistry& other) =
delete;
28 BehaviorRegistry& operator=(
const BehaviorRegistry& other) =
delete;
30 BehaviorRegistry(BehaviorRegistry && other) =
delete;
31 BehaviorRegistry& operator=(BehaviorRegistry && other) =
delete;
34 static BehaviorRegistry& get();
48 template<
typename... Ts>
59 std::unique_ptr<Behavior>
create(
const std::string& name)
const;
74 std::vector<std::string>
names()
const;
82 BehaviorRegistry() =
default;
90 void registerBehavior(std::string name, Factory factory);
93 std::unordered_map<std::string, Factory> m_factories;
std::unique_ptr< Behavior > create(const std::string &name) const
Create a fresh instance by name.
void registerBehaviors()
Register every type in Ts, in order, each under the name its reflect block records.
Definition behavior_registry.h:49
std::vector< std::string > names() const
List every registered behavior name, sorted.
bool contains(const std::string &name) const
Report whether name has a registered factory.
void clear()
Drop every registered factory; call before unloading the module whose code they hold.
The reflection trait, specialised per type by VKM_REFLECT_BEGIN / VKM_F / VKM_REFLECT_END.
Definition reflect.h:41