[xsd-users] copying IDREF elements classes

Omkar Wagh owagh at tower-research.com
Thu May 31 10:53:59 EDT 2012


hi

On 05/31/2012 03:38 AM, Boris Kolpackov wrote:
> Hi Omkar,
>
> Omkar Wagh<owagh at tower-research.com>  writes:
>
>> I want to be able to copy IDREF structs.
>>
>> <xs:complexType name="some_unit">
>> <xs:sequence>
>> <xs:element name="some_ref" type="IDREF" />
>> </xs:sequence>
>> </xs:complexType>
>>
>> <xs:complexType name="some_bigger_unit">
>> <xs:sequence>
>> <xs:element name="unit1" type="some_unit" />
>> <xs:element name="unit2" type="some_unit" />
>> </xs:sequence>
>> </xs:complexType>
>>
>> Now, I'm using xsd and cxx-tree and I want to be able to construct
>> instances of class some_bigger_unit from instances of class some_unit.
> I am not sure what the issue is. You can do:
>
> some_unit u1 ("id1"), u2 ("id2);
> some_bigger_unit bu (u1, u2);
> some_bigger_unit bu2 (bu.unit2 (), bu.unit1 ());
>
>> However, thanks to the auto_pointer thing, if I do that, the original
>> class looses ownership of the pointer to the referenced element (or so
>> I believe).
> I am not sure what you mean here? Are you detaching some_unit instance
> from some other tree? That's the only way to get an auto_ptr in C++/Tree.
> I think it will be the best if you show some sample code that doesn't
> work for you (always a good idea).
>
> Boris
Yeah I think I'll try to post some more code. The entire code is a bit 
complex but essentially it's something like this :-

document doc = document_(filename);

Now, at some point in the code, I have with me two references to 
some_bigger_unit say sbu1, sbu2.
I want to do this :-
some_bigger_unit sbu_new (sbu1.unit1(), sbu2.unit1());

Now if I try to dereference the element that sbu_new.unit1() should 
point to, I get a dynamic cast failure.

Basically,
referenced_class& myclass ( dynamic_cast <referenced_class&> (* ( 
sbu_new.unit1() ) ) );
doesn't work since sbu_new.unit1() doesn't point to anything.
On the other hand,
referenced_class& myclass ( dynamic_cast <referenced_class&> (* ( 
sbu1.unit1() ) ) );
works perfectly fine.

thanks
Omkar



More information about the xsd-users mailing list