Boost logo

Boost :

From: Stefan Seefeld (seefeld_at_[hidden])
Date: 2003-06-26 10:04:46


Hamish Mackenzie wrote:
> Ok I think I understand the problem now. What does node->document()
> return and what does it point to???

it returns a dom::document_ptr, which behaves exactly the same way
as the other _ptr types, i.e. it has reference semantics.

> Well I think as with the node->parent() it should return a proxy
> object. Something like...

that's what it does indeed.

> // non owning reference
> class document_ref
> {
> public:
> // Define document related methods here
> protected:
> document_ref() : raw_( 0 ) {}
> xmlDoc * raw_;
> };
>
> // non owning pointer
> class document_ptr
> {
> public:
> document_ptr( document_ref * );
> document_ref operator *() { return ref_; }
> document_ref * operator ->() { return &ref_; }
> private:
> document_ref ref_;
> };
>
> // owning object with deep copy
> class document : public document_ref
> {
> public:
> explicit document( const std::string & file );
> document( document_ref source )
> {
> // Deep copy here
> }
> ~document() { xmlFreeDoc( raw_ ); }
> };

I don't really understand why we need three different classes to
manage documents. In particular I don't understand why you provide
a 'document_ptr' that is a wrapper around document_ref.

And I don't use a 'document' class, as that is managed implicitely
by my dom::document_ptr:

dom::document_ptr document; // create new document;
dom::document_ptr doc(document); // create second reference to it
dom::document_ptr doc2 = document.clone(); // clone it, i.e. make deep
                                               copy

> root->document() can return document_ptr or document_ref.

indeed, that's what it does.

>
>
>>>value_types could exist but it would require a deep copy to be
>>>consistent. If you do want to define it then I suggest
>>
>>you mean if I do *not* want to define it ?
>
>
> Yes, you could
> 1) define a deep copy value_type

that doesn't work as there is no way to copy nodes 'out of the
document'.

> 2) typedef void value_type;
> 3) leave it undefined
>
>
>>>Your iterator types look good. Why is there an extra level of
>>>indirection in basic_element_const_iterator?
>>
>>the const iterator is non-functional right now. I'v been wondering
>>how to provide one. It seems I would need to define a 'const_node_ptr'
>>set of classes.
>
>
> I think that is right. I would prefer it to be
>
> typedef node_pointer< node_ref > node_ptr;
> typedef node_pointer< const_node_ref > const_node_ptr;
>
> In fact you will probably need const_ versions for all your reference,
> pointer and iterator types. Though the pointers and iterators should
> just be additional instances of template classes.

yes

Stefan


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