From 09dd11ddf800898c00ecb04a65fb5cd10fb481fa Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 8 May 2024 12:32:41 +0200 Subject: MHR-23: :boom: changes, reworked project tree. Signed-off-by: Amlal El Mahrouss --- NewKernel/NewKit/Ref.hpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 NewKernel/NewKit/Ref.hpp (limited to 'NewKernel/NewKit/Ref.hpp') diff --git a/NewKernel/NewKit/Ref.hpp b/NewKernel/NewKit/Ref.hpp new file mode 100644 index 00000000..b062cf09 --- /dev/null +++ b/NewKernel/NewKit/Ref.hpp @@ -0,0 +1,89 @@ + +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#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