FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
reg_manager.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_REG_MANAGER_HPP_INCLUDED
18#define _FGE_REG_MANAGER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21
22#include "FastEngine/object/C_object.hpp"
23#include <memory>
24#include <string>
25
26#define FGE_REG_BADCLASSID std::numeric_limits<fge::reg::ClassId>::max()
27
28namespace fge::reg
29{
30
31using ClassId = uint16_t;
32
34{
35public:
36 BaseStamp() = default;
37 virtual ~BaseStamp() = default;
38
39 [[nodiscard]] virtual fge::Object* createNew() const = 0;
40 [[nodiscard]] virtual fge::Object* duplicate(fge::Object const* obj) const = 0;
41
42 [[nodiscard]] std::string const& getClassName() const { return this->g_className; }
43
44protected:
45 std::string g_className;
46};
47template<class T>
48class Stamp : public BaseStamp
49{
50public:
51 Stamp()
52 {
53 T obj;
54 this->g_className = obj.getClassName();
55 }
56
57 [[nodiscard]] fge::Object* createNew() const final { return new T(); }
58 [[nodiscard]] fge::Object* duplicate(fge::Object const* obj) const final
59 {
60 return new T(*reinterpret_cast<T const*>(obj));
61 }
62};
63
64FGE_API void ClearAll();
65
66FGE_API bool RegisterNewClass(std::unique_ptr<fge::reg::BaseStamp>&& newStamp);
67template<class T>
68inline bool RegisterNewClass()
69{
70 return fge::reg::RegisterNewClass(std::make_unique<fge::reg::Stamp<T>>());
71}
72
73FGE_API bool Check(std::string_view className);
74FGE_API bool Check(fge::reg::ClassId classId);
75
76FGE_API fge::Object* Duplicate(fge::Object const* obj);
77
78FGE_API bool Replace(std::string_view className, std::unique_ptr<fge::reg::BaseStamp>&& newStamp);
79FGE_API bool Replace(fge::reg::ClassId classId, std::unique_ptr<fge::reg::BaseStamp>&& newStamp);
80
81FGE_API std::size_t GetRegisterSize();
82
83FGE_API fge::Object* GetNewClassOf(std::string_view className);
84FGE_API fge::Object* GetNewClassOf(fge::reg::ClassId classId);
85
86FGE_API fge::reg::ClassId GetClassId(std::string_view className);
87FGE_API std::string GetClassName(fge::reg::ClassId classId);
88
89FGE_API fge::reg::BaseStamp* GetStampOf(std::string_view className);
90FGE_API fge::reg::BaseStamp* GetStampOf(fge::reg::ClassId classId);
91
92} // namespace fge::reg
93
94
95#endif // _FGE_REG_MANAGER_HPP_INCLUDED
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
Definition reg_manager.hpp:34
Definition reg_manager.hpp:49