From 83d870e58457a1d335a1d9b9966a6a1887cc297b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 24 Nov 2025 03:02:43 +0100 Subject: feat! breaking changes on kernel sources. Signed-off-by: Amlal El Mahrouss --- src/kernel/NeKit/OwnPtr.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/kernel/NeKit/OwnPtr.h (limited to 'src/kernel/NeKit/OwnPtr.h') diff --git a/src/kernel/NeKit/OwnPtr.h b/src/kernel/NeKit/OwnPtr.h new file mode 100644 index 00000000..c8ceb1a2 --- /dev/null +++ b/src/kernel/NeKit/OwnPtr.h @@ -0,0 +1,67 @@ + +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#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)...); + + return ret; +} +} // namespace Kernel -- cgit v1.2.3