diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
| commit | 5339d016c07bf717ee388f4feb73544087324af0 (patch) | |
| tree | 94be6f67ed626091f24aee24ec3b3be03d01e4e7 /NewKit/ErrorOr.hpp | |
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'NewKit/ErrorOr.hpp')
| -rw-r--r-- | NewKit/ErrorOr.hpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/NewKit/ErrorOr.hpp b/NewKit/ErrorOr.hpp new file mode 100644 index 00000000..736340c7 --- /dev/null +++ b/NewKit/ErrorOr.hpp @@ -0,0 +1,68 @@ +/* +* ======================================================== +* +* hCore +* Copyright Mahrouss Logic, all rights reserved. +* +* ======================================================== +*/ + +#pragma once + +#include <NewKit/Defines.hpp> +#include <NewKit/Ref.hpp> + +namespace hCore +{ +using ErrorT = UInt; + +template <typename T> class ErrorOr final +{ + public: + ErrorOr() = default; + ~ErrorOr() = default; + + public: + explicit ErrorOr(Int32 err) + : mId(err) + {} + + explicit ErrorOr(nullPtr Null) + {} + + explicit ErrorOr(T Class) + : mRef(Class) + {} + + ErrorOr &operator=(const ErrorOr &) = default; + ErrorOr(const ErrorOr &) = default; + + ErrorOr &operator=(const Ref<T> &refErr) + { + mRef = refErr; + return *this; + } + + Ref<T> Leak() + { + return mRef; + } + + Int32 Error() + { + return mId; + } + + operator bool() + { + return mRef; + } + + private: + Ref<T> mRef; + Int32 mId{0}; +}; + +using ErrorOrAny = ErrorOr<voidPtr>; + +} // namespace hCore |
