summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NewKit/Ref.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-23 04:07:12 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-05-23 04:07:12 +0200
commitfc67c4af554189c941c811486a0b2b21aa3f54ea (patch)
treeddc7677c3bb1072c9b9fb85618b75c8ee172b377 /dev/kernel/NewKit/Ref.h
parentfbd1f65a2cd30b3b4ed3da236398ddcfc437ac47 (diff)
feat!(kernel): Rename NewKit to NeKit.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
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 31ad16f8..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_ptr(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_