[xsd-users] abstract types access
Boris Kolpackov
boris at codesynthesis.com
Thu Jan 8 06:36:55 EST 2009
Hi Azadeh,
I noticed that you sent two identical copies of this email. Please
refrain from doing this in the future to avoid unnecessary traffic
on the mailing list.
Azadeh Omrani <a.omrani at gmail.com> writes:
> esg::ESGType::ComponentDescription_sequence& cds
> (eagdata.esgData->ComponentDescription());
> for(esg::ESGType::ComponentDescription_iterator i (cds.begin ());i !=
> cds.end (); ++j)
> {
> esg::ComponentDescriptionType::SessionDescription_type sdt
> (i->SessionDescription());
You can test which type it is using dynamic_cast:
esg::ComponentDescriptionType::SessionDescription_type& sdt (
i->SessionDescription());
if (SDPRefType* ref = dynamic_cast<SDPRefType*> (&sdt))
{
// We've got SDPRefType.
}
else if (InlinedSDPType* inl = dynamic_cast<InlinedSDPType*> (&sdt))
{
// We've got InlinedSDPType.
}
Notice that I changed your 'sdt' declaration to use a reference. This
is important for the polymorphism to work.
For more information on working with polymorphic object models see
Section 2.11, "Mapping for xsi:type and Substitution Groups" in the
C++/Tree Mapping User Manual:
http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.11
Boris
More information about the xsd-users
mailing list