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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user