[xsd-users] Help me: How to find out what is the type of a class

Boris Kolpackov boris at codesynthesis.com
Tue Oct 20 09:40:14 EDT 2009


Hi James,

James Mei <jxmei3 at gmail.com> writes:

> Also, I assigned the class pointer to TreeNode->Data for later 
> manipulation.

TreeNode->Data is of type void*, right?


> However, I only have the pointer, not its class type. I do not know it 
> is a pointer to GSE() or it is a pointer to Address() May I know how do 
> I identify the type of this class pointer ?

Assuming TreeNode->Data is void*, then you can cast it to xml_schema::type*
and then use RTTI (dynamic_cast, typeid, etc.) to figure out its actual
type. This will work because xml_schema::type is a base type for all
generated and non-fundamental built-in types. For example:

xml_schema::type* t = static_cast<xml_schema::type*> (TreeNode->Data);

if (tGSE* gse = dynamic_cast<tGSE*> (t))
{
  // Handle gse.
}
else if (tAddress* addr = dynamic_cast<tAddress*> (t))
{
  // Handle addr.
}
...


> Also, is there a default data member in the generated class for storing
> reference data, such as the TreeNode->Data member.

No, there is no such pointer but you can add one by customizing the
xml_schema::type type. For more information on how to do this, see
the 'comments' example in the examples/cxx/tree/custom/ directory.

Boris



More information about the xsd-users mailing list