From 468f79b84da2af19e793b760a11c6aa52c60fafd Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 7 Oct 2023 09:36:09 +0200 Subject: [PATCH] Base: templates for type checking ================================= Original idea of Werner: https://github.com/FreeCAD/FreeCAD/pull/10643#issuecomment-1712966545 I really liked this syntax to avoid repetition and even explicit consideration of Types when type checking. I thought it would be a pitty to get it lost. --- src/Base/BaseClass.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Base/BaseClass.h b/src/Base/BaseClass.h index 88b5da6c3b..6d5abd285e 100644 --- a/src/Base/BaseClass.h +++ b/src/Base/BaseClass.h @@ -114,6 +114,18 @@ public: virtual void setPyObject(PyObject *); static void *create(){return nullptr;} + + template + bool is() const + { + return getTypeId() == T::getClassTypeId(); + } + + template + bool isDerivedFrom() const + { + return getTypeId().isDerivedFrom(T::getClassTypeId()); + } private: static Type classTypeId; protected: