summaryrefslogtreecommitdiff
path: root/LibCore/CObject.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-05-27 04:06:01 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-05-27 04:06:01 +0200
commit0c85d3dba9634f22634ab5c93fb67db4d2df3dcc (patch)
tree38a268652e069c97993527c82210e75e63fd48f3 /LibCore/CObject.h
parent723ba91f74a60fae688d5647a4c5763db7bc9b5d (diff)
downloadserenity-0c85d3dba9634f22634ab5c93fb67db4d2df3dcc.zip
LibCore+LibGUI: Add is<T>(CObject&) and to<T>(CObject&) helpers.
Diffstat (limited to 'LibCore/CObject.h')
-rw-r--r--LibCore/CObject.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/LibCore/CObject.h b/LibCore/CObject.h
index 4f12811812..92fe544edd 100644
--- a/LibCore/CObject.h
+++ b/LibCore/CObject.h
@@ -58,3 +58,20 @@ private:
bool m_widget { false };
Vector<CObject*> m_children;
};
+
+template<typename T> inline bool is(const CObject&) { return false; }
+template<> inline bool is<CObject>(const CObject&) { return true; }
+
+template<typename T>
+inline T& to(CObject& object)
+{
+ ASSERT(is<T>(object));
+ return static_cast<T&>(object);
+}
+
+template<typename T>
+inline const T& to(const CObject& object)
+{
+ ASSERT(is<T>(object));
+ return static_cast<const T&>(object);
+}