summaryrefslogtreecommitdiffhomepage
path: root/Private/NewKit
diff options
context:
space:
mode:
Diffstat (limited to 'Private/NewKit')
-rw-r--r--Private/NewKit/OwnPtr.hpp77
1 files changed, 40 insertions, 37 deletions
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 <NewKit/Defines.hpp>
-#include <NewKit/RuntimeCheck.hpp>
#include <NewKit/Ref.hpp>
+#include <NewKit/RuntimeCheck.hpp>
-namespace HCore
-{
-template <typename T> class OwnPtr;
+namespace HCore {
+template <typename T>
+class OwnPtr;
-template <typename T> class NonNullRefPtr;
+template <typename T>
+class NonNullRefPtr;
-template <typename T> class OwnPtr final
-{
- public:
- OwnPtr() {}
- ~OwnPtr() { this->Delete(); }
+template <typename T>
+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 <typename... Args> bool New(Args &&...arg)
- {
- m_Cls = new T(arg...);
- return m_Cls;
+ public:
+ template <typename... Args>
+ 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<T> AsRef() { return Ref<T>(m_Cls); }
+ Ref<T> AsRef() { return Ref<T>(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 <typename T, typename... Args> OwnPtr<T> make_ptr(Args... args)
-{
- OwnPtr<T> ret;
- ret.template New<Args...>(forward(args)...);
- MUST_PASS(ret);
+template <typename T, typename... Args>
+OwnPtr<T> make_ptr(Args... args) {
+ OwnPtr<T> ret;
+ ret.template New<Args...>(forward(args)...);
+ MUST_PASS(ret);
- return ret;
+ return ret;
}
-} // namespace HCore
+} // namespace HCore