summaryrefslogtreecommitdiff
path: root/modules/core
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core')
-rw-r--r--modules/core/c++/error.cpp6
-rw-r--r--modules/core/c++/error.hpp27
2 files changed, 33 insertions, 0 deletions
diff --git a/modules/core/c++/error.cpp b/modules/core/c++/error.cpp
index 192cab6..d5132ac 100644
--- a/modules/core/c++/error.cpp
+++ b/modules/core/c++/error.cpp
@@ -9,6 +9,12 @@ error::error(error::code code_, bool is_critical__, const std::string_view &msg)
error_code_{static_cast<error::code>(code_)}
, is_critical_{is_critical__}, error_message_{msg}{}
+ error::error(error::code code_, bool is_critical__, std::string&& msg):
+ error_code_{static_cast<error::code>(code_)},
+ is_critical_{is_critical__},
+ error_message_{std::move(msg)}
+ {}
+
error::error(error &&error)
:
error_code_{std::move(error.error_code_)}
diff --git a/modules/core/c++/error.hpp b/modules/core/c++/error.hpp
index 8439f85..7a5dd8a 100644
--- a/modules/core/c++/error.hpp
+++ b/modules/core/c++/error.hpp
@@ -2,6 +2,7 @@
#include <algorithm>
#include <limits>
+#include <functional>
#include <string>
#include <string_view>
#include <variant>
@@ -40,6 +41,7 @@ private:
public:
error(error::code id, bool is_critical);
error(error::code id, bool is_critical, const std::string_view &msg);
+ error(error::code id, bool is_critical, std::string&& msg);
error(error &&error);
SAW_FORBID_COPY(error);
@@ -158,6 +160,31 @@ template<typename T> error make_error(){
error make_error(error::code code, const std::string_view &generic);
+struct error_builder {
+private:
+ std::function<std::string()> func_;
+public:
+ template<typename Func>
+ error_builder(Func&& func__):
+ func_{std::move(func__)}
+ {}
+
+ template<typename T>
+ error make_error(const std::string& generic){
+ try{
+ std::string err_str = func_();
+ error::code id = impl::get_template_id<T>();
+ func_ = [](){return "";};
+ return error{id, T::is_critical, std::move(err_str)};
+ }catch(const std::exception&){}
+ return make_error<T>(generic);
+ }
+};
+
+template<typename Func>
+error_builder build_error(Func&& func){
+ return error_builder{std::move(func)};
+}
namespace err {
struct no_error {