From 8da679e594a705a9f0c61a63c53d4c5a8ae9b8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Mon, 4 Oct 2021 18:47:07 -0400 Subject: [PATCH 1/2] STYLE: Introduce non-virtual getter/boolean macros and use them Introduce non-virtual variants for the getter and boolean macros. Use macros to Set/Get ivars in `Common` operators. Take advantage of the commit to leave the documentation of the ivars only in their corresponding Set/Get methods, as dictated by the ITK SW Guide. --- .../Core/Common/include/itkAnnulusOperator.h | 74 +++--------------- .../Common/include/itkDerivativeOperator.h | 11 +-- .../include/itkGaussianDerivativeOperator.h | 75 +++++-------------- .../Core/Common/include/itkGaussianOperator.h | 53 +++---------- .../Common/include/itkImageKernelOperator.h | 4 +- .../Common/include/itkLaplacianOperator.h | 4 +- Modules/Core/Common/include/itkMacro.h | 30 ++++++++ .../Common/include/itkNeighborhoodOperator.h | 11 +-- 8 files changed, 81 insertions(+), 181 deletions(-) diff --git a/Modules/Core/Common/include/itkAnnulusOperator.h b/Modules/Core/Common/include/itkAnnulusOperator.h index 4c1888f7ab5..4cbade05ced 100644 --- a/Modules/Core/Common/include/itkAnnulusOperator.h +++ b/Modules/Core/Common/include/itkAnnulusOperator.h @@ -96,11 +96,7 @@ class ITK_TEMPLATE_EXPORT AnnulusOperator : public NeighborhoodOperatorSetNormalize(true); - } - void - NormalizeOff() - { - this->SetNormalize(false); - } + itkGetConstNonVirtualMacro(Normalize, bool); + itkBooleanNonVirtualMacro(Normalize); /** If Normalize is on, you define the annulus to have a bright * center or a dark center. */ @@ -159,21 +134,8 @@ class ITK_TEMPLATE_EXPORT AnnulusOperator : public NeighborhoodOperatorSetBrightCenter(true); - } - void - BrightCenterOff() - { - this->SetBrightCenter(false); - } + itkGetConstNonVirtualMacro(BrightCenter, bool); + itkBooleanNonVirtualMacro(BrightCenter); /** If Normalize is off, the interior to annulus, the * annulus (region between the two circles), and the region exterior to the @@ -184,31 +146,19 @@ class ITK_TEMPLATE_EXPORT AnnulusOperator : public NeighborhoodOperatorm_Order = order; } - - /** Returns the order of the derivative. */ - unsigned int - GetOrder() const - { - return m_Order; - } + itkGetConstNonVirtualMacro(Order, unsigned int); void PrintSelf(std::ostream & os, Indent indent) const override @@ -116,7 +110,6 @@ class ITK_TEMPLATE_EXPORT DerivativeOperator : public NeighborhoodOperatorm_##name; } \ ITK_MACROEND_NOOP_STATEMENT +/** Get built-in type. Creates a non-virtual member Get"name"() (e.g., GetVisibility()); + * This is the "non-virtual, const" form of the itkGetMacro. It should be used unless + * the member can be changed through the "Get" access routine and in situations where the + * method is not required to be overriden. */ +#define itkGetConstNonVirtualMacro(name, type) \ + type Get##name() const { return this->m_##name; } \ + ITK_MACROEND_NOOP_STATEMENT + /** Get built-in type. Creates member Get"name"() (e.g., GetVisibility()); * This is the "const" form of the itkGetMacro. It should be used unless * the member can be changed through the "Get" access routine. @@ -1016,6 +1024,22 @@ compilers. virtual const type & Get##name() const { return this->m_##name; } \ ITK_MACROEND_NOOP_STATEMENT +/** Get built-in type. Creates member Get"name"() (e.g., GetVisibility()); + * This is the "non-virtual, const" form of the itkGetMacro. It should be used unless + * the member can be changed through the "Get" access routine and in situations where the + * method is not required to be overriden. + * This version returns a const reference to the variable. */ +#define itkGetConstNonVirtualReferenceMacro(name, type) \ + const type & Get##name() const { return this->m_##name; } \ + ITK_MACROEND_NOOP_STATEMENT + +/** Get built-in type. Creates a non-virtual member Get"name"() (e.g., GetVisibility()); + * This is the "non-virtual" form of the itkGetMacro. It should be used in situations where the + * method is not required to be overriden. */ +#define itkGetNonVirtualMacro(name, type) \ + type Get##name() { return this->m_##name; } \ + ITK_MACROEND_NOOP_STATEMENT + /** Set built-in type. Creates member Set"name"() (e.g., SetVisibility()); * This should be used when the type is an enum. It is used to avoid warnings on * some compilers with non specified enum types passed to @@ -1200,6 +1224,12 @@ compilers. virtual void name##Off() { this->Set##name(false); } \ ITK_MACROEND_NOOP_STATEMENT +/** Create non-virtual members "name"On() and "name"Off() (e.g., DebugOn() DebugOff()). + * Set method must be defined to use this macro. */ +#define itkBooleanNonVirtualMacro(name) \ + void name##On() { this->Set##name(true); } \ + void name##Off() { this->Set##name(false); } + // clang-format off /** General set vector macro creates a single method that copies specified * number of values into object. diff --git a/Modules/Core/Common/include/itkNeighborhoodOperator.h b/Modules/Core/Common/include/itkNeighborhoodOperator.h index 55232f9e845..4a36802f093 100644 --- a/Modules/Core/Common/include/itkNeighborhoodOperator.h +++ b/Modules/Core/Common/include/itkNeighborhoodOperator.h @@ -89,7 +89,7 @@ class ITK_TEMPLATE_EXPORT NeighborhoodOperator : public Neighborhood::RealType; - /** Sets the dimensional direction of a directional operator. */ + /** Set/Get the direction (dimension number) of a directional operator. */ void SetDirection(const unsigned long direction) { @@ -100,13 +100,7 @@ class ITK_TEMPLATE_EXPORT NeighborhoodOperator : public Neighborhood Date: Mon, 4 Oct 2021 18:49:05 -0400 Subject: [PATCH 2/2] DOC: Fix typo in `itkGetConstReferenceMacro` macro documentation Fix typo in `itkGetConstReferenceMacro` macro documentation. --- Modules/Core/Common/include/itkMacro.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Core/Common/include/itkMacro.h b/Modules/Core/Common/include/itkMacro.h index 210ce42f036..4f0d218ee10 100644 --- a/Modules/Core/Common/include/itkMacro.h +++ b/Modules/Core/Common/include/itkMacro.h @@ -1019,7 +1019,7 @@ compilers. /** Get built-in type. Creates member Get"name"() (e.g., GetVisibility()); * This is the "const" form of the itkGetMacro. It should be used unless * the member can be changed through the "Get" access routine. - * This versions returns a const reference to the variable. */ + * This version returns a const reference to the variable. */ #define itkGetConstReferenceMacro(name, type) \ virtual const type & Get##name() const { return this->m_##name; } \ ITK_MACROEND_NOOP_STATEMENT