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.
This commit is contained in:
Abdullah Tahiri
2023-10-07 09:36:09 +02:00
committed by wwmayer
parent b724c39c4d
commit 468f79b84d

View File

@@ -114,6 +114,18 @@ public:
virtual void setPyObject(PyObject *);
static void *create(){return nullptr;}
template <typename T>
bool is() const
{
return getTypeId() == T::getClassTypeId();
}
template <typename T>
bool isDerivedFrom() const
{
return getTypeId().isDerivedFrom(T::getClassTypeId());
}
private:
static Type classTypeId;
protected: