2#include "EASTL/initializer_list.h"
3#include "EASTL/string.h"
5#include "EASTL/unordered_map.h"
6#include "EASTL/functional.h"
7#include "..\IO\Logger.hpp"
8#include <source_location>
60 template<
typename Functor>
61 void addFunction(
const eastl::string& name, Functor functor);
78 template<
typename Return,
typename... Arguments>
79 Return
callFunction(
const eastl::string& name, Arguments&&... args);
102 template<
typename Return,
typename... Arguments>
103 eastl::function<Return(Arguments...)>
operator[](
const eastl::string& name);
116 template<
typename Return,
typename... Arguments>
117 eastl::function<Return(Arguments...)>
getFunction(
const eastl::string& name);
120 eastl::unordered_map<eastl::string, eastl::any> functions;
130 template<
typename Functor>
132 FunctionContainer::functions[name] = functor;
140 template<
typename Return,
typename ...Arguments>
142 if (FunctionContainer::functions.find(name) != FunctionContainer::functions.end()) {
143 auto& func = FunctionContainer::functions[name];
144 auto castedFunc = eastl::any_cast<eastl::function<Return(Arguments...)>>(func);
145 return castedFunc(eastl::forward<Arguments>(args)...);
148 MCE_ERROR(
"Function \"{}\" not found! File:", name);
157 template<
typename Return,
typename ...Arguments>
159 if (FunctionContainer::functions.find(name) != FunctionContainer::functions.end()) {
160 return eastl::any_cast<eastl::function<Return(Arguments...)>>(FunctionContainer::functions[name]);
163 MCE_ERROR(
"Function \"{}\" not found! File:", name);
173 template<
typename Return,
typename ...Arguments>
175 if (FunctionContainer::functions.find(name) != FunctionContainer::functions.end()) {
176 return eastl::any_cast<eastl::function<Return(Arguments...)>>(FunctionContainer::functions[name]);
179 MCE_ERROR(
"Function \"{}\" not found! File:", name);
Return callFunction(const eastl::string &name, Arguments &&... args)
Call a stored function by name with the provided arguments.
Definition FunctionContainer.hpp:141
eastl::function< Return(Arguments...)> getFunction(const eastl::string &name)
Retrieve a stored function as an eastl::function.
Definition FunctionContainer.hpp:174
eastl::function< Return(Arguments...)> operator[](const eastl::string &name)
Retrieve a stored function as an eastl::function via operator[].
Definition FunctionContainer.hpp:158
void addFunction(const eastl::string &name, Functor functor)
Add a function to the container.
Definition FunctionContainer.hpp:131
FunctionContainer()=default
Default constructor.
bool findFunction(const eastl::string &name)
Check whether a function with the given name exists in the container.
Definition FunctionContainer.cpp:10
Thread-safe event bus.
Definition QEventBus.hpp:58