summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NeKit/ErrorOr.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-29 10:51:53 +0200
committerGitHub <noreply@github.com>2025-05-29 10:51:53 +0200
commit5c0bb7ee7b1b0fee02cc179fb21f4c57a61d6c2d (patch)
treecb17577bcdc9714c97a84ce417a075117097f146 /dev/kernel/NeKit/ErrorOr.h
parentd608230b1350b064ceb01e6572519b108f6139b0 (diff)
parent3167f59dbb401d6a79b1524537e04218baf49ee3 (diff)
Merge pull request #32 from nekernel-org/dev
0.0.2e3
Diffstat (limited to 'dev/kernel/NeKit/ErrorOr.h')
-rw-r--r--dev/kernel/NeKit/ErrorOr.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/dev/kernel/NeKit/ErrorOr.h b/dev/kernel/NeKit/ErrorOr.h
new file mode 100644
index 00000000..d7751b7e
--- /dev/null
+++ b/dev/kernel/NeKit/ErrorOr.h
@@ -0,0 +1,56 @@
+/*
+ * ========================================================
+ *
+ * NeKernel
+ * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <NeKit/Defines.h>
+#include <NeKit/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; }
+
+ BOOL HasError() { return this->mId > 0; }
+
+ private:
+ Ref<T> mRef;
+ UInt32 mId{0};
+};
+
+using ErrorOrAny = ErrorOr<voidPtr>;
+
+} // namespace Kernel