FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_commandHandler.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_COMMANDHANDLER_HPP_INCLUDED
18#define _FGE_C_COMMANDHANDLER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_property.hpp"
22#include <string>
23#include <unordered_map>
24#include <vector>
25
31#define FGE_CMD_FUNC(x) static_cast<fge::CommandFunction>(x)
32
33namespace fge
34{
35
36class CommandHandler;
37class Scene;
38class Object;
39
40using CommandFunction = fge::Property (CommandHandler::*)(fge::Object* caller,
41 fge::Property const& arg,
42 fge::Scene* caller_scene);
43
54class FGE_API CommandHandler
55{
56public:
62 {
63 fge::CommandHandler* _handle;
64 fge::CommandFunction _func;
65 std::string _name;
66 };
67
68 using CommandDataType = std::vector<fge::CommandHandler::CommandData>;
69
71
82 bool addCmd(std::string_view name, fge::CommandHandler* handle, fge::CommandFunction cmdfunc);
88 void delCmd(std::string_view name);
97 bool replaceCmd(std::string_view name, fge::CommandHandler* handle, fge::CommandFunction cmdfunc);
98
102 void clearCmd();
103
114 callCmd(std::string_view name, fge::Object* caller, fge::Property const& arg, fge::Scene* caller_scene);
124 fge::Property callCmd(std::size_t index, fge::Object* caller, fge::Property const& arg, fge::Scene* caller_scene);
125
132 [[nodiscard]] std::size_t getCmdIndex(std::string_view name) const;
139 [[nodiscard]] std::string_view getCmdName(std::size_t index) const;
140
147 [[nodiscard]] fge::CommandHandler::CommandData const* getCmd(std::string_view name) const;
148
154 [[nodiscard]] std::size_t getCmdSize() const;
155
161 [[nodiscard]] fge::CommandHandler::CommandDataType const& getCmdList() const;
162
163private:
164 fge::CommandHandler::CommandDataType g_cmdData;
165 std::unordered_map<std::string_view, std::size_t> g_cmdDataMap;
166};
167
168} // namespace fge
169
170#endif // _FGE_C_COMMANDHANDLER_HPP_INCLUDED
CommandHandler is a class that can be used to handle commands.
Definition C_commandHandler.hpp:55
void delCmd(std::string_view name)
Delete a command from the handler.
fge::CommandHandler::CommandDataType const & getCmdList() const
Get the commands list.
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::size_t index, fge::Object *caller, fge::Property const &arg, fge::Scene *caller_scene)
Call a command by its index.
bool addCmd(std::string_view name, fge::CommandHandler *handle, fge::CommandFunction cmdfunc)
Add a new command to the handler.
void clearCmd()
Clear all commands from the handler.
bool replaceCmd(std::string_view name, fge::CommandHandler *handle, fge::CommandFunction cmdfunc)
Replace a command from the handler.
std::size_t getCmdIndex(std::string_view name) const
Get the index of a command by its name.
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::CommandHandler::CommandData const * getCmd(std::string_view name) const
Get 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:450
This struct contain the data of a command, like the name and the function pointer.
Definition C_commandHandler.hpp:62