Explorar el Código

fixup! hle: kernel: Add initial impl. of KAutoObject.

bunnei hace 5 años
padre
commit
25538db150
Se han modificado 1 ficheros con 46 adiciones y 46 borrados
  1. 46 46
      src/core/hle/kernel/k_auto_object.h

+ 46 - 46
src/core/hle/kernel/k_auto_object.h

@@ -5,6 +5,7 @@
 #pragma once
 #pragma once
 
 
 #include <atomic>
 #include <atomic>
+#include <string>
 
 
 #include "common/assert.h"
 #include "common/assert.h"
 #include "common/common_funcs.h"
 #include "common/common_funcs.h"
@@ -45,19 +46,15 @@ public:
         return GetStaticTypeName();                                                                \
         return GetStaticTypeName();                                                                \
     }                                                                                              \
     }                                                                                              \
                                                                                                    \
                                                                                                    \
-private:
+private:                                                                                           \
+    constexpr bool operator!=(const TypeObj& rhs)
 
 
 class KAutoObject {
 class KAutoObject {
 protected:
 protected:
     class TypeObj {
     class TypeObj {
-    private:
-        const char* m_name;
-        ClassTokenType m_class_token;
-
     public:
     public:
         constexpr explicit TypeObj(const char* n, ClassTokenType tok)
         constexpr explicit TypeObj(const char* n, ClassTokenType tok)
-            : m_name(n), m_class_token(tok) { // ...
-        }
+            : m_name(n), m_class_token(tok) {}
 
 
         constexpr const char* GetName() const {
         constexpr const char* GetName() const {
             return m_name;
             return m_name;
@@ -66,35 +63,31 @@ protected:
             return m_class_token;
             return m_class_token;
         }
         }
 
 
-        constexpr bool operator==(const TypeObj& rhs) {
+        constexpr bool operator==(const TypeObj& rhs) const {
             return this->GetClassToken() == rhs.GetClassToken();
             return this->GetClassToken() == rhs.GetClassToken();
         }
         }
 
 
-        constexpr bool operator!=(const TypeObj& rhs) {
+        constexpr bool operator!=(const TypeObj& rhs) const {
             return this->GetClassToken() != rhs.GetClassToken();
             return this->GetClassToken() != rhs.GetClassToken();
         }
         }
 
 
-        constexpr bool IsDerivedFrom(const TypeObj& rhs) {
+        constexpr bool IsDerivedFrom(const TypeObj& rhs) const {
             return (this->GetClassToken() | rhs.GetClassToken()) == this->GetClassToken();
             return (this->GetClassToken() | rhs.GetClassToken()) == this->GetClassToken();
         }
         }
+
+    private:
+        const char* m_name;
+        ClassTokenType m_class_token;
     };
     };
 
 
 private:
 private:
     KERNEL_AUTOOBJECT_TRAITS(KAutoObject, KAutoObject);
     KERNEL_AUTOOBJECT_TRAITS(KAutoObject, KAutoObject);
 
 
-private:
-    std::atomic<u32> m_ref_count{};
-
-protected:
-    KernelCore& kernel;
-    std::string name;
-
-public:
-    static KAutoObject* Create(KAutoObject* ptr);
-
 public:
 public:
     explicit KAutoObject(KernelCore& kernel_) : kernel(kernel_) {}
     explicit KAutoObject(KernelCore& kernel_) : kernel(kernel_) {}
-    virtual ~KAutoObject() {}
+    virtual ~KAutoObject() = default;
+
+    static KAutoObject* Create(KAutoObject* ptr);
 
 
     // Destroy is responsible for destroying the auto object's resources when ref_count hits zero.
     // Destroy is responsible for destroying the auto object's resources when ref_count hits zero.
     virtual void Destroy() {
     virtual void Destroy() {
@@ -122,8 +115,8 @@ public:
 
 
     template <typename Derived>
     template <typename Derived>
     Derived DynamicCast() {
     Derived DynamicCast() {
-        static_assert(std::is_pointer<Derived>::value);
-        using DerivedType = typename std::remove_pointer<Derived>::type;
+        static_assert(std::is_pointer_v<Derived>);
+        using DerivedType = std::remove_pointer_t<Derived>;
 
 
         if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
         if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
             return static_cast<Derived>(this);
             return static_cast<Derived>(this);
@@ -134,8 +127,8 @@ public:
 
 
     template <typename Derived>
     template <typename Derived>
     const Derived DynamicCast() const {
     const Derived DynamicCast() const {
-        static_assert(std::is_pointer<Derived>::value);
-        using DerivedType = typename std::remove_pointer<Derived>::type;
+        static_assert(std::is_pointer_v<Derived>);
+        using DerivedType = std::remove_pointer_t<Derived>;
 
 
         if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
         if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
             return static_cast<Derived>(this);
             return static_cast<Derived>(this);
@@ -171,20 +164,18 @@ public:
             this->Destroy();
             this->Destroy();
         }
         }
     }
     }
-};
-
-class KAutoObjectWithListContainer;
 
 
-class KAutoObjectWithList : public KAutoObject {
-private:
-    friend class KAutoObjectWithListContainer;
+protected:
+    KernelCore& kernel;
+    std::string name;
 
 
 private:
 private:
-    Common::IntrusiveRedBlackTreeNode list_node;
+    std::atomic<u32> m_ref_count{};
+};
 
 
-protected:
-    KernelCore& kernel;
+class KAutoObjectWithListContainer;
 
 
+class KAutoObjectWithList : public KAutoObject {
 public:
 public:
     explicit KAutoObjectWithList(KernelCore& kernel_) : KAutoObject(kernel_), kernel(kernel_) {}
     explicit KAutoObjectWithList(KernelCore& kernel_) : KAutoObject(kernel_), kernel(kernel_) {}
 
 
@@ -209,23 +200,20 @@ public:
     virtual const std::string& GetName() const {
     virtual const std::string& GetName() const {
         return name;
         return name;
     }
     }
-};
-
-template <typename T>
-class KScopedAutoObject {
-    YUZU_NON_COPYABLE(KScopedAutoObject);
 
 
 private:
 private:
-    template <typename U>
-    friend class KScopedAutoObject;
+    friend class KAutoObjectWithListContainer;
 
 
 private:
 private:
-    T* m_obj{};
+    Common::IntrusiveRedBlackTreeNode list_node;
 
 
-private:
-    constexpr void Swap(KScopedAutoObject& rhs) {
-        std::swap(m_obj, rhs.m_obj);
-    }
+protected:
+    KernelCore& kernel;
+};
+
+template <typename T>
+class KScopedAutoObject {
+    YUZU_NON_COPYABLE(KScopedAutoObject);
 
 
 public:
 public:
     constexpr KScopedAutoObject() = default;
     constexpr KScopedAutoObject() = default;
@@ -301,6 +289,18 @@ public:
     constexpr bool IsNotNull() const {
     constexpr bool IsNotNull() const {
         return m_obj != nullptr;
         return m_obj != nullptr;
     }
     }
+
+private:
+    template <typename U>
+    friend class KScopedAutoObject;
+
+private:
+    T* m_obj{};
+
+private:
+    constexpr void Swap(KScopedAutoObject& rhs) noexcept {
+        std::swap(m_obj, rhs.m_obj);
+    }
 };
 };
 
 
 } // namespace Kernel
 } // namespace Kernel