/* ======================================== Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. ======================================== */ #pragma once #include #include #include #include namespace Kernel { template class OwnPtr; template class NonNullRefPtr; template class OwnPtr final { public: OwnPtr() = default; ~OwnPtr() { this->Reset(); } 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 Reset() { if (fCls) delete fCls; fCls = nullptr; } T* operator->() const { return fCls; } T* Raw() { return fCls; } Ref AsRef() { return Ref(fCls); } explicit operator bool() { return fCls; } bool operator!() { return !fCls; } private: T* fCls{nullptr}; }; template using OwnOr = ErrorOr>; template inline OwnPtr make_ptr(Args&&... args) { OwnPtr ret; ret.template New(forward(args)...); return ret; } } // namespace Kernel