[Insight-users] itkGetMacro vs. itkGetConstMacro
Luis Ibanez
luis.ibanez at kitware.com
Fri, 20 Feb 2004 04:00:38 -0500
Hi Hideaki,
I agree with you
but...
not everybody agree with us.
The reason why itkGetMacro() is around
is that ITK wasn't born const-correct,
it has been progressively converted
to the bright side.
So, let's divide and conquer, just let
the itkGetConstMacro() take progressively
the place of the itkGetMacro() until the
replacement becomes a trivial issue.
Please point out any classes where you see
that the use of itkGetMacro() should be
replaced with itkGetConstMacro().
Luis
-----------------------
HIRAKI Hideaki wrote:
> 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
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>