Re: [libxml++] Adding STL-container-like methods to Node instead of returning container instance (xmlwrapp)



Murray Cumming wrote:

1. Some people don't like changing begin() to children_begin(), because
it's not really STL-like
2. Some people don't like putting only a few STL-like methods in the
class without adding all of a clearly defined set of them.
3. I think that 2. could make the API generally cluttered and unclear.
4. I suggested an auxillary class instead to solve the problem of 3.
5. Someone needs to look at xmlwrapp to see what it does for this.

Also, could you repeat why you think this API addition is necessary. I
think you have said so already, but it's lost in the sea of messages.

Please tell us your thoughts about these points. I leave it to you to
investigate xmlwrapp because you are the author of this API change and
you are the one who cares about adding it at all. If we do not resolve
this soon then I will suggest again that we revert the stuff so far.

ok, here is my summary:

it seems we are converging towards the following:

class Node
{
public:
  NodeList get_children();
  NodeList get_attributes();
  //...the rest
};

class NodeList
{
public:
  class iterator;
  class const_iterator;
  iterator begin();
  //...and the rest
};

This looks quite similar to our current approach (at least as far
as the Node API itself goes). The issue I try to resolve is that
'NodeList' was a list, and so you had to copy all child-node pointers
into it to return it. Quite a waste.

With my proposed NodeList class (which will comply to STL API), only
a single xmlNode pointer needs to be copied, as the 'iterator' now
can be implemented in terms of libxml2's internal linked list structure,
not as an iterator over a std::list. That's the main benefit.

There is one remaining issue: we'd need a 'ConstNodeList' type that
provides read-only access to the children. If you hold a const
node reference, you shouldn't access child nodes in r/w mode, i.e
the corresponding 'get_children() const;' method shouldn't return
a NodeList, as you get r/w access with that.
(The issue exists since we don't return a reference to an internal
container, but a new one, so we can't restrict access).

Finally, the xmlwrapp does use the approach I originally sugested:
the Node class itself provides iterators. However, it uses 'begin()'
and 'end()' instead of 'children_begin()' and 'children_end()', but
returns attributes via a separate container (wrapper).

Stefan





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