From: Anthony Williams (anthony.williamsNOSPAM_at_[hidden])
Date: 2003-06-27 03:09:20
Stefan Seefeld <seefeld_at_[hidden]> writes:
> Hamish Mackenzie wrote:
> > dom::document doc;
> > dom::document_ref doc2( doc.root().document() );
> > assert( &doc2 == &doc );
> > and...
> > assert( doc2 == doc );
> > Can be implemented but ideally it would compare all the nodes in the
> > document.
> well, that's different. Do you want to know whether both documents are
> equal, or whether they are identical, i.e. whether both references point to
> the same document ?
> Hmm, just to check whether we are still talking about the same thing here:
> do we agree that there can't be a 'node' type, i.e. just a
> 'node_ref'/'node_ptr' ?
You mean: have "node" as an abstract class, so you can't have any objects of
that type, but you can have pointers and references? Sounds good.
What's wrong with just having boost::shared_ptr<Document> and
boost::shared_ptr<Node>, boost::shared_ptr<Element> ?
You could have each node store a boost::weak_ptr<Element> pointing to its
parent, which is converted to a boost::shared_ptr<Element> when you ask for
it. That way, a child doesn't keep its parent alive (though parents should
keep their children alive), but you can still traverse up the tree if you
You could do the same for documents --- the document holds a shared_ptr to the
root element, and so keeps the whole tree alive. Each element holds a weak_ptr
to the document, so you can retrieve the document from it, but it doesn't keep
it alive. Consequently, if you erase an element from the document, but you
still have a pointer to it, then the element itself is OK, but it will then
die when your pointer goes out of scope. Also, if the document goes out of
scope, then your element is still OK, but is no longer associated with a
-- Anthony Williams Senior Software Engineer, Beran Instruments Ltd. Remove NOSPAM when replying, for timely response.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk