summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NewKit/Ref.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/NewKit/Ref.h
parentd608230b1350b064ceb01e6572519b108f6139b0 (diff)
parent3167f59dbb401d6a79b1524537e04218baf49ee3 (diff)
Merge pull request #32 from nekernel-org/dev
0.0.2e3
Diffstat (limited to 'dev/kernel/NewKit/Ref.h')
-rw-r--r--dev/kernel/NewKit/Ref.h79
1 files changed, 0 insertions, 79 deletions
diff --git a/dev/kernel/NewKit/Ref.h b/dev/kernel/NewKit/Ref.h
deleted file mode 100644
index 6737ce09..00000000
--- a/dev/kernel/NewKit/Ref.h
+++ /dev/null
@@ -1,79 +0,0 @@
-
-/* -------------------------------------------
-
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
-
-------------------------------------------- */
-
-#ifndef _NEWKIT_REF_H_
-#define _NEWKIT_REF_H_
-
-#include <KernelKit/MemoryMgr.h>
-#include <NewKit/Defines.h>
-#include <NewKit/KernelPanic.h>
-
-namespace Kernel {
-template <typename T>
-class Ref final {
- public:
- Ref() = default;
-
- ~Ref() {
- if (mm_is_valid_heap(fClass)) delete fClass;
- }
-
- public:
- Ref(T* cls) : fClass(cls) {}
-
- Ref(T cls) : fClass(nullptr) { fClass = new T(cls); }
-
- Ref& operator=(T ref) {
- if (!fClass) return *this;
-
- fClass = &ref;
- return *this;
- }
-
- public:
- T operator->() const {
- MUST_PASS(*fClass);
- return *fClass;
- }
-
- T& Leak() noexcept { return *fClass; }
-
- T& TryLeak() const noexcept {
- MUST_PASS(*fClass);
- return *fClass;
- }
-
- T operator*() { return *fClass; }
-
- operator bool() noexcept { return fClass; }
-
- private:
- T* fClass{nullptr};
-};
-
-template <typename T>
-class NonNullRef final {
- public:
- NonNullRef() = delete;
- NonNullRef(nullPtr) = delete;
-
- NonNullRef(T* ref) : fRef(ref) { MUST_PASS(ref); }
-
- Ref<T>& operator->() {
- MUST_PASS(fRef);
- return fRef;
- }
-
- NonNullRef& operator=(const NonNullRef<T>& ref) = delete;
- NonNullRef(const NonNullRef<T>& ref) = default;
-
- private:
- Ref<T> fRef{nullptr};
-};
-} // namespace Kernel
-
-#endif // ifndef _NEWKIT_REF_H_