CommandHandler can implement functions attached to an Object that can be called by others with a name.
More...
#include <C_commandHandler.hpp>
|
| struct | CommandData |
| | This struct contain the data of a command, like the name and the function pointer. More...
|
|
|
| CommandHandler (CommandHandler const &r)=delete |
|
| CommandHandler (CommandHandler &&r) noexcept=delete |
|
CommandHandler & | operator= (CommandHandler const &r)=delete |
|
CommandHandler & | operator= (CommandHandler &&r) noexcept=delete |
| bool | addCmd (std::string_view name, fge::CommandFunction cmdfunc) |
| | Add a new command to the handler.
|
| void | delCmd (std::string_view name) |
| | Delete a command from the handler.
|
| bool | replaceCmd (std::string_view name, fge::CommandFunction cmdfunc) |
| | Replace a command from the handler.
|
| void | clearCmd () |
| | Clear all commands from the handler.
|
| fge::Property | callCmd (std::string_view name, fge::Object *caller, fge::Property const &arg, fge::Scene *callerScene) |
| | Call a command by its name.
|
| fge::Property | callCmd (std::size_t index, fge::Object *caller, fge::Property const &arg, fge::Scene *callerScene) |
| | Call a command by its index.
|
| std::size_t | getCmdIndex (std::string_view name) const |
| | Get the index of a command by its name.
|
| std::string_view | getCmdName (std::size_t index) const |
| | Get the name of a command by its index.
|
| CommandData const * | getCmd (std::string_view name) const |
| | Get a command by its name.
|
| std::size_t | getCmdSize () const |
| | Get the number of commands.
|
| CommandDataType const & | getCmdList () const |
| | Get the commands list.
|
CommandHandler can implement functions attached to an Object that can be called by others with a name.
A command is a well-defined function signature that can be attributed to a name (string) and be called by another object with ease.
A command is also indexed to avoid sending the command name on a network communication.
◆ addCmd()
| bool fge::CommandHandler::addCmd |
( |
std::string_view | name, |
|
|
fge::CommandFunction | cmdfunc ) |
Add a new command to the handler.
An object should inherit from CommandHandler and add commands to it.
- Parameters
-
| name | The name of the command |
| cmdfunc | The command |
- Returns
- true if the command was added, false otherwise
◆ callCmd() [1/2]
Call a command by its index.
- Parameters
-
| index | The index of the command |
| caller | The object that call the command |
| arg | The arguments of the command |
| callerScene | The scene that contains the caller |
- Returns
- A Property containing the result of the command
◆ callCmd() [2/2]
Call a command by its name.
- Parameters
-
| name | The name of the command |
| caller | The object that call the command |
| arg | The arguments of the command |
| callerScene | The scene that contains the caller |
- Returns
- A Property containing the result of the command
◆ clearCmd()
| void fge::CommandHandler::clearCmd |
( |
| ) |
|
Clear all commands from the handler.
◆ delCmd()
| void fge::CommandHandler::delCmd |
( |
std::string_view | name | ) |
|
Delete a command from the handler.
- Parameters
-
| name | The name of the command |
◆ getCmd()
| CommandData const * fge::CommandHandler::getCmd |
( |
std::string_view | name | ) |
const |
|
nodiscard |
Get a command by its name.
- Parameters
-
| name | The name of the command |
- Returns
- The command or nullptr if the command doesn't exist
◆ getCmdIndex()
| std::size_t fge::CommandHandler::getCmdIndex |
( |
std::string_view | name | ) |
const |
|
nodiscard |
Get the index of a command by its name.
- Parameters
-
| name | The name of the command |
- Returns
- The index of the command or std::numeric_limits<std::size_t>::max() if the command doesn't exist
◆ getCmdList()
| CommandDataType const & fge::CommandHandler::getCmdList |
( |
| ) |
const |
|
nodiscard |
Get the commands list.
- Returns
- The commands list
◆ getCmdName()
| std::string_view fge::CommandHandler::getCmdName |
( |
std::size_t | index | ) |
const |
|
nodiscard |
Get the name of a command by its index.
- Parameters
-
| index | The index of the command |
- Returns
- The name of the command or an empty string if the command doesn't exist
◆ getCmdSize()
| std::size_t fge::CommandHandler::getCmdSize |
( |
| ) |
const |
|
nodiscard |
Get the number of commands.
- Returns
- The number of commands
◆ replaceCmd()
| bool fge::CommandHandler::replaceCmd |
( |
std::string_view | name, |
|
|
fge::CommandFunction | cmdfunc ) |
Replace a command from the handler.
- Parameters
-
| name | The name of the command |
| cmdfunc | The command |
- Returns
- true if the command was replaced, false otherwise
The documentation for this class was generated from the following file: