summaryrefslogtreecommitdiff
path: root/modules/core
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-01-06 17:27:08 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-01-06 17:27:08 +0100
commit8f56be892fe95bbd7b533c9701e68d46f69351c9 (patch)
treede117d7a2f8083237eb9df6203c9bee2b697a30d /modules/core
parent70a3abcb3aad4c5e74b4b9fa6ac76508ac157f55 (diff)
core: Adding comments to error
Diffstat (limited to 'modules/core')
-rw-r--r--modules/core/c++/error.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/modules/core/c++/error.h b/modules/core/c++/error.h
index e816734..581782d 100644
--- a/modules/core/c++/error.h
+++ b/modules/core/c++/error.h
@@ -19,10 +19,22 @@ namespace saw {
*/
class error {
public:
+ /**
+ * Type alias
+ */
using code = uint32_t;
private:
+ /**
+ * Type representing the error code used to distinguish the different error types
+ */
code error_code_;
+ /**
+ * Helper variable for ease of checking if it's a critical error.
+ */
bool is_critical_;
+ /**
+ * Member holding the message. It's a variant for edge cases where we are out of memory.
+ */
std::variant<std::string_view, std::string> error_message_;
public:
@@ -34,13 +46,29 @@ public:
error &operator=(error &&) = default;
+ /**
+ * Returns a string view to the message
+ */
const std::string_view get_message() const;
+ /**
+ * Returns a string view which describes which error this is.
+ */
const std::string_view get_category() const;
+ /**
+ * Checks if it's an error at all, since 0 is reserved for no error.
+ */
bool failed() const;
+ /**
+ * Checks if the error is critical.
+ */
bool is_critical() const;
+
+ /**
+ * Checks if the error is recoverable.
+ */
bool is_recoverable() const;
/**
@@ -48,17 +76,29 @@ public:
*/
error copy_error() const;
+ /**
+ * Return the id.
+ */
code get_id() const;
+ /**
+ * Provide an error struct and check if it matches the type
+ */
template<typename T>
bool is_type() const;
};
+/**
+ * Class which is basically a variant. Replaces exceptions
+ */
template<typename T>
class error_or;
namespace impl {
+/**
+ * Internal registry for all error types. Is generated dynamically.
+ */
class error_registry {
private:
struct error_info {
@@ -104,6 +144,13 @@ error::code get_template_id(){
}
}
+/**
+ * Helper function since changing returns between void_t{} and make_error<...>() is a bit annoying.
+ */
+void_t make_void(){
+ return {};
+}
+
template<typename T> error make_error(const std::string_view& generic){
error::code id = impl::get_template_id<T>();