Name -> factory registry for Behavior subclasses.
More...
#include <behavior_registry.h>
|
| void | registerBehavior (std::string name, Factory factory) |
| | Register name -> factory.
|
| template<typename T> |
| void | registerBehavior () |
| | Register T under the name its reflect block records.
|
| template<typename... Ts> |
| void | registerBehaviors () |
| | Register every type in Ts, in order, as registerBehavior<T>() does.
|
| std::unique_ptr< Behavior > | create (const std::string &name) const |
| | Create a fresh instance by name.
|
| bool | contains (const std::string &name) const |
| | Report whether name has a registered factory.
|
| std::vector< std::string > | names () const |
| | List every registered behavior name, sorted.
|
|
void | clear () |
| | Drop every registered factory; call before unloading the module whose code they hold.
|
Name -> factory registry for Behavior subclasses.
A gameplay module registers its types from vkmRegisterBehaviors. One per process, since game-DLL code must reach it.
◆ registerBehavior() [1/2]
| void Vkm::Engine::BehaviorRegistry::registerBehavior |
( |
std::string | name, |
|
|
Factory | factory ) |
Register name -> factory.
A duplicate name logs a warning and overwrites the existing factory.
- Parameters
-
| name | Key the type is registered and created under. |
| factory | Constructs a fresh instance. |
◆ registerBehavior() [2/2]
template<typename T>
| void Vkm::Engine::BehaviorRegistry::registerBehavior |
( |
| ) |
|
|
inline |
Register T under the name its reflect block records.
The same string typeName() returns, so the save and load keys cannot differ.
- Template Parameters
-
| T | Behavior subclass with a VKM_REFLECT block, default-constructible. |
◆ registerBehaviors()
template<typename... Ts>
| void Vkm::Engine::BehaviorRegistry::registerBehaviors |
( |
| ) |
|
|
inline |
Register every type in Ts, in order, as registerBehavior<T>() does.
BehaviorRegistry::get().registerBehaviors<Spinner, Health, Door>();
- Template Parameters
-
| Ts | Behavior subclasses with VKM_REFLECT blocks. |
◆ create()
| std::unique_ptr< Behavior > Vkm::Engine::BehaviorRegistry::create |
( |
const std::string & | name | ) |
const |
Create a fresh instance by name.
- Parameters
-
| name | Registered type name. |
- Returns
- The new instance, or nullptr, logged, when the name is unknown.
◆ contains()
| bool Vkm::Engine::BehaviorRegistry::contains |
( |
const std::string & | name | ) |
const |
Report whether name has a registered factory.
- Parameters
-
- Returns
- True if a factory is registered under
name.
◆ names()
| std::vector< std::string > Vkm::Engine::BehaviorRegistry::names |
( |
| ) |
const |
List every registered behavior name, sorted.
- Returns
- Sorted copy of the names.
The documentation for this class was generated from the following file: