diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-12-21 21:59:13 +0100 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-12-21 21:59:45 +0100 |
| commit | 610f91d87152cbe48d3054fcf437d8239da6ef35 (patch) | |
| tree | a386f7047ab73d088169ab2371ddc6ffe8020f1c /dev/Kernel/NewKit/ErrorOr.h | |
| parent | 509fcca5986651c8ba712fb395f8498f2dea4109 (diff) | |
IMP: :boom: Breaking changes some checks are needed to be done.
Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/NewKit/ErrorOr.h')
| -rw-r--r-- | dev/Kernel/NewKit/ErrorOr.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/dev/Kernel/NewKit/ErrorOr.h b/dev/Kernel/NewKit/ErrorOr.h new file mode 100644 index 00000000..c33e6f2b --- /dev/null +++ b/dev/Kernel/NewKit/ErrorOr.h @@ -0,0 +1,77 @@ +/* + * ======================================================== + * + * ZKA + * Copyright (C) 2024, TQ B.V, all rights reserved., all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <NewKit/Defines.h> +#include <NewKit/Ref.h> + +namespace Kernel +{ + 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) + { + } + + 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 Kernel |
