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
{{ message }}
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
ticpp has the NextSibling family of functions for getting the next node at the same level of the XML tree, as well as Parent and FirstChild for navigating up and down the XML tree. It also has iterators that will iterate over all siblings at a given level, but, as far as I can tell, not all nodes of the tree.
I need to be able to find the next node in the XML tree, be it a sibling, parent, or child, so I came up with this:
ticpp::Node* NextNode(ticpp::Node* node)
{
ticpp::Node* result;
if ((result = node->FirstChild(false)) || (result = node->NextSibling(false)))
return result;
else
{
// Keep going back up in the tree until we find an orphan (the root of the tree).// or an ancestor that has a sibling --- a (great-)*(grand)?uncle, if you will.while ((node = node->Parent(false)) && !(result = node->NextSibling(false)))
{ }
return result; // may be "parent of root", i.e. nullptr
}
}
The function can then be called repeatedly using the return value from the previous call as the argument:
while (node && someCondition)
node = node.NextNode(node);
Aside from the fact that the NextNode function can cause a memory leak when node->Parent() returns the root of the tree (as described in #61), it seems strange to me that a similar function apparently does not exist in ticpp already. Is there any other, better way to go about getting the next node?
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
ticpp has the
NextSibling
family of functions for getting the next node at the same level of the XML tree, as well asParent
andFirstChild
for navigating up and down the XML tree. It also has iterators that will iterate over all siblings at a given level, but, as far as I can tell, not all nodes of the tree.I need to be able to find the next node in the XML tree, be it a sibling, parent, or child, so I came up with this:
The function can then be called repeatedly using the return value from the previous call as the argument:
while (node && someCondition) node = node.NextNode(node);
Aside from the fact that the
NextNode
function can cause a memory leak whennode->Parent()
returns the root of the tree (as described in #61), it seems strange to me that a similar function apparently does not exist in ticpp already. Is there any other, better way to go about getting the next node?The text was updated successfully, but these errors were encountered: