You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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...
The text was updated successfully, but these errors were encountered:
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.
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 linexml_node arg_for_each(cur)
which wraps the current node and thus a copy of the current node reference is passed tofor_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 thexml_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 notarg_for_each
, butcur
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...
The text was updated successfully, but these errors were encountered: