[xsd-users] abstract types access
Azadeh Omrani
a.omrani at gmail.com
Mon Jan 26 07:43:43 EST 2009
Hi,
Thanks for your response on polymorphism Boris.
Can you please help me on the following problem?
The schema (in aq.xds) is this:
<xsd:complexType name="AcquisitionType">
<xsd:sequence>
<xsd:element name="ComponentDescription"
type="ComponentDescriptionType"
maxOccurs="unbounded"/>
[...]
</xsd:complexType>
<xsd:complexType name="ComponentDescriptionType">
<xsd:sequence>
[...]
<xsd:element name="SessionDescription"
type="SessionDescriptionBaseType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="SessionDescriptionBaseType" abstract="true" />
<xsd:complexType name="InlinedSDPType">
<xsd:complexContent>
<xsd:extension base="SessionDescriptionBaseType">
<xsd:sequence>
<xsd:element name="SDP" type="SDPType"/>
[...]
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="SDPRefType">
<xsd:complexContent>
<xsd:extension base="SessionDescriptionBaseType">
<xsd:sequence>
<xsd:element name="SDPStream" type="SDPType"/>
[...]
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
I set the --generate -polymorphysm option, then I have the following error
on line 36 of aq.cxx (below):
"Unhandled exception at 0x7c812aeb in ESG.exe: Microsoft C++ exception:
xsd::cxx::tree::not_derived<char> at memory location 0x0012d5bc.."
1 void ComponentDescriptionType::
2 parse (::xsd::cxx::xml::dom::parser< char >& p,
3 ::xml_schema::flags f)
4 {
5 for (; p.more_elements (); p.next_element ())
6 {
7 const ::xercesc::DOMElement& i (p.cur_element ());
8 const ::xsd::cxx::xml::qualified_name< char > n (
9 ::xsd::cxx::xml::dom::name< char > (i));
10
11 // SessionDescription
12 //
13 {
14 ::xsd::cxx::tree::type_factory_map< char >& tfm (
15 ::xsd::cxx::tree::type_factory_map_instance< 0, char > ());
16
17 ::std::auto_ptr< ::xsd::cxx::tree::type > tmp (
18 tfm.create (
19 "SessionDescription",
20 "urn:dvb:ipdc:esg:2005",
21 &::xsd::cxx::tree::factory_impl< SessionDescription_type
>,
22 false, true, i, n, f, this));
23
24 if (tmp.get () != 0)
25 {
26 if (!SessionDescription_.present ())
27 {
28 ::std::auto_ptr< SessionDescription_type > r (
29 dynamic_cast< SessionDescription_type* > (tmp.get ()));
30
31 if (r.get ())
32 tmp.release ();
33 else
34 throw ::xsd::cxx::tree::not_derived< char > ();
35
36 this->SessionDescription_.set (r);
37 continue;
38 }
39 }
40 }
What does this line do and where do you think this problem comes from?
P.S. If I remove the option then there is no error like that but non of the
following "if clauses" come true. I think it is natural in this case.
acquisition::ComponentDescriptionType::SessionDescription_type& sd
(cdi->SessionDescription());
if (acquisition::SDPRefType* reff =
dynamic_cast<acquisition::SDPRefType*> (&sd))
{
//======== We've got SDPRefType.
acquisition::SDPRefType::SDPStream_type sdpstr
(reff->SDPStream());
sdp=(char *)sdpstr.c_str();
}
else if (acquisition::InlinedSDPType* inll =
dynamic_cast<acquisition::InlinedSDPType*> (&sd))
{
//======== We've got InlinedSDPType.
acquisition::InlinedSDPType::SDP_type sdp (
inll->SDP());
sdp= (char *) sdp.c_str();
}
On Thu, Jan 8, 2009 at 3:06 PM, Boris Kolpackov <boris at codesynthesis.com>wrote:
> 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