summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius Holeksa <mail@keldu.de>2023-05-02 00:10:35 +0200
committerClaudius Holeksa <mail@keldu.de>2023-05-02 00:10:35 +0200
commit2410f902180b41cf5056f6d230d1b534d1741fd1 (patch)
tree7b81421d8f0b3f7039c05ebfe3bae5fcca01b8c9
parent3c8f8137c6a6317b2b7ae9e64a8b4e0f4de5f680 (diff)
c++: Working on refactoring the error system to make it more extendable
-rw-r--r--forstio/core/error.h61
1 files 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 <string>
#include <string_view>
#include <variant>
+#include <vector>
#include <cassert>
@@ -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<std::string_view, std::string> 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<error_info> 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<typename T>
+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<typename T> error make_error(const std::string_view& generic){
+ auto id = get_template_id<T>();
+
+ return error{id};
+}
+
error make_error(const std::string_view &generic, error::code c);
template <typename Formatter>