summaryrefslogtreecommitdiff
path: root/forstio/core/error.h
diff options
context:
space:
mode:
Diffstat (limited to 'forstio/core/error.h')
-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>