Skip to content
Snippets Groups Projects
Commit bee9cb88 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add operator<< for all graph::GraphComponents

parent 9815cb64
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,9 @@ namespace hpp { ...@@ -47,6 +47,9 @@ namespace hpp {
/// \param config Configuration that will initialize the projector. /// \param config Configuration that will initialize the projector.
ConfigProjectorPtr_t pathProjector(const Configuration_t config); ConfigProjectorPtr_t pathProjector(const Configuration_t config);
/// Print the object in a stream.
std::ostream& print (std::ostream& os) const;
protected: protected:
/// Initialization of the object. /// Initialization of the object.
void init (const EdgeWkPtr_t& weak, const NodeWkPtr_t& from, void init (const EdgeWkPtr_t& weak, const NodeWkPtr_t& from,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
# define HPP_MANIPULATION_GRAPH_GRAPH_HH # define HPP_MANIPULATION_GRAPH_GRAPH_HH
# include <string> # include <string>
# include <ostream>
# include <hpp/util/assertion.hh> # include <hpp/util/assertion.hh>
# include "hpp/manipulation/robot.hh" # include "hpp/manipulation/robot.hh"
...@@ -30,7 +31,7 @@ namespace hpp { ...@@ -30,7 +31,7 @@ namespace hpp {
namespace manipulation { namespace manipulation {
namespace graph { namespace graph {
/// Define common methods of the graph components. /// Define common methods of the graph components.
class HPP_MANIPULATION_LOCAL GraphComponent class HPP_MANIPULATION_DLLAPI GraphComponent
{ {
public: public:
/// Get the component name. /// Get the component name.
...@@ -59,6 +60,12 @@ namespace hpp { ...@@ -59,6 +60,12 @@ namespace hpp {
return id_; return id_;
} }
/// Print the object in a stream.
virtual std::ostream& print (std::ostream& os) const
{
return os;
}
protected: protected:
void init (const GraphComponentWkPtr_t& weak) void init (const GraphComponentWkPtr_t& weak)
{ {
...@@ -109,6 +116,9 @@ namespace hpp { ...@@ -109,6 +116,9 @@ namespace hpp {
/// NULL pointer if not found. /// NULL pointer if not found.
NodeSelectorPtr_t getNodeSelectorByName (const std::string& name); NodeSelectorPtr_t getNodeSelectorByName (const std::string& name);
/// Print the object in a stream.
std::ostream& print (std::ostream& os) const;
protected: protected:
/// Initialization of the object. /// Initialization of the object.
void init (const GraphWkPtr_t& weak, RobotPtr_t robot); void init (const GraphWkPtr_t& weak, RobotPtr_t robot);
...@@ -133,6 +143,10 @@ namespace hpp { ...@@ -133,6 +143,10 @@ namespace hpp {
}; // Class Graph }; // Class Graph
} // namespace graph } // namespace graph
} // namespace manipulation } // namespace manipulation
HPP_MANIPULATION_DLLAPI std::ostream& operator<< (std::ostream& os,
const hpp::manipulation::graph::GraphComponent& graphComp);
} // namespace hpp } // namespace hpp
#endif // HPP_MANIPULATION_GRAPH_GRAPH_HH #endif // HPP_MANIPULATION_GRAPH_GRAPH_HH
...@@ -45,6 +45,9 @@ namespace hpp { ...@@ -45,6 +45,9 @@ namespace hpp {
/// Select randomly an outgoing edge of the given node. /// Select randomly an outgoing edge of the given node.
virtual EdgePtr_t chooseEdge(const NodePtr_t& node); virtual EdgePtr_t chooseEdge(const NodePtr_t& node);
/// Print the object in a stream.
std::ostream& print (std::ostream& os) const;
protected: protected:
/// Initialization of the object. /// Initialization of the object.
void init (const NodeSelectorPtr_t& weak); void init (const NodeSelectorPtr_t& weak);
......
...@@ -80,6 +80,9 @@ namespace hpp { ...@@ -80,6 +80,9 @@ namespace hpp {
return neighbors_; return neighbors_;
} }
/// Print the object in a stream.
std::ostream& print (std::ostream& os) const;
protected: protected:
/// Initialize the object. /// Initialize the object.
void init (const NodeWkPtr_t& self); void init (const NodeWkPtr_t& self);
......
...@@ -37,6 +37,14 @@ namespace hpp { ...@@ -37,6 +37,14 @@ namespace hpp {
to_ = to; to_ = to;
constraints_ = constraints; constraints_ = constraints;
} }
std::ostream& Edge::print (std::ostream& os) const
{
os << " | | |__ " << name () << " --> "
<< to_.lock ()->name ();
return os;
}
} // namespace graph } // namespace graph
} // namespace manipulation } // namespace manipulation
} // namespace hpp } // namespace hpp
...@@ -73,6 +73,22 @@ namespace hpp { ...@@ -73,6 +73,22 @@ namespace hpp {
} }
return NodeSelectorPtr_t(); return NodeSelectorPtr_t();
} }
std::ostream& Graph::print (std::ostream& os) const
{
os << name () << std::endl;
for (NodeSelectors_t::const_iterator it = nodeSelectors_.begin();
it != nodeSelectors_.end(); it++)
os << *(*it);
return os;
}
} // namespace graph } // namespace graph
} // namespace manipulation } // namespace manipulation
std::ostream& operator<< (std::ostream& os,
const hpp::manipulation::graph::GraphComponent& graphComp)
{
return graphComp.print (os);
}
} // namespace hpp } // namespace hpp
...@@ -66,6 +66,15 @@ namespace hpp { ...@@ -66,6 +66,15 @@ namespace hpp {
size_t n = rand() % neighbors.size(); size_t n = rand() % neighbors.size();
return neighbors[n]; return neighbors[n];
} }
std::ostream& NodeSelector::print (std::ostream& os) const
{
os << " |__ " << name() << std::endl;
for (Nodes_t::const_iterator it = orderedStates_.begin();
orderedStates_.end() != it; it++)
os << *(*it);
return os;
}
} // namespace graph } // namespace graph
} // namespace manipulation } // namespace manipulation
} // namespace hpp } // namespace hpp
...@@ -62,6 +62,15 @@ namespace hpp { ...@@ -62,6 +62,15 @@ namespace hpp {
Configuration_t cfg = config; Configuration_t cfg = config;
return constraints_->apply(cfg) && ( cfg == config ); return constraints_->apply(cfg) && ( cfg == config );
} }
std::ostream& Node::print (std::ostream& os) const
{
os << " | |_ " << name() << std::endl;
for (Edges_t::const_iterator it = neighbors_.begin();
it != neighbors_.end(); it++)
os << *(*it);
return os;
}
} // namespace graph } // namespace graph
} // namespace manipulation } // namespace manipulation
} // namespace hpp } // namespace hpp
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment