/* ------------------------------------------- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ #pragma once #include #include #include namespace Kernel { template class OwnPtr; template class NonNullRefPtr; template class OwnPtr final { public: OwnPtr() { } ~OwnPtr() { this->Delete(); } OwnPtr& operator=(const OwnPtr&) = default; OwnPtr(const OwnPtr&) = default; public: template bool New(Args&&... arg) { if (fCls) { return false; } fCls = new T(arg...); return fCls; } void Delete() { if (fCls) delete fCls; fCls = nullptr; } T* operator->() const { return fCls; } T* Raw() { return fCls; } Ref AsRef() { return Ref(fCls); } operator bool() { return fCls; } bool operator!() { return !fCls; } private: T* fCls; }; template inline OwnPtr mm_make_own_ptr(Args... args) { OwnPtr ret; ret.template New(forward(args)...); MUST_PASS(ret); return ret; } } // namespace Kernel