[Insight-users] itkGetMacro vs. itkGetConstMacro

Luis Ibanez luis.ibanez at kitware.com
Thu, 19 Feb 2004 16:15:18 -0500


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
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>