summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/NewKit/ErrorOr.hxx
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
commitf3d931aa7cfaf96baef8383b59a8938779541ee7 (patch)
treefdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Kernel/NewKit/ErrorOr.hxx
parent86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff)
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/NewKit/ErrorOr.hxx')
-rw-r--r--dev/Kernel/NewKit/ErrorOr.hxx72
1 files changed, 72 insertions, 0 deletions
diff --git a/dev/Kernel/NewKit/ErrorOr.hxx b/dev/Kernel/NewKit/ErrorOr.hxx
new file mode 100644
index 00000000..ae2763b2
--- /dev/null
+++ b/dev/Kernel/NewKit/ErrorOr.hxx
@@ -0,0 +1,72 @@
+/*
+ * ========================================================
+ *
+ * Kernel
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+
+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, true)
+ {
+ }
+
+ 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