FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::CommandHandler Class Reference

CommandHandler is a class that can be used to handle commands. More...

#include <C_commandHandler.hpp>

Inheritance diagram for fge::CommandHandler:
fge::Scene

Classes

struct  CommandData
 This struct contain the data of a command, like the name and the function pointer. More...
 

Public Types

using CommandDataType = std::vector<fge::CommandHandler::CommandData>
 

Public Member Functions

bool addCmd (std::string_view name, fge::CommandHandler *handle, 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::CommandHandler *handle, 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 *caller_scene)
 Call a command by its name.
 
fge::Property callCmd (std::size_t index, fge::Object *caller, fge::Property const &arg, fge::Scene *caller_scene)
 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.
 
fge::CommandHandler::CommandData const * getCmd (std::string_view name) const
 Get a command by its name.
 
std::size_t getCmdSize () const
 Get the number of commands.
 
fge::CommandHandler::CommandDataType const & getCmdList () const
 Get the commands list.
 

Detailed Description

CommandHandler is a class that can be used to handle commands.

A command is a well-defined function signature that can be attributed to an 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.

Member Function Documentation

◆ addCmd()

bool fge::CommandHandler::addCmd ( std::string_view name,
fge::CommandHandler * handle,
fge::CommandFunction cmdfunc )

Add a new command to the handler.

An object should inherit from CommandHandler and add commands to it.

Parameters
nameThe name of the command
handleThe object that will handle the command
cmdfuncThe function pointer of the command
Returns
true if the command was added, false otherwise

◆ callCmd() [1/2]

fge::Property fge::CommandHandler::callCmd ( std::size_t index,
fge::Object * caller,
fge::Property const & arg,
fge::Scene * caller_scene )

Call a command by its index.

Parameters
indexThe index of the command
callerThe object that call the command
argThe arguments of the command
caller_sceneThe scene that contains the caller
Returns
A Property containing the result of the command

◆ callCmd() [2/2]

fge::Property fge::CommandHandler::callCmd ( std::string_view name,
fge::Object * caller,
fge::Property const & arg,
fge::Scene * caller_scene )

Call a command by its name.

Parameters
nameThe name of the command
callerThe object that call the command
argThe arguments of the command
caller_sceneThe 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
nameThe name of the command

◆ getCmd()

fge::CommandHandler::CommandData const * fge::CommandHandler::getCmd ( std::string_view name) const
nodiscard

Get a command by its name.

Parameters
nameThe 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
nameThe 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()

fge::CommandHandler::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
indexThe 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::CommandHandler * handle,
fge::CommandFunction cmdfunc )

Replace a command from the handler.

Parameters
nameThe name of the command
handleThe new object that will handle the command
cmdfuncThe new function pointer of the command
Returns
true if the command was replaced, false otherwise

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