Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
WrappedSystem.ipp
Go to the documentation of this file.
1#include "WrappedSystem.hpp"
2
3namespace Engine {
4template <typename TSystem, typename TErrorCallback>
5WrappedSystem<TSystem, TErrorCallback>::WrappedSystem(TSystem system, TErrorCallback errorCallback)
6 : _system(system), _errorCallback(errorCallback)
7{
10}
11
12template <typename TSystem, typename TErrorCallback>
14{
15 try
16 {
17 return _system(core);
18 }
19 catch (const std::exception &) // NOSONAR
20 {
21 _errorCallback(core);
22 throw;
23 }
24}
25
26template <typename TSystem, typename TErrorCallback>
31
32template <typename TSystem, typename TErrorCallback> std::string WrappedSystem<TSystem, TErrorCallback>::GetName() const
33{
34 return _name;
35}
36
37template <typename TSystem, typename TErrorCallback>
39{
40 if constexpr (std::is_class_v<TSystem>)
41 {
42 return typeid(callable).hash_code();
43 }
44 else
45 {
46 return std::hash<TSystem>{}(callable);
47 }
48}
49
50template <typename TSystem, typename TErrorCallback>
52{
53 if constexpr (std::is_class_v<TSystem>)
54 {
55 return FunctionUtils::DemangleTypeName(typeid(callable));
56 }
57 else
58 {
59 return std::to_string(GetCallableID(callable));
60 }
61}
62} // namespace Engine
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
WrappedSystem(TSystem system, TErrorCallback errorCallback)
Constructor for WrappedSystem.
Definition WrappedSystem.ipp:5
FunctionUtils::FunctionID GetID() const override
Returns the unique ID of the system.
Definition WrappedSystem.ipp:27
std::string _name
Name of the system.
Definition WrappedSystem.hpp:59
static FunctionUtils::FunctionID GetCallableID(const TSystem &callable)
Get the ID of the system.
Definition WrappedSystem.ipp:38
TSystem _system
The wrapped system.
Definition WrappedSystem.hpp:50
static std::string GetCallableName(const TSystem &callable)
Get the name of the system.
Definition WrappedSystem.ipp:51
TErrorCallback _errorCallback
The error callback to be called if the system throws an exception.
Definition WrappedSystem.hpp:53
void operator()(Engine::Core &core) const override
Calls the system.
Definition WrappedSystem.ipp:13
FunctionUtils::FunctionID _id
Unique ID for the system.
Definition WrappedSystem.hpp:56
std::string GetName() const override
Get the name of the system.
Definition WrappedSystem.ipp:32
Definition Core.hpp:17
std::size_t FunctionID
FunctionID class to represent a unique identifier for functions.
Definition FunctionID.hpp:9
std::string DemangleTypeName(const std::type_info &typeInfo)
Definition Demangle.hpp:13