diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-04 21:36:54 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-04 21:48:09 +0100 |
| commit | 6cda526bd4efcee31b1ea7405dc46d7985ba64e6 (patch) | |
| tree | f7d138fd5652cdc0e7a2c4918b36d754969d6cf5 /CompilerKit/StdKit/Ref.hpp | |
| parent | 60271b79a91a06772241aed737426f5d097ca533 (diff) | |
masm: fix assembler bug where addr1, 0x0 (add r1, 0x0) doesn't error
out.
cc/ccplus: minor compiler changes, will get to them very soon...
refactor: rename C++Kit to CompilerKit.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerKit/StdKit/Ref.hpp')
| -rw-r--r-- | CompilerKit/StdKit/Ref.hpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/CompilerKit/StdKit/Ref.hpp b/CompilerKit/StdKit/Ref.hpp new file mode 100644 index 0000000..2ca540a --- /dev/null +++ b/CompilerKit/StdKit/Ref.hpp @@ -0,0 +1,89 @@ + +/* + * ======================================================== + * + * CompilerKit + * Copyright Western Company, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <CompilerKit/Defines.hpp> + +namespace CompilerKit +{ + // @author Western Company + // @brief Reference class, refers to a pointer of data in static memory. + template <typename T> + class Ref final + { + public: + Ref() = default; + ~Ref() = default; + + public: + 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; + bool m_Strong{ false }; + + }; + + template <typename T> + class NonNullRef final + { + public: + NonNullRef() = delete; + NonNullRef(nullPtr) = delete; + + 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 CompilerKit |
