From: Christophe de V. <cde...@al...> - 2003-05-22 14:13:47
|
=2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'd like to discuss the subject of iterators inside libxml++. We did already several month ago but this did not went to any=20 conclusion/decision. To illustrate how I would see things, I made a small patch which implements= a=20 class NodeIterator, which permit to iterate through the children of a node. I think it implements correctly the following concept from STL: =2D - Bidirectionnal Iterator. =2D - Input Iterator. It's quite trivial to use. Exemple to iterate a complete tree: void do_something(xmlpp::Node & node) { for( xmlpp::NodeIterator i =3D node.children_node(), i_end =3D xmlpp::NodeIterator(); i !=3D i_end; ++i) { std::cout << i->get_name() << std::endl; do_something(*i); } }; One interesting thing is that is nodes are added/removed at the same tree=20 level, the iterator will stay valid (unless we suppress the pointed node of= =20 course). A const iterator is needed, but I did not do it yet. I'd like to have comments/suggestions at least on: - Does this iterator have the behavior any C++ developer would expect ? - The class name. Should it be Node::iterator ? I'm not sure about that si= nce=20 it would suggest Node is a container, which is not right I think. - Does Node::children_begin() sounds right ? It seems to me that yes. - Should we drop Node::get_children ? simply keep it ? - Should we wait for the next major version to add this feature ? The patch (which concerns only the 'nodes' directory) also includes a littl= e=20 change : it uses pimpl idiom so that no libxml header is included by the=20 libxml++ user.=20 I think it would be a good thing to do this for the whole library, and it's= =20 not much work. What do you think about it ? Comments welcome Cheers Christophe =2D----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+zNsQB+sU3TyOQjARAmhAAJ0f0HMTVUiJv9SrCoikIeprPYaJ+QCgxVgI 1dUmvUzJqx3rW09uoFJYfgE=3D =3DGMZg =2D----END PGP SIGNATURE----- |