Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom traversal possibility via 'xml_tree_walker' interface #319

Closed
DanN91 opened this issue Jan 8, 2020 · 2 comments
Closed

Custom traversal possibility via 'xml_tree_walker' interface #319

DanN91 opened this issue Jan 8, 2020 · 2 comments

Comments

@DanN91
Copy link

DanN91 commented Jan 8, 2020

I am referring to this method: PUGI__FN bool xml_node::traverse(xml_tree_walker& walker)

As I see now in the code, before calling for_each, we have this line xml_node arg_for_each(cur) which wraps the current node and thus a copy of the current node reference is passed to for_each.

The limitation with this is that if I want to skip the traversal of, let's say, all the siblings of a specific node inside my for_each implementation for the xml_tree_walker which I provided for traversal, I know not of a way to do this.

This is due to the fact that after the call to walker.for_each(arg_for_each), what is used in the traversal logic is not arg_for_each, but cur and so, what I do inside my implementation in order to change the node which would be traversed next ( node = node.parent().next_sibling() ), has no effect on the traversal logic.

My questions is if the way things are done now has a good purpose in making a copy of the reference to the current node. And if not, can you provide this custom traversal functionality? I think it's of benefit when you want to optimize the traversal based on some criteria...

@zeux
Copy link
Owner

zeux commented Jan 10, 2020

This is somewhat related to #103; I was hoping to provide a functionality for skipping subtrees as part of the new interface.

As for the reference issue, the way it happened is mostly a historical accident - logically, the intention has always been to use a parameter passed by value. Unfortunately, pugxml (which pugixml is a fork of from more than 10 years ago) used a non-const reference argument and I failed to notice it until it was too late in that the backwards compatibility was a significant concern so changing this wasn't possible.

The internal implementation doesn't use xml_node to begin with - it uses a lower level xml_node_struct - so the code naturally has to wrap the object in a node handle that is then discarded.

@DanN91
Copy link
Author

DanN91 commented Jan 11, 2020

I will close this because it's more than covered in #103;

Thank you for considering this.

@DanN91 DanN91 closed this as completed Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants