[Insight-developers] CastWithRangeCheck implmentation and usage

Luis Ibanez luis.ibanez at kitware.com
Fri Dec 18 11:31:51 EST 2009


Hi Brad,

Good point,

Fully implementing the class is certainly a good idea.

The current code contains just a plain "static_cast".

I'm not sure I'm following on the need for making additional
checks for integer types.

Let's talk during the tcon.


     Luis


------------------------------------------------------------
On Thu, Dec 17, 2009 at 5:43 PM, Bradley Lowekamp
<blowekamp at mail.nih.gov> wrote:
> Hello,
> I was thinking that this newly created method, needs some work before it's
> used much further. This is the implementation that I was thinking about:
> template <typename TType>
> inline TType CastWithRangeCheck( TType x )
> {
>   itkConceptMacro( OnlyDefinedForIntegerTypes, (Concept::Integer<TType>) );
>   return x;
> }
> template <typename TReturn,typename TInput>
> inline TReturn CastWithRangeCheck(TInput x)
> {
>   itkConceptMacro( OnlyDefinedForIntegerTypes1, (Concept::Integer<TReturn>)
> );
>   itkConceptMacro( OnlyDefinedForIntegerTypes2, (Concept::Integer<TInput>)
> );
>   TReturn ret = static_cast<TReturn>(x);
>   if ( ret != x ||
>        ( NumericTraits<TInput>::IsPositive(x) !=
> NumericTraits<TReturn>::IsPositive(x) ) )
>     {
>     // this should likely be a new exception class
>     RangeError _e(__FILE__, __LINE__);
>     throw _e;
>     }
>   return ret;
> }
>
> What I had not considered was that this method has started to already be
> used to convert double to floats. I believe that we should fill in the
> behavior of this methods relatively soon.
> Brad
>
> ========================================================
>
> Bradley Lowekamp
>
> Lockheed Martin Contractor for
>
> Office of High Performance Computing and Communications
>
> National Library of Medicine
>
> blowekamp at mail.nih.gov
>
>


More information about the Insight-developers mailing list