From fe6474e69273a033a22f7961228b75a9eb967ab7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 26 Jul 2020 17:15:51 +0200 Subject: [PATCH] Kernel: Switch to using AK::is and AK::downcast --- Kernel/VM/AnonymousVMObject.h | 10 ++++------ Kernel/VM/ContiguousVMObject.h | 8 +++----- Kernel/VM/InodeVMObject.h | 8 +++----- Kernel/VM/PurgeableVMObject.h | 8 +++----- Kernel/VM/VMObject.h | 11 +---------- 5 files changed, 14 insertions(+), 31 deletions(-) diff --git a/Kernel/VM/AnonymousVMObject.h b/Kernel/VM/AnonymousVMObject.h index 13b7222f80..1a0f5f13ba 100644 --- a/Kernel/VM/AnonymousVMObject.h +++ b/Kernel/VM/AnonymousVMObject.h @@ -26,8 +26,8 @@ #pragma once -#include #include +#include namespace Kernel { @@ -56,10 +56,8 @@ private: virtual bool is_anonymous() const override { return true; } }; -template<> -inline bool is(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() diff --git a/Kernel/VM/ContiguousVMObject.h b/Kernel/VM/ContiguousVMObject.h index 84f54ef4dc..0693bf67aa 100644 --- a/Kernel/VM/ContiguousVMObject.h +++ b/Kernel/VM/ContiguousVMObject.h @@ -51,10 +51,8 @@ private: virtual bool is_contiguous() const override { return true; } }; -template<> -inline bool is(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() diff --git a/Kernel/VM/InodeVMObject.h b/Kernel/VM/InodeVMObject.h index ca5f0af6e7..727199ff7e 100644 --- a/Kernel/VM/InodeVMObject.h +++ b/Kernel/VM/InodeVMObject.h @@ -66,10 +66,8 @@ protected: Bitmap m_dirty_pages; }; -template<> -inline bool is(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() diff --git a/Kernel/VM/PurgeableVMObject.h b/Kernel/VM/PurgeableVMObject.h index 0b63801284..846222deab 100644 --- a/Kernel/VM/PurgeableVMObject.h +++ b/Kernel/VM/PurgeableVMObject.h @@ -64,10 +64,8 @@ private: bool m_volatile { false }; }; -template<> -inline bool is(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() diff --git a/Kernel/VM/VMObject.h b/Kernel/VM/VMObject.h index bb0314301c..e7043f03c1 100644 --- a/Kernel/VM/VMObject.h +++ b/Kernel/VM/VMObject.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -84,14 +85,4 @@ private: VMObject(VMObject&&) = delete; }; -template -inline bool is(const VMObject&) { return false; } - -template -inline T& to(VMObject& object) -{ - ASSERT(is::Type>(object)); - return static_cast(object); -} - }