Skip to content

Commit f6f73fe

Browse files
committed
DOC: Document brace and brace list initialization preference
Document brace and brace list initialization preference in member declaration. Change the examples that were using any other initialization type accordingly, using mock class and method names if necessary.
1 parent 7b34899 commit f6f73fe

File tree

1 file changed

+62
-41
lines changed

1 file changed

+62
-41
lines changed

SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,44 +1543,58 @@ \section{The auto Keyword}
15431543
\section{Initialization and Assignment}
15441544
\label{sec:IniitalizationAndAssignment}
15451545
1546-
All member variables must be initialized in the class constructor. For such
1547-
purpose, initialization lists are preferred
1546+
All member variables must be initialized when they are declared. For such
1547+
purpose, brace initializers, e.g.
1548+
1549+
\small
1550+
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
1551+
private:
1552+
double m_InnerRadius{ 1.0 };
1553+
double m_Thickness{ 1.0 };
1554+
bool m_Normalize{ false };
1555+
bool m_BrightCenter{ false };
1556+
PixelType m_InteriorValue{ NumericTraits<PixelType>::ZeroValue() };
1557+
PixelType m_AnnulusValue{ NumericTraits<PixelType>::OneValue() };
1558+
PixelType m_ExteriorValue{ NumericTraits<PixelType>::ZeroValue() };
1559+
SpacingType m_Spacing{ 1.0 };
1560+
\end{minted}
1561+
\normalsize
1562+
1563+
and brace list initialization, e.g.
1564+
1565+
\small
1566+
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
1567+
private:
1568+
IndexType m_Index = { { 0 } };
1569+
SizeType m_Size = { { 0 } };
1570+
\end{minted}
1571+
\normalsize
1572+
1573+
are preferred over initialization lists in the method constructor, e.g.
15481574
15491575
\small
15501576
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
15511577
template <typename TInputImage, typename TOutputImage>
1552-
SpecializedFilter<TInputImage, TOutputImage>
1553-
::SpecializedFilter() :
1554-
m_ForegroundValue(NumericTraits<InputImagePixelType>::max()),
1555-
m_BackgroundValue(NumericTraits<InputImagePixelType>::ZeroValue()),
1556-
m_NumPixelComponents(0),
1557-
m_NoiseSigmaIsSet(false),
1558-
m_SearchSpaceList(ListAdaptorType::New())
1578+
SpecializedFilter<TInputImage, TOutputImage>::SpecializedFilter()
1579+
: m_BackgroundValue(NumericTraits<OutputImagePixelType>::ZeroValue())
1580+
, m_ForegroundValue(NumericTraits<OutputImagePixelType>::OneValue())
15591581
{
1560-
// By default, turn off automatic kernel bandwidth sigma estimation
1561-
this->KernelBandwidthEstimationOff();
1582+
...
15621583
}
15631584
\end{minted}
15641585
\normalsize
15651586
1566-
over assignment:
1587+
or assignment:
15671588
15681589
\small
15691590
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
15701591
template <typename TInputImage, typename TOutputImage>
1571-
SpecializedFilter<TInputImage, TOutputImage>
1572-
::SpecializedFilter()
1592+
SpecializedFilter<TInputImage, TOutputImage>::SpecializedFilter()
15731593
{
1574-
m_ForegroundValue = NumericTraits<InputImagePixelType>::max();
1575-
m_BackgroundValue = NumericTraits<InputImagePixelType>::ZeroValue();
1576-
1577-
m_NumPixelComponents = 0;
1578-
m_UseSmoothDiscPatchWeights = false;
1579-
1580-
m_SearchSpaceList = ListAdaptorType::New();
1594+
m_BackgroundValue = NumericTraits<OutputImagePixelType>::ZeroValue();
1595+
m_ForegroundValue = NumericTraits<OutputImagePixelType>::OneValue();
15811596
1582-
// By default, turn off automatic kernel bandwidth sigma estimation
1583-
this->KernelBandwidthEstimationOff();
1597+
...
15841598
}
15851599
\end{minted}
15861600
\normalsize
@@ -2464,13 +2478,12 @@ \subsection{Alignment}
24642478
24652479
\small
24662480
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
2467-
InputPixelType m_ForegroundValue;
2468-
OutputPixelType m_BackgroundValue;
2481+
std::string m_FileName;
2482+
ConstTransformListType m_TransformList;
2483+
bool m_AppendMode{ false };
24692484
2470-
unsigned int m_MaximumIterations;
2471-
2472-
std::vector<double> m_Sensitivity;
2473-
std::vector<float> m_Overlaps;
2485+
bool m_UseCompression{ false };
2486+
typename TransformIOType::Pointer m_TransformIO;
24742487
\end{minted}
24752488
\normalsize
24762489
@@ -2773,26 +2786,26 @@ \subsection{Empty Lines}
27732786
*
27742787
*=========================================================================*/
27752788
2776-
#ifndef itkBoxImageFilter_hxx
2777-
#define itkBoxImageFilter_hxx
2789+
#ifndef itkSpecializedImageFilter_hxx
2790+
#define itkSpecializedImageFilter_hxx
27782791
2779-
#include "itkBoxImageFilter.h"
2792+
#include "itkSpecializedImageFilter.h"
27802793
#include "itkProgressAccumulator.h"
27812794
27822795
namespace itk
27832796
{
27842797
27852798
template <typename TInputImage, typename TOutputImage>
2786-
BoxImageFilter<TInputImage, TOutputImage>
2787-
::BoxImageFilter()
2799+
SpecializedImageFilter<TInputImage, TOutputImage>
2800+
::SpecializedImageFilter()
27882801
{
2789-
m_Radius.Fill(1); // A good arbitrary starting point.
2802+
this->DynamicMultiThreadingOn();
27902803
}
27912804
27922805
27932806
template <typename TInputImage, typename TOutputImage>
27942807
void
2795-
BoxImageFilter<TInputImage, TOutputImage>
2808+
SpecializedImageFilter<TInputImage, TOutputImage>
27962809
::SetRadius(const RadiusType & radius)
27972810
{
27982811
if (m_Radius != radius)
@@ -2805,7 +2818,7 @@ \subsection{Empty Lines}
28052818
28062819
template <typename TInputImage, typename TOutputImage>
28072820
void
2808-
BoxImageFilter<TInputImage, TOutputImage>
2821+
SpecializedImageFilter<TInputImage, TOutputImage>
28092822
::PrintSelf(std::ostream & os, Indent indent) const
28102823
{
28112824
Superclass::PrintSelf(os, indent);
@@ -2815,7 +2828,7 @@ \subsection{Empty Lines}
28152828
28162829
} // end namespace itk
28172830
2818-
#endif // itkBoxImageFilter_hxx
2831+
#endif // itkSpecializedImageFilter_hxx
28192832
\end{minted}
28202833
\normalsize
28212834
@@ -3948,10 +3961,18 @@ \subsection{General Principles}
39483961
\small
39493962
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
39503963
template <typename TInputImage, typename TOutputImage>
3951-
BoxImageFilter<TInputImage, TOutputImage>
3952-
::BoxImageFilter()
3964+
void
3965+
SpecializedImageFilter<TInputImage, TOutputImage>
3966+
::SpecializedMethod()
39533967
{
3954-
m_Radius.Fill(1); // A good arbitrary starting point.
3968+
...
3969+
3970+
OutputVectorRealType lambda11 = -(x1 * v1) / ((x - x1) * v1); // upper left
3971+
OutputVectorRealType lambda12 = -(x1 * v2) / ((x - x1) * v2); // upper right
3972+
OutputVectorRealType lambda21 = -(x2 * v1) / ((x - x2) * v1); // lower left
3973+
OutputVectorRealType lambda22 = -(x2 * v2) / ((x - x2) * v2); // lower right
3974+
3975+
...
39553976
}
39563977
\end{minted}
39573978
\normalsize

0 commit comments

Comments
 (0)