Browse Source

Kernel: Switch to using AK::is and AK::downcast

Andreas Kling 5 years ago
parent
commit
fe6474e692

+ 4 - 6
Kernel/VM/AnonymousVMObject.h

@@ -26,8 +26,8 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <Kernel/VM/VMObject.h>
 #include <Kernel/PhysicalAddress.h>
 #include <Kernel/PhysicalAddress.h>
+#include <Kernel/VM/VMObject.h>
 
 
 namespace Kernel {
 namespace Kernel {
 
 
@@ -56,10 +56,8 @@ private:
     virtual bool is_anonymous() const override { return true; }
     virtual bool is_anonymous() const override { return true; }
 };
 };
 
 
-template<>
-inline bool is<AnonymousVMObject>(const VMObject& vmobject)
-{
-    return vmobject.is_anonymous();
 }
 }
 
 
-}
+AK_BEGIN_TYPE_TRAITS(Kernel::AnonymousVMObject)
+static bool is_type(const Kernel::VMObject& vmobject) { return vmobject.is_anonymous(); }
+AK_END_TYPE_TRAITS()

+ 3 - 5
Kernel/VM/ContiguousVMObject.h

@@ -51,10 +51,8 @@ private:
     virtual bool is_contiguous() const override { return true; }
     virtual bool is_contiguous() const override { return true; }
 };
 };
 
 
-template<>
-inline bool is<ContiguousVMObject>(const VMObject& vmobject)
-{
-    return vmobject.is_contiguous();
 }
 }
 
 
-}
+AK_BEGIN_TYPE_TRAITS(Kernel::ContiguousVMObject)
+static bool is_type(const Kernel::VMObject& vmobject) { return vmobject.is_contiguous(); }
+AK_END_TYPE_TRAITS()

+ 3 - 5
Kernel/VM/InodeVMObject.h

@@ -66,10 +66,8 @@ protected:
     Bitmap m_dirty_pages;
     Bitmap m_dirty_pages;
 };
 };
 
 
-template<>
-inline bool is<InodeVMObject>(const VMObject& vmobject)
-{
-    return vmobject.is_inode();
 }
 }
 
 
-}
+AK_BEGIN_TYPE_TRAITS(Kernel::InodeVMObject)
+static bool is_type(const Kernel::VMObject& vmobject) { return vmobject.is_inode(); }
+AK_END_TYPE_TRAITS()

+ 3 - 5
Kernel/VM/PurgeableVMObject.h

@@ -64,10 +64,8 @@ private:
     bool m_volatile { false };
     bool m_volatile { false };
 };
 };
 
 
-template<>
-inline bool is<PurgeableVMObject>(const VMObject& vmobject)
-{
-    return vmobject.is_purgeable();
 }
 }
 
 
-}
+AK_BEGIN_TYPE_TRAITS(Kernel::PurgeableVMObject)
+static bool is_type(const Kernel::VMObject& vmobject) { return vmobject.is_purgeable(); }
+AK_END_TYPE_TRAITS()

+ 1 - 10
Kernel/VM/VMObject.h

@@ -30,6 +30,7 @@
 #include <AK/InlineLinkedList.h>
 #include <AK/InlineLinkedList.h>
 #include <AK/RefCounted.h>
 #include <AK/RefCounted.h>
 #include <AK/RefPtr.h>
 #include <AK/RefPtr.h>
+#include <AK/TypeCasts.h>
 #include <AK/Weakable.h>
 #include <AK/Weakable.h>
 #include <Kernel/Lock.h>
 #include <Kernel/Lock.h>
 
 
@@ -84,14 +85,4 @@ private:
     VMObject(VMObject&&) = delete;
     VMObject(VMObject&&) = delete;
 };
 };
 
 
-template<typename T>
-inline bool is(const VMObject&) { return false; }
-
-template<typename T>
-inline T& to(VMObject& object)
-{
-    ASSERT(is<typename RemoveConst<T>::Type>(object));
-    return static_cast<T&>(object);
-}
-
 }
 }