9 #ifndef MRPT_DIRECTED_TREE_H
10 #define MRPT_DIRECTED_TREE_H
50 template <
class TYPE_EDGES = u
int8_t>
61 TEdgeInfo(
TNodeID child_id_,
bool direction_child_to_parent=
false,
const TYPE_EDGES & edge_data = TYPE_EDGES() ) :
id(child_id_),
reverse(direction_child_to_parent),
data(edge_data) { }
96 const size_t next_depth_level = root_depth_level+1;
99 const TListEdges &children = itChildren->second;
110 const size_t next_depth_level = root_depth_level+1;
113 const TListEdges &children = itChildren->second;
132 std::ostringstream s;
135 std::ostringstream &m_s;
136 CMyVisitor(std::ostringstream &s) : m_s(s) { }
138 m_s << std::string(depth_level*5,
' ') << (edge_to_child.
reverse ?
"<-" :
"->" )
139 << edge_to_child.
id << std::endl;
142 CMyVisitor myVisitor(s);
143 s <<
root << std::endl;
< Make available this typedef in this namespace too
void clear()
Empty all edge data and set "root" to INVALID_NODEID.
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 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),...
std::string getAsTextDescription() const
Return a text representation of the tree spanned in a depth-first view, as in this example:
TNodeID root
The root of the tree.
std::list< TEdgeInfo > TListEdges
TMapNode2ListEdges edges_to_children
The edges of each node.
const Scalar * const_iterator
uint64_t TNodeID
The type for node IDs in graphs of different types.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TNodeID id
The ID of the child node.
TYPE_EDGES data
User data for this edge.
TEdgeInfo(TNodeID child_id_, bool direction_child_to_parent=false, const TYPE_EDGES &edge_data=TYPE_EDGES())
Edge constructor from data.
bool reverse
True if edge direction is child->parent, false if it's parent->child.
Virtual base class for user-defined visitors.
CDirectedTree< TYPE_EDGES > tree_t
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...