[xsd-users] Re: Copying objects
Mathew Benson
mathew.benson at gmail.com
Mon Mar 24 11:15:07 EDT 2014
I got it. I think we were saying the same thing, you are just able to state it better. The problem is when I created an object with the new operator, it didn't belong to the DOM. I found a better solution.
Sent from my iPhone
> On Mar 24, 2014, at 9:43 AM, Boris Kolpackov <boris at codesynthesis.com> wrote:
>
> Hi Mathew,
>
> You really have a knack for overcomplicating things. I am typically
> lost at about the second sentence of your email ;-).
>
> Here is how the ID/IDREF stuff works in C++/Tree. The resolution
> of the IDREF is dynamic. That is, every time you call get() or
> operator->(), the idref class searches the object model that it
> belongs to for the matching ID.
>
> In particular, notice this phrase in the above sentence: "searches
> the object model that it belongs to". That's the important part
> to understand and that I believe is the key to your struggles.
>
> Let me try to illustrate this with an example. Say we have type
> Root that has two elements of type Foo and Bar. Foo has the ID
> attribute (let's call it id) and Bar has the IDREF attribute
> (let's call it ref). Here is some code that illustrates what
> I am talking about:
>
> Bar b;
> b.ref ("a");
>
> // b.ref is NULL.
>
> Foo f;
> f.id ("a");
>
> // b.ref is still NULL since f and b don't belong to the same model.
>
> Root r;
> r.bar (b);
>
> // r.bar.ref is still NULL.
>
> r.foo (f);
>
> // r.bar.ref now points to r.foo. BUT: b.ref is still NULL.
>
> Bar b1 (r.bar ());
>
> // b1.ref is NULL since it does not belong to r (a copy).
>
> Bar& b2 (r.bar ());
>
> // b2.ref is not NULL.
>
> r.foo ().id ("b");
>
> // r.bar.ref is now NULL since there is no ID "a" in the object model.
>
> Boris
More information about the xsd-users
mailing list