diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-25 13:14:01 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-25 13:14:01 +0200 |
| commit | 20042235d1f53ae428aa154e64afdbae5d8d91ad (patch) | |
| tree | 6ea42d1b30505a57301f8ff2916c78ce94ff6eaf /dev/LibCompiler/Ref.h | |
| parent | 0561a8d0a6ae7588309a6e3513bbfeeef5f0aa15 (diff) | |
meta: update .clang-format, format codebase.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/LibCompiler/Ref.h')
| -rw-r--r-- | dev/LibCompiler/Ref.h | 150 |
1 files changed, 61 insertions, 89 deletions
diff --git a/dev/LibCompiler/Ref.h b/dev/LibCompiler/Ref.h index 117083c..c5188b5 100644 --- a/dev/LibCompiler/Ref.h +++ b/dev/LibCompiler/Ref.h @@ -12,92 +12,64 @@ #include <LibCompiler/Defines.h> -namespace LibCompiler -{ - // @author EL Mahrouss Amlal - // @brief Reference holder class, refers to a pointer of data in static memory. - template <typename T> - class Ref final - { - public: - explicit Ref() = default; - - ~Ref() - { - if (m_Strong) - { - (*m_Class).~T(); - } - } - - LIBCOMPILER_COPY_DEFAULT(Ref); - - public: - explicit Ref(T cls, const Bool& strong = false) - : m_Class(&cls), m_Strong(strong) - { - } - - Ref& operator=(T ref) - { - *m_Class = ref; - return *this; - } - - public: - T* operator->() const - { - return m_Class; - } - - T& Leak() - { - return *m_Class; - } - - T operator*() - { - return *m_Class; - } - - Bool IsStrong() const - { - return m_Strong; - } - - operator bool() - { - return *m_Class; - } - - private: - T* m_Class{nullptr}; - Bool m_Strong{false}; - }; - - // @author EL Mahrouss Amlal - // @brief Non null Reference holder class, refers to a pointer of data in static memory. - template <typename T> - class NonNullRef final - { - public: - explicit NonNullRef() = delete; - - explicit NonNullRef(T* ref) - : m_Ref(ref, true) - { - } - - Ref<T>& operator->() - { - MUST_PASS(m_Ref); - return m_Ref; - } - - NonNullRef& operator=(const NonNullRef<T>& ref) = delete; - NonNullRef(const NonNullRef<T>& ref) = default; - - private: - Ref<T> m_Ref{nullptr}; - }; -} // namespace LibCompiler +namespace LibCompiler { +// @author EL Mahrouss Amlal +// @brief Reference holder class, refers to a pointer of data in static memory. +template <typename T> +class Ref final { + public: + explicit Ref() = default; + + ~Ref() { + if (m_Strong) { + (*m_Class).~T(); + } + } + + LIBCOMPILER_COPY_DEFAULT(Ref); + + public: + explicit Ref(T cls, const Bool& strong = false) : m_Class(&cls), m_Strong(strong) {} + + Ref& operator=(T ref) { + *m_Class = ref; + return *this; + } + + public: + T* operator->() const { return m_Class; } + + T& Leak() { return *m_Class; } + + T operator*() { return *m_Class; } + + Bool IsStrong() const { return m_Strong; } + + operator bool() { return *m_Class; } + + private: + T* m_Class{nullptr}; + Bool m_Strong{false}; +}; + +// @author EL Mahrouss Amlal +// @brief Non null Reference holder class, refers to a pointer of data in static memory. +template <typename T> +class NonNullRef final { + public: + explicit NonNullRef() = delete; + + explicit NonNullRef(T* ref) : m_Ref(ref, true) {} + + Ref<T>& operator->() { + MUST_PASS(m_Ref); + return m_Ref; + } + + NonNullRef& operator=(const NonNullRef<T>& ref) = delete; + NonNullRef(const NonNullRef<T>& ref) = default; + + private: + Ref<T> m_Ref{nullptr}; +}; +} // namespace LibCompiler |
