[xsd-users] copying IDREF elements classes

Omkar Wagh owagh at tower-research.com
Thu Jun 21 13:54:59 EDT 2012


Hi Boris

On 06/21/2012 05:16 AM, Boris Kolpackov wrote:
> The ID attribute should be unique in the XML, so this is consistent
> with that restriction, except for the seg fault Are you sure it is
> not throwing the duplicate_id exception?
I am quite sure of this. Setting the ID of the temporary some_bigger_unit
(which has an IDREF as a member element) to some random (hopefully unique)
value avoids the segfault the next time I want to dereference an IDREF 
to the same
some_bigger_unit. It definitely doesn't throw an exception but segfaults 
when
I try to do the second dynamic cast.
> IDREF in C++/Tree doesn't store a pointer to the node it points
> to. Rather it stores the value of the ID and whenever you need
> the pointed-to node, it does a lookup in the ID-to-node map
> that is stored in the root node of the object model. Whenever
> a node is added somewhere in the model, its _container()
> function is called to notify it that it is now part of that model.
> In _container() the node registers all its IDs in the map. If
> there is a duplicate, then you get the duplicate_id exception.
This is somewhat how I thought it works after going through the library 
source code.
Thanks for clearing it all up.
>> I suppose if there now were a way to "unset" the container once the job
>> of the temporary is done, that too might work.
> Yes, you can do that by passing NULL pointer to _container(). That's
> what happens when you detach a node from a model.
I tried this out but then I get a different exception :-
terminate called after throwing an instance of 
'xsd::cxx::tree::_type::not_registered'
   what():  attempt to unregister non-existent id
Aborted

Omkar



More information about the xsd-users mailing list