From af8a516fc22865abd80d6e26f1541fa3d6bebfdc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 9 May 2024 00:42:44 +0200 Subject: MHR-23: :boom:, refactors. - Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss --- Kernel/NewKit/Ref.hpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Kernel/NewKit/Ref.hpp (limited to 'Kernel/NewKit/Ref.hpp') diff --git a/Kernel/NewKit/Ref.hpp b/Kernel/NewKit/Ref.hpp new file mode 100644 index 00000000..356fcad0 --- /dev/null +++ b/Kernel/NewKit/Ref.hpp @@ -0,0 +1,89 @@ + +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace NewOS +{ + template + class Ref final + { + public: + Ref() = default; + ~Ref() = default; + + public: + Ref(T cls, const bool& strong = false) + : fClass(cls), fStrong(strong) + { + } + + Ref& operator=(T ref) + { + fClass = ref; + return *this; + } + + public: + T operator->() const + { + return fClass; + } + + T& Leak() + { + return fClass; + } + + T operator*() + { + return fClass; + } + + bool IsStrong() const + { + return fStrong; + } + + operator bool() + { + return fStrong; + } + + private: + T fClass; + bool fStrong{false}; + }; + + template + class NonNullRef final + { + public: + NonNullRef() = delete; + NonNullRef(nullPtr) = delete; + + NonNullRef(T* ref) + : fRef(ref, true) + { + } + + Ref& operator->() + { + MUST_PASS(fRef); + return fRef; + } + + NonNullRef& operator=(const NonNullRef& ref) = delete; + NonNullRef(const NonNullRef& ref) = default; + + private: + Ref fRef{nullptr}; + }; +} // namespace NewOS -- cgit v1.2.3