From b0554a3dd0ea14d2d84f3d0e9fa7f22ff1c04175 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Wed, 31 Jul 2024 15:53:21 +0200 Subject: Basic Arg parsing support --- modules/core/c++/error.cpp | 6 ++++++ modules/core/c++/error.hpp | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) (limited to 'modules/core') 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(code_)} , is_critical_{is_critical__}, error_message_{msg}{} + error::error(error::code code_, bool is_critical__, std::string&& msg): + error_code_{static_cast(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 #include +#include #include #include #include @@ -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 error make_error(){ error make_error(error::code code, const std::string_view &generic); +struct error_builder { +private: + std::function func_; +public: + template + error_builder(Func&& func__): + func_{std::move(func__)} + {} + + template + error make_error(const std::string& generic){ + try{ + std::string err_str = func_(); + error::code id = impl::get_template_id(); + func_ = [](){return "";}; + return error{id, T::is_critical, std::move(err_str)}; + }catch(const std::exception&){} + return make_error(generic); + } +}; + +template +error_builder build_error(Func&& func){ + return error_builder{std::move(func)}; +} namespace err { struct no_error { -- cgit v1.2.3