9 #ifndef MRPT_DIRECTED_TREE_H
10 #define MRPT_DIRECTED_TREE_H
34 template <
class TYPE_EDGES = u
int8_t>
76 const size_t next_depth_level = root_depth_level+1;
78 if (itChildren==edges_to_children.end())
return;
79 const TListEdges &children = itChildren->second;
82 user_visitor.
OnVisitNode(root,*itEdge,next_depth_level);
90 const size_t next_depth_level = root_depth_level+1;
92 if (itChildren==edges_to_children.end())
return;
93 const TListEdges &children = itChildren->second;
95 user_visitor.
OnVisitNode(root,*itEdge,next_depth_level);
112 std::ostringstream s;
115 std::ostringstream &m_s;
116 CMyVisitor(std::ostringstream &s) : m_s(s) { }
118 m_s << std::string(depth_level*5,
' ') << (edge_to_child.
reverse ?
"<-" :
"->" )
119 << edge_to_child.
id << std::endl;
122 CMyVisitor myVisitor(s);
123 s << root << std::endl;
void visitBreadthFirst(const TNodeID root, Visitor &user_visitor, const size_t root_depth_level=0) const
Breadth-first visit of all children nodes of a given root (itself excluded from the visit)...
TMapNode2ListEdges edges_to_children
The edges of each node.
A special kind of graph in the form of a tree with directed edges and optional edge annotations of te...
std::list< TEdgeInfo > TListEdges
const Scalar * const_iterator
CDirectedTree< TYPE_EDGES > tree_t
Virtual base class for user-defined visitors.
bool reverse
True if edge direction is child->parent, false if it's parent->child.
std::string getAsTextDescription() const
Return a text representation of the tree spanned in a depth-first view, as in this example: ...
virtual void OnVisitNode(const TNodeID parent, const typename tree_t::TEdgeInfo &edge_to_child, const size_t depth_level)=0
Virtual method to be implemented by the user and which will be called during the visit to a graph wit...
TNodeID root
The root of the tree.
TNodeID id
The ID of the child node.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
uint64_t TNodeID
The type for node IDs in graphs of different types.
TYPE_EDGES data
User data for this edge.
std::map< TNodeID, TListEdges > TMapNode2ListEdges
void visitDepthFirst(const TNodeID root, Visitor &user_visitor, const size_t root_depth_level=0) const
Depth-first visit of all children nodes of a given root (itself excluded from the visit)...
void clear()
Empty all edge data and set "root" to INVALID_NODEID.