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

Add static vector to retrieve GraphComponents

parent caecc031
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ namespace hpp { ...@@ -27,6 +27,7 @@ namespace hpp {
HPP_PREDEF_CLASS (Node); HPP_PREDEF_CLASS (Node);
HPP_PREDEF_CLASS (Edge); HPP_PREDEF_CLASS (Edge);
HPP_PREDEF_CLASS (NodeSelector); HPP_PREDEF_CLASS (NodeSelector);
HPP_PREDEF_CLASS (GraphComponent);
typedef boost::shared_ptr < Graph > GraphPtr_t; typedef boost::shared_ptr < Graph > GraphPtr_t;
typedef boost::shared_ptr < Node > NodePtr_t; typedef boost::shared_ptr < Node > NodePtr_t;
typedef boost::shared_ptr < Edge > EdgePtr_t; typedef boost::shared_ptr < Edge > EdgePtr_t;
......
...@@ -45,8 +45,39 @@ namespace hpp { ...@@ -45,8 +45,39 @@ namespace hpp {
name_ = name; name_ = name;
} }
/// Keep track of the create components in order to retrieve them
/// easily.
static std::vector < GraphComponentWkPtr_t > components;
/// Get the component by its ID. The validity of the GraphComponent
/// is not checked.
static GraphComponentWkPtr_t get(int id)
{
HPP_ASSERT (id >= 0 && id < (int)components.size());
return components[id];
};
/// Return the component id.
int id () const
{
return id_;
}
protected:
void init (const GraphComponentWkPtr_t& weak)
{
wkPtr_ = weak;
components.push_back (wkPtr_);
id_ = components.size();
}
GraphComponent() : id_(-1)
{}
private: private:
std::string name_; std::string name_;
GraphComponentWkPtr_t wkPtr_;
int id_;
}; };
......
...@@ -31,6 +31,7 @@ namespace hpp { ...@@ -31,6 +31,7 @@ namespace hpp {
void Edge::init (const EdgeWkPtr_t& weak, const NodeWkPtr_t& from, void Edge::init (const EdgeWkPtr_t& weak, const NodeWkPtr_t& from,
const NodeWkPtr_t& to, const ConstraintPtr_t& constraints) const NodeWkPtr_t& to, const ConstraintPtr_t& constraints)
{ {
GraphComponent::init (weak);
wkPtr_ = weak; wkPtr_ = weak;
from_ = from; from_ = from;
to_ = to; to_ = to;
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
namespace hpp { namespace hpp {
namespace manipulation { namespace manipulation {
namespace graph { namespace graph {
std::vector < GraphComponentWkPtr_t > GraphComponent::components = std::vector < GraphComponentWkPtr_t >();
GraphPtr_t Graph::create(RobotPtr_t robot) GraphPtr_t Graph::create(RobotPtr_t robot)
{ {
Graph* ptr = new Graph; Graph* ptr = new Graph;
...@@ -32,6 +34,7 @@ namespace hpp { ...@@ -32,6 +34,7 @@ namespace hpp {
void Graph::init (const GraphWkPtr_t& weak, RobotPtr_t robot) void Graph::init (const GraphWkPtr_t& weak, RobotPtr_t robot)
{ {
GraphComponent::init (weak);
robot_ = robot; robot_ = robot;
wkPtr_ = weak; wkPtr_ = weak;
} }
......
...@@ -31,6 +31,7 @@ namespace hpp { ...@@ -31,6 +31,7 @@ namespace hpp {
void NodeSelector::init (const NodeSelectorPtr_t& weak) void NodeSelector::init (const NodeSelectorPtr_t& weak)
{ {
GraphComponent::init (weak);
wkPtr_ = weak; wkPtr_ = weak;
} }
......
...@@ -37,6 +37,7 @@ namespace hpp { ...@@ -37,6 +37,7 @@ namespace hpp {
void Node::init (const NodeWkPtr_t& weak) void Node::init (const NodeWkPtr_t& weak)
{ {
GraphComponent::init (weak);
wkPtr_ = weak; wkPtr_ = weak;
} }
......
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