diff --git a/include/hpp/manipulation/graph/edge.hh b/include/hpp/manipulation/graph/edge.hh index 57605c59f85761bee1ddaef76623b30060f7ef90..c4d8295a5efba4b5895b7ebe5f7a9239c597d507 100644 --- a/include/hpp/manipulation/graph/edge.hh +++ b/include/hpp/manipulation/graph/edge.hh @@ -33,9 +33,12 @@ namespace hpp { class HPP_MANIPULATION_DLLAPI Edge : public GraphComponent { public: - /// Create a new Edge. - static EdgePtr_t create (const NodeWkPtr_t& from, const NodeWkPtr_t& to, - const ConstraintPtr_t& constraints); + /// Create a new empty Edge. + static EdgePtr_t create (const NodeWkPtr_t& from, const NodeWkPtr_t& to); + + /// Set the constraints of the Edge. + void constraints (const ConstraintPtr_t& constraints) + throw (Bad_function_call); /// Projector to project onto the same leaf as config. /// \return The initialized projector. @@ -53,7 +56,7 @@ namespace hpp { protected: /// Initialization of the object. void init (const EdgeWkPtr_t& weak, const NodeWkPtr_t& from, - const NodeWkPtr_t& to, const ConstraintPtr_t& constraints); + const NodeWkPtr_t& to); /// Constructor Edge() diff --git a/include/hpp/manipulation/graph/fwd.hh b/include/hpp/manipulation/graph/fwd.hh index 719e7d3b4792622104ee5855138e3f84f1c2889c..610da41f93757ca72715c311545c5dce9485c9b2 100644 --- a/include/hpp/manipulation/graph/fwd.hh +++ b/include/hpp/manipulation/graph/fwd.hh @@ -32,6 +32,7 @@ namespace hpp { typedef boost::shared_ptr < Node > NodePtr_t; typedef boost::shared_ptr < Edge > EdgePtr_t; typedef boost::shared_ptr < NodeSelector > NodeSelectorPtr_t; + typedef boost::shared_ptr < GraphComponent > GraphComponentPtr_t; typedef std::vector < NodePtr_t > Nodes_t; typedef std::vector < EdgePtr_t > Edges_t; typedef std::vector < NodeSelectorPtr_t > NodeSelectors_t; diff --git a/include/hpp/manipulation/graph/graph.hh b/include/hpp/manipulation/graph/graph.hh index b38cd3e80191d1881c99b7a5d1ef508409d1dee5..37e732a1e7d91ea029f0c27cdd71fe20dd8e911c 100644 --- a/include/hpp/manipulation/graph/graph.hh +++ b/include/hpp/manipulation/graph/graph.hh @@ -20,6 +20,7 @@ # include <string> # include <ostream> # include <hpp/util/assertion.hh> +# include <hpp/util/exception.hh> # include "hpp/manipulation/robot.hh" @@ -30,6 +31,8 @@ namespace hpp { namespace manipulation { namespace graph { + HPP_MAKE_EXCEPTION ( HPP_MANIPULATION_DLLAPI, Bad_function_call ); + /// Define common methods of the graph components. class HPP_MANIPULATION_DLLAPI GraphComponent { @@ -61,10 +64,11 @@ namespace hpp { } /// Print the object in a stream. - virtual std::ostream& print (std::ostream& os) const - { - return os; - } + virtual std::ostream& print (std::ostream& os) const = 0; + + /// Set the constraints of the component. + virtual void constraints (const ConstraintPtr_t& /* constraints */) + throw (Bad_function_call) = 0; protected: void init (const GraphComponentWkPtr_t& weak) @@ -119,6 +123,13 @@ namespace hpp { /// Print the object in a stream. std::ostream& print (std::ostream& os) const; + /// Should never be called. + virtual void constraints (const ConstraintPtr_t& /* constraints */) + throw (Bad_function_call) + { + HPP_THROW_EXCEPTION (Bad_function_call, "This component does not have constraints."); + } + protected: /// Initialization of the object. void init (const GraphWkPtr_t& weak, RobotPtr_t robot); diff --git a/include/hpp/manipulation/graph/node-selector.hh b/include/hpp/manipulation/graph/node-selector.hh index e042e4a3dafbf1169317bef364529017dac894f1..5b430c175d3d42a71d277f3fee8b6190783b8153 100644 --- a/include/hpp/manipulation/graph/node-selector.hh +++ b/include/hpp/manipulation/graph/node-selector.hh @@ -48,6 +48,12 @@ namespace hpp { /// Print the object in a stream. std::ostream& print (std::ostream& os) const; + /// Should never be called. + virtual void constraints (const ConstraintPtr_t& /* constraints */) + throw (Bad_function_call) + { + HPP_THROW_EXCEPTION (Bad_function_call, "This component does not have constraints."); + } protected: /// Initialization of the object. void init (const NodeSelectorPtr_t& weak); diff --git a/include/hpp/manipulation/graph/node.hh b/include/hpp/manipulation/graph/node.hh index d7c073f89b34d69c78a45872e9df97d3c6c71817..091d434e5a4035228b6ce8f92cd677e5443b6163 100644 --- a/include/hpp/manipulation/graph/node.hh +++ b/include/hpp/manipulation/graph/node.hh @@ -40,7 +40,7 @@ namespace hpp { static NodePtr_t create (const ConstraintPtr_t& constraints); /// Create a link from this node to the given node. - EdgePtr_t linkTo(const NodePtr_t& to, const ConstraintPtr_t& constraints); + EdgePtr_t linkTo(const NodePtr_t& to); /// Check whether the configuration is in this state. /// \return True if this state contains this configuration @@ -58,9 +58,7 @@ namespace hpp { /// Set the constraint set associated to the node. void constraints (const ConstraintPtr_t& constraints) - { - constraints_ = constraints; - } + throw (Bad_function_call); /// Get the parent NodeSelector. NodeSelectorWkPtr_t nodeSelector () @@ -90,6 +88,7 @@ namespace hpp { /// Initialize the object. void init (const NodeWkPtr_t& self, const ConstraintPtr_t& constraints); + /// Constructor Node() {} diff --git a/src/graph/edge.cc b/src/graph/edge.cc index bb20a01545bfc314d3908a3b4db383af7e8d3aff..1d4f40c20ba0bb8f443139cfbf26f4cfc3bf1707 100644 --- a/src/graph/edge.cc +++ b/src/graph/edge.cc @@ -19,23 +19,27 @@ namespace hpp { namespace manipulation { namespace graph { - EdgePtr_t Edge::create (const NodeWkPtr_t& from, const NodeWkPtr_t& to, - const ConstraintPtr_t& constraints) + EdgePtr_t Edge::create (const NodeWkPtr_t& from, const NodeWkPtr_t& to) { Edge* ptr = new Edge; EdgePtr_t shPtr (ptr); - ptr->init(shPtr, from, to, constraints); + ptr->init(shPtr, from, to); return shPtr; } + void Edge::constraints (const ConstraintPtr_t& constraint) + throw (Bad_function_call) + { + constraints_ = constraint; + } + void Edge::init (const EdgeWkPtr_t& weak, const NodeWkPtr_t& from, - const NodeWkPtr_t& to, const ConstraintPtr_t& constraints) + const NodeWkPtr_t& to) { GraphComponent::init (weak); wkPtr_ = weak; from_ = from; to_ = to; - constraints_ = constraints; } std::ostream& Edge::print (std::ostream& os) const diff --git a/src/graph/node.cc b/src/graph/node.cc index 01fe00edc1980e11024fa3881a9557c502a72a23..cbc4480812320bea661d27077a7ac20860e24412 100644 --- a/src/graph/node.cc +++ b/src/graph/node.cc @@ -47,9 +47,15 @@ namespace hpp { constraints(constraint); } - EdgePtr_t Node::linkTo(const NodePtr_t& to, const ConstraintPtr_t& constraints) + void Node::constraints (const ConstraintPtr_t& constraint) + throw (Bad_function_call) { - EdgePtr_t newEdge = Edge::create(wkPtr_, to, constraints); + constraints_ = constraint; + } + + EdgePtr_t Node::linkTo(const NodePtr_t& to) + { + EdgePtr_t newEdge = Edge::create(wkPtr_, to); neighbors_.push_back(newEdge); return newEdge; }