8000 Better node visitor interface · Issue #103 · zeux/pugixml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Better node visitor interface #103
Open
@zeux

Description

@zeux

Assuming node visitor interface is a good idea (is it? not 100% clear), there are several problems with existing xml_tree_walker:

  1. ::begin/::end are pretty pointless - could be called from external code
  2. No way to get callbacks before/after the subtree - this is what begin/end could have been. This was mentioned (if memory serves) in https://code.google.com/p/pugixml/issues/detail?id=219 but this link is now dead.
  3. No way to skip a subtree. This is mentioned in issue wish to add another xml_node::traverse function meber #77.

While manually implementing a recursive traversal is pretty trivial, all traversals that pugixml implements are stackless (which is not as simple/concise to write yourself), so there seems to be some value in a generic traversal. There are still several implementation options though:

  1. Interface with virtual functions. This will have to be a new interface to maintain binary compatibility - xml_tree_visitor or something like that.
  2. Pseudo-interface with templated member functions. This can be faster, although in a non-LTO build it's a weird tradeoff - templated implementations can't inline node structure accessors, while an implementation based on virtual dispatch can't inline user code. With LTO or header-only mode the approach based on compile-time polymorphism should be faster though. This can be seen as an extension of xml_node::find_node.
  3. Tree iterator with ability to descend into a subtree or skip it, so that the user code is in control of the flow.

These need to be evaluated for the performance and versatility in various scenarios. 1 and 2 are extensions of existring ::traverse() support while 3 is basically a separate idea.

Finally, there is - as it is - quite a few ways to traverse the nodes in pugixml. Ideally if we do need a new way it has to supplant the old one - that is, we should at the minimum deprecate existing ::traverse in favor of whatever the new interface is.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0