From 81144dd05a7c01701c3bf7b04e345dccfef2bf82 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 5 Feb 2024 11:12:42 +0100 Subject: HCR-11: Kernel: Improvements and more. Bootloader: Now works on real hardware (previous commit.) Signed-off-by: Amlal El Mahrouss --- Private/NewKit/OwnPtr.hpp | 77 ++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 37 deletions(-) (limited to 'Private/NewKit') diff --git a/Private/NewKit/OwnPtr.hpp b/Private/NewKit/OwnPtr.hpp index 72a37244..e24eba3e 100644 --- a/Private/NewKit/OwnPtr.hpp +++ b/Private/NewKit/OwnPtr.hpp @@ -11,57 +11,60 @@ #pragma once #include -#include #include +#include -namespace HCore -{ -template class OwnPtr; +namespace HCore { +template +class OwnPtr; -template class NonNullRefPtr; +template +class NonNullRefPtr; -template class OwnPtr final -{ - public: - OwnPtr() {} - ~OwnPtr() { this->Delete(); } +template +class OwnPtr final { + public: + OwnPtr() {} + ~OwnPtr() { this->Delete(); } - OwnPtr &operator=(const OwnPtr &) = default; - OwnPtr(const OwnPtr &) = default; + OwnPtr &operator=(const OwnPtr &) = default; + OwnPtr(const OwnPtr &) = default; - public: - template bool New(Args &&...arg) - { - m_Cls = new T(arg...); - return m_Cls; + public: + template + bool New(Args &&...arg) { + if (m_Cls) { + return false; } - void Delete() - { - if (m_Cls) - delete m_Cls; + m_Cls = new T(arg...); + return m_Cls; + } - m_Cls = nullptr; - } + void Delete() { + if (m_Cls) delete m_Cls; + + m_Cls = nullptr; + } - T *operator->() const { return m_Cls; }; - T *Raw() { return m_Cls; } + T *operator->() const { return m_Cls; }; + T *Raw() { return m_Cls; } - Ref AsRef() { return Ref(m_Cls); } + Ref AsRef() { return Ref(m_Cls); } - operator bool() { return m_Cls; } - bool operator!() { return !m_Cls; } + operator bool() { return m_Cls; } + bool operator!() { return !m_Cls; } - private: - T *m_Cls; + private: + T *m_Cls; }; -template OwnPtr make_ptr(Args... args) -{ - OwnPtr ret; - ret.template New(forward(args)...); - MUST_PASS(ret); +template +OwnPtr make_ptr(Args... args) { + OwnPtr ret; + ret.template New(forward(args)...); + MUST_PASS(ret); - return ret; + return ret; } -} // namespace HCore +} // namespace HCore -- cgit v1.2.3