STYLE: Make PrintSelf implementation style consistent#3872
Conversation
8ba8047 to
a53a4cc
Compare
dzenanz
left a comment
There was a problem hiding this comment.
Looks great! There are still a few compile errors.
I know. Still WIP/draft. I have other changes locally, but unsure whether I should split it across at least 2 PRs, as it is becoming difficult to deal with. Also it is not intended to be comprehensive, as unfortunately, this is not an automated change. I also grant that some changes belong to |
|
Having it as a single commit is fine. I know that splitting into themed commits requires extra effort. |
|
Amazing work getting this more consistent!
One other issue that some time occurs with the print self methods is when "pixel types" are char. When they are a char then they are printed as an ASCII char and not a numeric value as expected. This is a case where the NumbericTraits::PrintType must be used. This is clearly separate work. |
Thanks Brad.
Will rework the commit message as time permits and as I revise all the changes contained.
Yes, had that in mind, but did not take the chance to make the changes. Will try to do that for the ivars that I'll be streaming, but will not be checking the existing ones as a general rule. Note that this process is not automated, and I do not intend it to be comprehensive across the entire code base, but just a first step: I have mainly looked at some given patterns (like containing equal signs, etc.). Also, it will take me some time until I can get a working version. For now, it is still WIP. |
db723f1 to
19557f6
Compare
96bc1cd to
1edc5e3
Compare
463580c to
0647883
Compare
|
I assume this will be ready for review after a rebase? |
Thanks for the follow-up @dzenanz. Yes, I need to rebase. I also have some other local changes that I need to add, and I will also do this:
And adapt the commit message. Probably will be ready during the weekend. Note that it will still not be comprehensive as this is not automated. |
709ebc5 to
a4107a7
Compare
087b2b9 to
29d0f07
Compare
Make `PrintSelf`implementation style consistent following the ITK SWG
coding style guideline and the available ITK macros:
- Always print the superclass first.
- Print only the class instance variables.
- Use the `os << indent << "{ivarName}: " << m_ivarName << std::endl`
recipe: do not print the leading `m_` of the ivar; use a colon after
printing its name; leave a whitespace between the colon and the
printed value of the ivar.
- For boolean ivars print `On`/`Off` according to their values using the
ternary operator.
- Use `itkPrintSelfObjectMacro` to print objects inheriting from
`itk::LightObject` that can be null.
- For pointers that do not inherit from `itk::LightObject` check whether
they are non-null before attempting to print them and print the
`(empty)` string otherwise.
- Rely on the self printing ability of the ITK classes to avoid
boilerplate code when printing the corresponding ivars in other
classes' `PrintSelf` methods.
- Take advantage of the output stream `<<` insertion operator overload
for `std::vector` types in the `itk::print_helper` namespace defined
in `itkPrintHelper.h` to print such types consistently.
- Cast custom types to their numerical values using
`itk::NumericTraits::PrinType` so that they are printed as expected.
- Remove statements printing the hard-coded class name and its own
pointer, e.g.
```
os << indent << "ArrowSpatialObject(" << this << ")" << std::endl;
```
`PrintSelf` does this without requiring the removed line.
- Save typing `this->` to point to the instance of the current class.
Apply the same principles to the `<<` operator overloads.
Overload the ostream operator for the `FixedImageSamplePoint` class used
by the `itk::ImageToImageMetric` class.
Overload the ostream operator for the `ImageVoxel` class used by the
`itk::DeformableSimplexMesh3DGradientConstraintForceFilter` class.
|
itkPrintSelfObject(Material);
itkPrintSelfObjectMacro(Element);Does |
|
Again, thanks for the heads-up @issakomi. You're right, it should be |
|
Thanks @jhlegarreta. |
Oh, my bad. I did not have the |
PR #3918. |
Make
PrintSelfimplementation style consistent following the ITK SWGcoding style guideline and the available ITK macros:
os << indent << "{ivarName}: " << m_ivarName << std::endlrecipe: do not print the leading
m_of the ivar; use a colon afterprinting its name; leave a whitespace between the colon and the
printed value of the ivar.
On/Offaccording to their values using theternary operator.
itkPrintSelfObjectMacroto print objects inheriting fromitk::LightObjectthat can be null.itk::LightObjectcheck whetherthey are non-null before attempting to print them and print the
(empty)string otherwise.boilerplate code when printing the corresponding ivars in other
classes'
PrintSelfmethods.<<insertion operator overloadfor
std::vectortypes in theitk::print_helpernamespace definedin
itkPrintHelper.hto print such types consistently.itk::NumericTraits::PrinTypeso that they are printed as expected.pointer, e.g.
PrintSelfdoes this without requiring the removed line.this->to point to the instance of the current class.Apply the same principles to the
<<operator overloads.Overload the ostream operator for the
FixedImageSamplePointclass usedby the
itk::ImageToImageMetricclass.Overload the ostream operator for the
ImageVoxelclass used by theitk::DeformableSimplexMesh3DGradientConstraintForceFilterclass.Overload the ostream operator for the
ImageVoxelclass used by theitk::DeformableSimplexMesh3DGradientConstraintForceFilterclass.PR Checklist