[xsd-users] Re: Copying objects

Boris Kolpackov boris at codesynthesis.com
Mon Mar 24 10:43:12 EDT 2014


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