Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
Error.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** R-Type
4** File description:
5** Error.cpp
6*/
7
8/*
9** MIT License
10**
11** Copyright (c) 2025 Robin Toillon
12**
13** Permission is hereby granted, free of charge, to any person obtaining
14** a copy of this software and associated documentation files (the
15** "Software"), to deal in the Software without restriction, including
16** without limitation the rights to use, copy, modify, merge, publish,
17** distribute, sublicense, and/or sell copies of the Software, and to
18** permit persons to whom the Software is furnished to do so, subject to
19** the following conditions:
20**
21** The above copyright notice and this permission notice shall be
22** included in all copies or substantial portions of the Software.
23**
24** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31*/
32
41#include "RType/Error.hpp"
42
43namespace rtp
44{
46 // Private API
48
49 namespace
50 {
51 class RTypeCategory : public std::error_category {
52 public:
53 const char *name(void) const noexcept override
54 {
55 return "RTypeEngine";
56 }
57
58 std::string message(int ev) const override
59 {
60 return std::string(toString(static_cast<ErrorCode>(ev)));
61 }
62 };
63 }
64
65 Error::Error(ErrorCode code, log::Level severity, std::string_view msg)
66 : _code(code), _severity(severity), _message(msg)
67 {
68 }
69
71 // Public API
73
74 const std::error_category &rtype_category(void) noexcept
75 {
76 static const RTypeCategory instance;
77 return instance;
78 }
79
80 std::error_code make_error_code(ErrorCode e) noexcept
81 {
82 return {static_cast<int>(e), rtype_category()};
83 }
84
85 ErrorCode Error::code(void) const noexcept
86 {
87 return this->_code;
88 }
89
90 log::Level Error::severity(void) const noexcept
91 {
92 return this->_severity;
93 }
94
95 std::uint8_t Error::retryCount(void) const noexcept
96 {
97 return this->_retryCount;
98 }
99
100 auto Error::message(void) const noexcept
101 -> std::string_view
102 {
103 return this->_message;
104 }
105
106 std::uint8_t Error::incrementRetryCount(void) noexcept
107 {
108 return this->_retryCount++;
109 }
110}
Error handling system with categorized error codes.
Error(ErrorCode code, log::Level severity, std::string_view msg)
Private constructor for error creation.
Definition Error.cpp:65
std::uint8_t retryCount(void) const noexcept
Get the current retry count.
Definition Error.cpp:95
log::Level severity(void) const noexcept
Get the severity level of this error.
Definition Error.cpp:90
auto message(void) const noexcept -> std::string_view
Get the error message.
Definition Error.cpp:100
ErrorCode code(void) const noexcept
Get the error code.
Definition Error.cpp:85
std::uint8_t incrementRetryCount(void) noexcept
Increment the retry counter.
Definition Error.cpp:106
Level
Severity levels for log messages.
Definition LogLevel.hpp:57
ErrorCode
Enumeration of all possible error codes in the RType engine.
Definition Error.hpp:68
std::error_code make_error_code(ErrorCode e) noexcept
Create a std::error_code from an ErrorCode.
Definition Error.cpp:80
const std::error_category & rtype_category(void) noexcept
Get the RType error category for std::error_code integration.
Definition Error.cpp:74
constexpr std::string_view toString(ErrorCode e) noexcept
Convert an ErrorCode to its string representation.