aboutsummaryrefslogtreecommitdiff
path: root/include/Result.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-12 17:33:03 +0100
committerdec05eba <dec05eba@protonmail.com>2017-12-12 17:34:16 +0100
commitf3b7b7d34b3bf2b1be18914577c96b66dead379a (patch)
treef24a08256bc959929d51045eb49283fcab7e8b54 /include/Result.hpp
parentcfe578ec12198d09a9a89a2e0b40bccaa06aa8ae (diff)
Download and extract missing dependencies from github
Using libcurl and libarchive
Diffstat (limited to 'include/Result.hpp')
-rw-r--r--include/Result.hpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/include/Result.hpp b/include/Result.hpp
index f755b15..eb0aa01 100644
--- a/include/Result.hpp
+++ b/include/Result.hpp
@@ -13,20 +13,29 @@ namespace sibs
static Result Ok(const T &value)
{
Result result(value);
- result.error = false;
+ result.errorCode = 0;
return result;
}
- static Result Err(const std::string &errMsg)
+ template <typename OtherType>
+ static Result Err(const Result<OtherType> &other)
+ {
+ Result result;
+ result.errMsg = other.getErrMsg();
+ result.errorCode = other.getErrorCode();
+ return result;
+ }
+
+ static Result Err(const std::string &errMsg, int errorCode = 1)
{
Result result;
result.errMsg = errMsg;
- result.error = true;
+ result.errorCode = errorCode;
return result;
}
- bool isOk() const { return !error; }
- bool isErr() const { return error; }
+ bool isOk() const { return !errorCode; }
+ bool isErr() const { return errorCode; }
T& unwrap()
{
@@ -39,12 +48,17 @@ namespace sibs
assert(isErr());
return errMsg;
}
+
+ int getErrorCode() const
+ {
+ return errorCode;
+ }
private:
Result(const T &_value = T()) : value(_value) {}
private:
T value;
std::string errMsg;
- bool error;
+ int errorCode;
};
}