Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Olympe::AtomicTaskRegistry Class Reference

Singleton registry mapping task IDs to factory functions. More...

#include <AtomicTaskRegistry.h>

Public Types

using FactoryFn = std::function< std::unique_ptr< IAtomicTask >()>
 Factory function type: returns a heap-allocated IAtomicTask.
 

Public Member Functions

void Register (const std::string &id, FactoryFn factory)
 Registers a factory function under the given task ID.
 
std::unique_ptr< IAtomicTaskCreate (const std::string &id) const
 Creates a new instance of the task identified by id.
 
bool IsRegistered (const std::string &id) const
 Returns true if a factory is registered for id.
 
std::vector< std::string > GetAllTaskIDs () const
 Returns a vector of all registered task IDs.
 

Static Public Member Functions

static AtomicTaskRegistryGet ()
 Returns the singleton instance.
 

Private Member Functions

 AtomicTaskRegistry ()=default
 

Private Attributes

std::unordered_map< std::string, FactoryFnm_factories
 

Detailed Description

Singleton registry mapping task IDs to factory functions.

Usage:

// Register (done automatically via REGISTER_ATOMIC_TASK macro):
AtomicTaskRegistry::Get().Register("Task_LogMessage",
[]() { return std::unique_ptr<IAtomicTask>(new Task_LogMessage()); });
// Create:
auto task = AtomicTaskRegistry::Get().Create("Task_LogMessage");
if (task) { task->Execute(params); }
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::unique_ptr< IAtomicTask > Create(const std::string &id) const
Creates a new instance of the task identified by id.
static AtomicTaskRegistry & Get()
Returns the singleton instance.
void Register(const std::string &id, FactoryFn factory)
Registers a factory function under the given task ID.
Atomic task that logs the value of the "message" parameter.

Definition at line 46 of file AtomicTaskRegistry.h.

Member Typedef Documentation

◆ FactoryFn

using Olympe::AtomicTaskRegistry::FactoryFn = std::function<std::unique_ptr<IAtomicTask>()>

Factory function type: returns a heap-allocated IAtomicTask.

Definition at line 50 of file AtomicTaskRegistry.h.

Constructor & Destructor Documentation

◆ AtomicTaskRegistry()

Olympe::AtomicTaskRegistry::AtomicTaskRegistry ( )
privatedefault

Member Function Documentation

◆ Create()

std::unique_ptr< IAtomicTask > Olympe::AtomicTaskRegistry::Create ( const std::string &  id) const

Creates a new instance of the task identified by id.

Parameters
idTask type identifier (as registered via Register()).
Returns
A unique_ptr to the new task, or nullptr if id is unknown.

Definition at line 39 of file AtomicTaskRegistry.cpp.

References GetComponentTypeID_Static(), m_factories, and SYSTEM_LOG.

Referenced by Olympe::TaskSystem::ExecuteAtomicTask(), and Olympe::VSGraphExecutor::HandleAtomicTask().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Get()

AtomicTaskRegistry & Olympe::AtomicTaskRegistry::Get ( )
static

Returns the singleton instance.

Definition at line 20 of file AtomicTaskRegistry.cpp.

Referenced by Olympe::TaskSystem::ExecuteAtomicTask(), Olympe::VSGraphExecutor::HandleAtomicTask(), and Olympe::NodeGraphPanel::RenderContextMenu().

+ Here is the caller graph for this function:

◆ GetAllTaskIDs()

std::vector< std::string > Olympe::AtomicTaskRegistry::GetAllTaskIDs ( ) const

Returns a vector of all registered task IDs.

The order of IDs in the returned vector is unspecified. Useful for editor enumeration (e.g. context menus, palette panels).

Returns
Vector of every ID that has been passed to Register().

Definition at line 101 of file AtomicTaskRegistry.cpp.

References GetComponentTypeID_Static(), and m_factories.

Referenced by Olympe::NodeGraphPanel::RenderContextMenu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsRegistered()

bool Olympe::AtomicTaskRegistry::IsRegistered ( const std::string &  id) const

Returns true if a factory is registered for id.

Parameters
idTask type identifier.

Definition at line 92 of file AtomicTaskRegistry.cpp.

References m_factories.

◆ Register()

void Olympe::AtomicTaskRegistry::Register ( const std::string &  id,
FactoryFn  factory 
)

Registers a factory function under the given task ID.

If a factory is already registered for id, it is replaced.

Parameters
idUnique string identifier for the task type.
factoryCallable that produces a new IAtomicTask instance.

Definition at line 30 of file AtomicTaskRegistry.cpp.

References GetComponentTypeID_Static(), and m_factories.

+ Here is the call graph for this function:

Member Data Documentation

◆ m_factories

std::unordered_map<std::string, FactoryFn> Olympe::AtomicTaskRegistry::m_factories
private

Definition at line 95 of file AtomicTaskRegistry.h.

Referenced by Create(), GetAllTaskIDs(), IsRegistered(), and Register().


The documentation for this class was generated from the following files: