Run-time type information and vtkWhatever::New()

Will Schroeder will.schroeder at kitware.com
Tue Jan 18 09:22:31 EST 2000


Hi Brian-

At 04:42 PM 1/17/00 -0500, Brian Alexander Todd wrote:
>Dear vtkusers,
>
>I have a question about navigating the vtk class heirarchy.
>...............

>So, basically, I have two questions.  Why does this happen (out of
>curiousoty) and what can I do to get run-time type identification
>so that make my program works (more importantly)?

A very timely question! I just checked in a bunch of changes addressing 
these issues. The change was to replace the GetClassName() method with
a new macro vtkTypeMacro. vtkTypeMacro expands into three methods:

virtual const char *GetClassName() -> available from interpreters, same as before
virtual int IsA(const char *) -> available from interpreters
static *<classname>::SafeDownCast(vtkObject *o)  ->available only from C++

GetClassName() returns a string naming the class (as before).

IsA() returns a 1 if "this" instance is a the same as,or a subclass of, the named class.
Example: aFollower->IsA("vtkActor")  returns 1; anActor->IsA("vtkProp2D") returns 0.

SafeDownCast() returns a non-null pointer cast to the correct type if the cast is valid,
     otherwise it returns NULL. Example: 
         vtkActor *a=vtkActor::New();
         vtkProp3D *p=a;
         vtkActor *b = vtkActor::SafeDownCast(p); //will return non-NULL


We decided not to use RTTI at this point in time because there are issues 
with some compilers. For example, on some compilers you cannot mix
RTTI and non-RTTI objects, or different system libraries have to be linked in, etc.
We we may reimplement these methods with RTTI in the future, if that makes sense.)

These changes have been checked in and will be available in tonight's release.
You might give it a day or two until everything stabilizes (check the dashboard).

Will



-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list