Boost & Spirit : How to reverse iterate a tree?
I've got an abstract symbol tree to reverse parse but as far as I can see there isn't a reverse iterator for it.
It's going to sit in a big recursive function that passes an iterator for the children of each node on to itself. Here's the forward iterator version:
ProcessNode(boost::spirit::tree_match<char const*>::const_tree_iterator nodeIter)
{
boost::spirit::tree_match<char const*>::const_tree_iterator iter_t;
for(iter_t = nodeIter->children.begin(); iter_t != nodeIter->children.end(); iter_t++)
{
ProcessNode(iter_t);
}
}
Now if I want to go backwards what do I use?
so far I have this, but I don't trust it and haven't tested fully if it works yet, but I doubt it does work right.
if(nodeIter->children.size() > 0)
{
boost::spirit::tree_match<char const*>::const_tree_iterator iter_t;
for(iter_t = nodeIter->children.begin()+(nodeIter->children.size()-1);
iter_t != nodeIter->children.begin(); iter_t--)
{
ProcessNode(iter_t);
}
}
if(nodeIter->children.size() > 0)
{
boost::spirit::tree_match<char const*>::const_tree_iterator iter_t;
for(iter_t = nodeIter->children.begin()+(nodeIter->children.size()-1);
iter_t != nodeIter->children.begin(); iter_t--)
{
ProcessNode(iter_t);
}
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement