/* ------------------------------------------- Copyright ZKA Technologies ------------------------------------------- */ #ifndef _NEWKIT_REF_HPP_ #define _NEWKIT_REF_HPP_ #include #include namespace Kernel { 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() noexcept { return fClass; } T& Fetch() const noexcept { return fClass; } T operator*() { return fClass; } bool IsStrong() const { return fStrong; } operator bool() noexcept { return fStrong; } private: T fClass; bool fStrong{false}; }; template class NonNullRef final { public: NonNullRef() = delete; NonNullRef(nullPtr) = delete; NonNullRef(T* ref) : fRef(ref, true) { MUST_PASS(ref != nullptr); } Ref& operator->() { MUST_PASS(fRef); return fRef; } NonNullRef& operator=(const NonNullRef& ref) = delete; NonNullRef(const NonNullRef& ref) = default; private: Ref fRef{nullptr}; }; } // namespace Kernel #endif // ifndef _NEWKIT_REF_HPP_