17#ifndef _FGE_C_COMMANDHANDLER_HPP_INCLUDED
18#define _FGE_C_COMMANDHANDLER_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_callback.hpp"
22#include "FastEngine/C_property.hpp"
24#include <unordered_map>
27#define FGE_COMMAND_DEFAULT_RESERVE_SIZE 16
36using CommandFunction = fge::CalleeUniquePtr<fge::Property, fge::Object*, fge::Property const&, fge::Scene*>;
37using CommandStaticHelpers =
38 fge::CallbackStaticHelpers<fge::Property, CommandFunction, fge::Object*, fge::Property const&, fge::Scene*>;
50class FGE_API CommandHandler
59 inline CommandData(fge::CommandFunction cmdfunc, std::string_view name) :
60 _func(std::move(cmdfunc)),
64 fge::CommandFunction _func;
68 using CommandDataType = std::vector<CommandData>;
71 CommandHandler(CommandHandler
const& r) =
delete;
72 CommandHandler(CommandHandler&& r)
noexcept =
delete;
74 CommandHandler& operator=(CommandHandler
const& r) =
delete;
75 CommandHandler& operator=(CommandHandler&& r)
noexcept =
delete;
86 bool addCmd(std::string_view name, fge::CommandFunction cmdfunc);
100 bool replaceCmd(std::string_view name, fge::CommandFunction cmdfunc);
135 [[nodiscard]] std::size_t
getCmdIndex(std::string_view name)
const;
142 [[nodiscard]] std::string_view
getCmdName(std::size_t index)
const;
167 CommandDataType g_cmdData;
168 std::unordered_map<std::string_view, std::size_t> g_cmdDataMap;
CommandHandler can implement functions attached to an Object that can be called by others with a name...
Definition C_commandHandler.hpp:51
void delCmd(std::string_view name)
Delete a command from the handler.
CommandDataType const & getCmdList() const
Get the commands list.
bool replaceCmd(std::string_view name, fge::CommandFunction cmdfunc)
Replace a command from the handler.
std::string_view getCmdName(std::size_t index) const
Get the name of a command by its index.
std::size_t getCmdSize() const
Get the number of commands.
fge::Property callCmd(std::string_view name, fge::Object *caller, fge::Property const &arg, fge::Scene *callerScene)
Call a command by its name.
CommandData const * getCmd(std::string_view name) const
Get a command by its name.
void clearCmd()
Clear all commands from the handler.
fge::Property callCmd(std::size_t index, fge::Object *caller, fge::Property const &arg, fge::Scene *callerScene)
Call a command by its index.
bool addCmd(std::string_view name, fge::CommandFunction cmdfunc)
Add a new command to the handler.
std::size_t getCmdIndex(std::string_view name) const
Get the index of a command by its name.
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
A class that can store any type of data.
Definition C_property.hpp:54
A scene contain a collection of object and handle them.
Definition C_scene.hpp:465
This struct contain the data of a command, like the name and the function pointer.
Definition C_commandHandler.hpp:58