[libxml++] Re: [Libxmlplusplus-general] Node ownership
- From: murrayc t-online de (Murray Cumming)
- To: libxml++ <libxmlplusplus-general lists sourceforge net>
- Subject: [libxml++] Re: [Libxmlplusplus-general] Node ownership
- Date: 06 Feb 2003 18:53:08 +0100
On Thu, 2003-02-06 at 18:23, Stefan Seefeld wrote:
> > Murray Cumming wrote:
> > Clearly libxml++ objects need to be able to create nodes. Maybe
> > people
> > want to create nodes with normal C++ memory management too.
> Well, that's not so clear to me.
But that's what you've been telling us that you want.
> And even if it was, there are multiple
> ways to achieve this.
That's what I'm trying to discuss.
> I was discussing this with DV, and he suggested to
> make something simple, even if it is a bit restrictive. It's more
> important to have a non-leaking library (by that I also mean an API
> that is clear about the semantics) than something that is flexible but
> is an invitation for bugs.
That is the intention at the moment. Nodes own nodes.
> > So, let's list some possible solutions. For instance,
> >
> > 1. A boolean owned_by_libxml member variable.
> > The libxml destroy callback would not destroy the C++ wrapper instance
> > if owned_by_libxml is false.
>
> but what would it do instead ? The impl object is already destroyed, so
> the wrapper is invalid anyways.
True. Does libxml provide any way to detach a node from it's parent? If
not then we probably can't provide functionality via a wrapper that's
not in the libxml itself.
> I'd suggest
>
> 4. add a clipboard-like API, i.e. a place where nodes that aren't
> currently part of a document are helt. This could be hidden:
>
> We don't need an extra flag to specify ownership. If the document
> points to the node (and, the node to the document), it is owned. The
> question arises only if we take the node out of the document.
>
> So, the question is how to implement that 'remove node from tree'
> method. It could work like this:
>
> void Node::remove_child(Node *node)
> {
> Clipboard::store(node); // unlink the node from the current doc
> }
> void Node::insert_child(iterator i, Node *node)
> {
> Clipboard::restore(node); // remove the node from the
> // clipboard, if it was stored,
> // else unlink it from the old
> // document
> xmlAddPrevSibling(node->_impl); // link the node into the new doc
> }
>
>
> the Clipboard would be hidden, only accessible by xmlpp objects.
> Oh, and we may add a static method to Node:
>
> void Node::destroy(Node *node); that really deletes a subtree.
>
> The advantage here is that nodes are always owned by *exactly* one
> container. Either a document or a clipboard. That's simple to keep
> in mind by users, and it is simple to implement correctly.
This doesn't show how we would detach the node in C. If there is a way
to do that then 1. would also seem to be possible, and simpler.
--
Murray Cumming
murray usa net
www.murrayc.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]