diff --git a/include/hpp/manipulation/graph/state-selector.hh b/include/hpp/manipulation/graph/state-selector.hh index d4b00890ce82b3e419889107a4bfabcf7a3ce3d9..e726ed33b61db968bf12dd0e21087ab343de9d28 100644 --- a/include/hpp/manipulation/graph/state-selector.hh +++ b/include/hpp/manipulation/graph/state-selector.hh @@ -27,7 +27,7 @@ namespace hpp { namespace graph { /// This class is used to get the state of a configuration. States have to /// be ordered because a configuration can be in several states. - class HPP_MANIPULATION_DLLAPI StateSelector : public GraphComponent + class HPP_MANIPULATION_DLLAPI StateSelector { public: virtual ~StateSelector () {}; @@ -35,6 +35,11 @@ namespace hpp { /// Create a new StateSelector. static StateSelectorPtr_t create(const std::string& name); + const std::string& name() const + { + return name_; + } + /// Create an empty state StatePtr_t createState (const std::string& name, bool waypoint = false, const int w = 0); @@ -54,29 +59,21 @@ namespace hpp { /// Select randomly an outgoing edge of the given state. virtual EdgePtr_t chooseEdge(RoadmapNodePtr_t from) const; - /// Should never be called. - void addNumericalConstraint (const constraints::ImplicitPtr_t& /* function */, - const segments_t& /* passiveDofs */ = segments_t ()) - { - throw std::logic_error ("StateSelector component does not have constraints."); - } - - /// Should never be called. - void addLockedJointConstraint - (const constraints::LockedJoint& /* constraint */) - { - throw std::logic_error ("StateSelector component does not have constraints."); - } - /// Print the object in a stream. virtual std::ostream& dotPrint (std::ostream& os, dot::DrawingAttributes da = dot::DrawingAttributes ()) const; + /// Set the parent graph. + void parentGraph(const GraphWkPtr_t& parent); + + /// Set the parent graph. + GraphPtr_t parentGraph() const; + protected: /// Initialization of the object. void init (const StateSelectorPtr_t& weak); /// Constructor - StateSelector (const std::string& name) : GraphComponent (name) + StateSelector (const std::string& name) : name_ (name) {} /// Print the object in a stream. @@ -88,12 +85,21 @@ namespace hpp { WeighedStates_t orderedStates_; States_t waypoints_; - virtual void initialize () { isInit_ = true; }; - private: + /// Name of the component. + std::string name_; + /// A weak pointer to the parent graph. + GraphWkPtr_t graph_; /// Weak pointer to itself. StateSelectorPtr_t wkPtr_; + + friend std::ostream& operator<< (std::ostream& os, const StateSelector& ss); }; // Class StateSelector + + inline std::ostream& operator<< (std::ostream& os, const StateSelector& ss) + { + return ss.print(os); + } } // namespace graph } // namespace manipulation } // namespace hpp diff --git a/src/graph/guided-state-selector.cc b/src/graph/guided-state-selector.cc index 78bad90323861ab17efe14380304bc8c6de3294f..334504c95108c16a7ce974c880026344c96bfae7 100644 --- a/src/graph/guided-state-selector.cc +++ b/src/graph/guided-state-selector.cc @@ -138,12 +138,7 @@ namespace hpp { std::ostream& GuidedStateSelector::print (std::ostream& os) const { - os << "|-- "; - GraphComponent::print (os) << std::endl; - for (WeighedStates_t::const_iterator it = orderedStates_.begin(); - orderedStates_.end() != it; ++it) - os << it->first << " " << *it->second; - return os; + return StateSelector::print (os); } } // namespace graph } // namespace manipulation diff --git a/src/graph/state-selector.cc b/src/graph/state-selector.cc index 657199de108eb64c1ad9ce5f8557c4b7174ead94..6c0e3239cfafdfe0c98437cce580a514713d3ddf 100644 --- a/src/graph/state-selector.cc +++ b/src/graph/state-selector.cc @@ -35,7 +35,6 @@ namespace hpp { void StateSelector::init (const StateSelectorPtr_t& weak) { - GraphComponent::init (weak); wkPtr_ = weak; } @@ -129,13 +128,24 @@ namespace hpp { std::ostream& StateSelector::print (std::ostream& os) const { - os << "|-- "; - GraphComponent::print (os) << std::endl; for (WeighedStates_t::const_iterator it = orderedStates_.begin(); orderedStates_.end() != it; ++it) os << it->first << " " << *it->second; return os; } + + GraphPtr_t StateSelector::parentGraph() const + { + return graph_.lock (); + } + + void StateSelector::parentGraph(const GraphWkPtr_t& parent) + { + graph_ = parent; + GraphPtr_t g = graph_.lock(); + assert(g); + } + } // namespace graph } // namespace manipulation } // namespace hpp