[Insight-developers] proper way to test for a superclass?
Luis Ibanez
luis.ibanez at kitware.com
Sat Oct 16 15:00:21 EDT 2010
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
Best,
Luis
-------------------------------------------------------------
On Wed, Oct 13, 2010 at 11:23 AM, Michael Stauffer (Circular Logic) <
mstauff at verizon.net> wrote:
> Hi Luis,
>
> Yes sorry, that wasn't clear.
>
> 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.
>
> I can't see in the TransformFileReader class how I can tell or control 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.
>
> 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/20101016/c6e31dad/attachment.htm>
More information about the Insight-developers
mailing list