[Insight-developers] proper way to test for a superclass?

Michael Stauffer (Circular Logic) mstauff at verizon.net
Fri Oct 22 19:49:35 EDT 2010


Luis,
 
Thanks for the example code. Do you know why it uses a static_cast first
in the code? Is it just for style/readability, or something else I'm
missing?
 
itkTransformFileReaderWriterTest.cxx:
 
    AffineTransformPointer affine_read =
static_cast<AffineTransformType*>((*tit).GetPointer());
    affine_transform1 = dynamic_cast< AffineTransformType * >(
affine_read.GetPointer() );

I'm doing just this, based on some code I saw elsewhere. It seems to
work:
 
    typename TransformType::ConstPointer transform;    
    transform = dynamic_cast<TransformType *>( ( (
transformReader->GetTransformList() )->front() ).GetPointer() );

Cheers,
Michael


  _____  

From: Luis Ibanez [mailto:luis.ibanez at kitware.com] 
Sent: Saturday, October 16, 2010 3:00 PM
To: Michael Stauffer (Circular Logic)
Cc: ITK-dev-list
Subject: Re: [Insight-developers] proper way to test for a superclass?



Hi Michael,

An attempt to dynamic_cast, followed by checking
whether the returned pointer is null or not, is the
standard way in which we check for the actual
type of a class.

Please note that IO is probably the only space in
which dynamic_casting can be tolerated as a 
standard practice.


In general, no dynamic_cast should be needed 
in a well designed generic programming package.


You may want to look at the code in

ITK/Testing/Code/Review/itkTransformFileReaderWriterTest.cxx



B B B Best,


B B B B B B Luis


-------------------------------------------------------------

On Wed, Oct 13, 2010 at 11:23 AM, Michael Stauffer (Circular Logic)
<mstauff at verizon.net> wrote:


Hi Luis,
B 
Yes sorry, that wasn't clear. 
B 
For example, I'd like to test at runtime that an object is a
MatrixOffsetTransformBase class, or a subclass thereof, to make sure it
has certain member functions. The issue comes from reading a transform
file using the transform file reader, and wanting to make sure the
output object is of the type or a subclass.
B 
I can't see in the TransformFileReader class how I can tell or controlB
what kind of transform type it's returning, except for trying a dynamic
class. Am I missing some way to do so more properly? The documentation
doesn't seem to cover this.
B 
Cheers,
Michael


  _____  

From: Luis Ibanez [mailto:luis.ibanez at kitware.com] 
Sent: Wednesday, October 13, 2010 9:50 AM
To: Michael Stauffer (Circular Logic)
Cc: ITK-dev-list
Subject: Re: [Insight-developers] proper way to test for a superclass?



Hi Michael,

What do you mean by a "minimum superclass" ?

Please explain.


B B Thanks


B B B B B B B B Luis 



---------------------------------------------------

On Tue, Oct 12, 2010 at 4:51 PM, Michael Stauffer (Circular Logic)
<mstauff at verizon.net> wrote:


Hi,

What's the proper way in ITK to test for a minimum superclass? I could
do a dynamic cast and check for NULL - is that acceptable? Thanks.

Cheers,
Michael

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://kitware.com/products/protraining.html

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-developers




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20101022/ce5c71b8/attachment.htm>


More information about the Insight-developers mailing list