Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-06-12 09:52:39


Stefan Seefeld wrote:
> Peter Dimov wrote:
>>
>> I think that there is considerable interest in a boost::xml library.
>> But...
>>
>> Document *document = Document::parse_file(argv[1]);
>>
>> ... I don't believe that a raw pointer based interface is acceptable.
>>
>> xml::dom::document document = xml::dom::parse_file(argv[1]);
>>
>> looks much better.
>
> Good catch. However, it looks worse than it actually is :-) :
>
> The memory management for nodes is entirely handled by the backend
> (libxml2), i.e. nodes are always created and deleted by their parents.
> Constructors and destructors are protected.
>
> The 'Document' class is the only one that is owned directly by the
> user, and thus has to be deleted.

Looks reasonable, but we don't want the architecture of the backend to
affect the interface. There is also the problem that the user can be left
with an invalid pointer after the document has been deleted.

Since the DOM is a tree and has no cycles, it should be possible to get
fairly close to the Java interface using strict ownership or shared_ptr
underneath. In the libxml2 case every Node would need to keep the whole
Document alive but this may not be necessary given a different backend.

Of course if this isn't practical a quick fix would be to return a
shared_ptr<Document> from parse_file.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk