Skip to content

Commit

Permalink
ENH: Add itkVirtualGetNameOfClassMacro + itkOverrideGetNameOfClassMacro
Browse files Browse the repository at this point in the history
Added two new macro's, intended to replace the old `itkTypeMacro` and
`itkTypeMacroNoParent`.

The main aim is to be clearer about what those macro's do: add a virtual
`GetNameOfClass()` member function and override it. Unlike `itkTypeMacro`,
`itkOverrideGetNameOfClassMacro` does not have a `superclass` parameter, as it
was not used anyway.

Note that originally `itkTypeMacro` did not use its `superclass` parameter
either, looking at commit 699b66c, Will
Schroeder, June 27, 2001:
https://github.com/InsightSoftwareConsortium/ITK/blob/699b66cb04d410e555656828e8892107add38ccb/Code/Common/itkMacro.h#L331-L337
  • Loading branch information
N-Dekker authored and hjmjohnson committed Dec 26, 2023
1 parent caab8d2 commit 94e7339
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Modules/Core/Common/include/itkMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,22 @@ namespace itk
ITK_MACROEND_NOOP_STATEMENT
#endif

/** Macro used to add standard methods to all classes, mainly type
* information. */
#define itkTypeMacro(thisClass, superclass) \
const char * GetNameOfClass() const override { return #thisClass; } \
ITK_MACROEND_NOOP_STATEMENT

#define itkTypeMacroNoParent(thisClass) \
/** Macro's used to add `GetNameOfClass()` member functions to polymorphic ITK classes: `itkVirtualGetNameOfClassMacro`
* adds a virtual `GetNameOfClass()` member function to the class definition, and `itkOverrideGetNameOfClassMacro` adds
* a `GetNameOfClass()` override. */
#define itkVirtualGetNameOfClassMacro(thisClass) \
virtual const char * GetNameOfClass() const { return #thisClass; } \
ITK_MACROEND_NOOP_STATEMENT

#define itkOverrideGetNameOfClassMacro(thisClass) \
const char * GetNameOfClass() const override { return #thisClass; } \
ITK_MACROEND_NOOP_STATEMENT

/** Macro used to add standard methods to all classes, mainly type information. */
#define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
#define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)

namespace itk
{
/**
Expand Down

0 comments on commit 94e7339

Please sign in to comment.