Re: [libxml++] Re: [Libxmlplusplus-general] Node ownership



On Thu, 2003-02-06 at 19:32, Stefan Seefeld wrote:
> > That is the intention at the moment. Nodes own nodes.
> 
> but what about root nodes ? I.e. nodes that don't have a parent
> (neither a parent node nor a document) ?

Owned by the parser. You know I mean "libxml++ objects are owned by
libxml++ objects".

> >>>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.
>
> just unlink it: xmlUnlinkNode(_impl);
> 
> The things I dislike about 1) are:
> 
> 1) you suggest an additional member: 'owned_by_libxml', which isn't
>     necessary as you can determine by inspecting the _impl whether it
>     is linked into a tree.

Yes, that might work, but I'd prefer not to access libxml's private
structures.
> 
> 2) you need an accessible destructor, so you can delete the node
>     explicitely, after having checked that you are allowed to
> 
>     if (!node->is_owned_by_libxml()) delete node;
> 
>     or equivalent. That doesn't look very nice.

Or just assume that you know what you are doing. The existence of an
is_owned_by_libxml() method wouldn't force you to use it.


-- 
Murray Cumming
murray usa net
www.murrayc.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]