From 2410f902180b41cf5056f6d230d1b534d1741fd1 Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Tue, 2 May 2023 00:10:35 +0200 Subject: c++: Working on refactoring the error system to make it more extendable --- forstio/core/error.h | 61 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/forstio/core/error.h b/forstio/core/error.h index d8a5ae2..a8d299b 100644 --- a/forstio/core/error.h +++ b/forstio/core/error.h @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -16,21 +17,15 @@ namespace saw { */ class error { public: - enum class code : int16_t { - GenericCritical = -1, - GenericRecoverable = 1, - Disconnected = -99, - Exhausted = -98 - }; - + using code = uint32_t; private: std::variant error_message_; - code error_; + code error_code_; public: error(); - error(const std::string_view &msg, error::code id); - error(std::string &&msg, error::code id); + error(error::code id); + error(error::code id, const std::string_view &msg); error(error &&error); SAW_FORBID_COPY(error); @@ -43,11 +38,55 @@ public: bool is_critical() const; bool is_recoverable() const; + /** + * Replaces the copy constructor. We need this since we want to explicitly copy and not implicitly + */ error copy_error() const; - code id() const; + code get_id() const; }; +namespace impl { + +class error_registry { +private: + struct error_info { + std::string_view description; + }; + + std::vector infos; +public: + error::code search_or_register_id(const std::string_view& desc){ + auto find = std::find_if(infos.begin(), infos.end(), + + ); + + if( find != find.end() ){ + + } + } +}; + +error_registry& get_error_registry(); + +template +error::code get_template_id(){ + static error::code id = 0; + + if(id == 0){ + auto& reg = get_error_registry(); + id = reg.search_or_register_id(typename T::description); + } + + return id; +} + +template error make_error(const std::string_view& generic){ + auto id = get_template_id(); + + return error{id}; +} + error make_error(const std::string_view &generic, error::code c); template -- cgit v1.2.3