Run-time type information

Some of the classes in the WebSphere value type library contain methods that accept instances of a superclass. For such cases, the library use a C++ dynamic_cast to determine the type of the passed object. For example:

CORBA::Boolean equals(CORBA::ValueBase& arg0)
 {
    ...
	 OBV_java::lang::Integer*  argInteger = dynamic_cast<OBV_java::lang::Integer*>(& arg0) ;
	 ...
  }

This functionality allows you to perform type inquiries just as you would in the Java language using the "instance of" operator.

Note: For this code to work, a polymorphic hierarchy must exist, that is, at least one virtual function must be implemented in the class hierarchy.

Another possible approach is to use the "typeid()" operator of the type_info class. For example:

#include <typeinfo>
#include <iostream>
using namespace std;
class Test1 { __ };
class Test2 : Test1 {_..};
void main(void)
{
Test2* ptr = new Test2();
cout << typeid(*ptr).name() << endl; //yields the string "class Test2"
}

Depending on the compiler that is used, you must enable certain options in order for this functionality to work properly. For example, for MSVC++, the /GR option must be added to the compiler settings.


Related concepts
CORBA valuetype library for C++



Searchable topic ID:   ccor_vallc4
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/corba/concepts/ccor_vallc4.html

Library | Support | Terms of Use | Feedback