aboutsummaryrefslogtreecommitdiff
path: root/include/Result.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-08 00:49:15 +0100
committerdec05eba <dec05eba@protonmail.com>2017-12-08 00:50:04 +0100
commitbf24f6fc48b4eebb06cdcd7029d1d31d4c6028dd (patch)
treeb9cb68dc44e002586a1e09aeb60bb42f75258758 /include/Result.hpp
parent3fc89b69ff3fc937a0cde32c2fae9ce3b3cf1ebc (diff)
Added loading of project file and file validations
Next up: parse project.conf file
Diffstat (limited to 'include/Result.hpp')
-rw-r--r--include/Result.hpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/Result.hpp b/include/Result.hpp
new file mode 100644
index 0000000..31f9e4d
--- /dev/null
+++ b/include/Result.hpp
@@ -0,0 +1,45 @@
+#ifndef SIBS_RESULT_HPP
+#define SIBS_RESULT_HPP
+
+#include <cassert>
+
+namespace sibs
+{
+ template <typename T>
+ class Result
+ {
+ public:
+ static Result Ok(const T &value)
+ {
+ return Result(value);
+ }
+
+ static Result Err(const char *errMsg)
+ {
+ return Result(errMsg);
+ }
+
+ bool isOk() const { return !errMsg; }
+ bool isErr() const { return errMsg; }
+
+ T& unwrap()
+ {
+ assert(isOk());
+ return value;
+ }
+
+ const char *getErrMsg() const
+ {
+ assert(isErr());
+ return errMsg;
+ }
+ private:
+ Result(const T &_value) : value(_value), errMsg(nullptr){}
+ Result(const char *_errMsg) : errMsg(_errMsg){}
+ private:
+ T value;
+ const char *errMsg;
+ };
+}
+
+#endif //SIBS_RESULT_HPP