Boost logo

Boost :

From: Hamish Mackenzie (hamish_at_[hidden])
Date: 2003-06-13 14:35:46


On Fri, 2003-06-13 at 18:53, Stefan Seefeld wrote:
> > Maybe we do need to allow the use of _private in higher level layers.
>
> I don't think that's a good idea, in particular because it's to tightly
> coupled to a particular implementation. We could allow a 'payload' for
> nodes (possibly a template parameter), but we could as well do the
> association between a node and its template in an external lookup
> mechanism, which seems to be more clean and drag in the least overhead.

Cool. I think the at least one association should belong to the
document (so that associations can be removed when the node or it's
parents are erased from the document). Something like....

template< typename node_data, ... >
class document
{
public:
  typedef xmlNodePtr node_key;
  std::map< node_key, node_data > & node_data_map();
  const std::map< node_key, node_data > & node_data_map() const;

private:
  std::map< node_key, node_data > node_data_map_;
};

class node_reference
{
public:
  typedef xmlNodePtr node_key;
  node_key key() { return node_; }
};

A libxml2 implementation could substitute node_data_map for a class that
uses _private to store the data (or to speedup lookup). However this
would be an optimisation (definitely not a requirement).

The user would be free to set up other associative containers using the
node key. However they would be responsible for erasing the entries for
deleted nodes themselves.

-- 
Hamish Mackenzie <hamish_at_[hidden]>

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