[Insight-users] itkGetMacro vs. itkGetConstMacro

HIRAKI Hideaki hhiraki at lab.nig.ac.jp
Fri, 20 Feb 2004 17:38:19 +0900


Thank you Luis, for quick response.

I'm afraid of missing something.
ALL use of itkGetMacro seems to be replacable with itkGetConstMacro.
Both just return a copy of member variable to the caller. The 
difference is only that itkGetMacro prohibits accessing to a const 
object. 
I didn't realize why this feature was needed. I thought itkGetMacro 
could allow const access and itkGetConstMacro could be removed.

Regards

Hideaki Hiraki

Luis Ibanez wrote:
> 
> Hi Hideaki,
> 
> 
> The degree of support for const-correctness
> have evolved in ITK over time.
> 
> This evolution is normal on the practice of
> extreme  programming. Software behaves like
> a living organism. It grows and adapts in
> reaction to the environment.
> 
> There are still some pieces of code that
> don't completely adhere to the standard
> established for the rest of the toolkit.
> 
> As a general rule, all Get()s should be const.
> Only in very specific cases we should offer
> non-const access to member variables. That
> typically occurs in methods that actually
> compute the value to be returned.
> 
> Probably the best thing to do at this point
> is for you to post to the list a summary of
> the classes and methods that you have found
> not to support const-correctness as they
> should.  Developers will then look through
> those classes and change the ones that are
> appropriate. The changes in most cases, will
> simply involve replacing the itkGetMacro()
> with itkGetConstMacro().
> 
> 
> Please feel free to open your account in the
> bug tracker and log those comments as bug
> reports.
> 
> 
> 
> Thanks
> 
> 
>    Luis
> 
> 
> -----------------------
> HIRAKI Hideaki wrote:
> > Hello,
> > 
> > In many classes, itkGetMacro is used to provide access to their data 
> > members and prohibits 'Get' a data member of a 'const' object. I could 
> > workaround the problem by const_cast (and there are some classes that 
> > use itkGetConstMacro to allow this kind of operation). But it seems to 
> > be easier and safe to change the definition of itkGetMacro as 
> > itkGetConstMacro. Why the two macro need to be differentiated? Is 
> > there a case itkGetMacro returns a lawbreaker such as a pointer?
> > 
> > Thanks,
> > 
> > Hideaki Hiraki