YARP
Yet Another Robot Platform
node.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_MANAGER_NODE
10 #define YARP_MANAGER_NODE
11 
12 #include <iostream>
13 #include <vector>
14 #include <string>
15 
16 #include <yarp/manager/ymm-types.h>
17 
18 
19 namespace yarp {
20 namespace manager {
21 
22 class Node;
23 class Link;
24 
25 typedef std::vector<Link> LinkContainer;
26 typedef std::vector<Link>::iterator LinkIterator;
27 
28 class GraphicModel {
29 
30 public:
31  GraphicModel() = default;
32  virtual ~GraphicModel() = default;
33  std::vector<GyPoint> points;
34 };
35 
36 
37 
41 class Link {
42 
43 public:
44  Link(Node* to, float weight, bool virtualLink=false) {
45  fWeight = weight;
46  connectTo = to;
47  bVirtual = virtualLink;
48  }
49  virtual ~Link(){}
50  Node* to() { return connectTo; }
51  void setWeight(float w) { fWeight = w; }
52  float weight() { return fWeight; }
53  void setVirtual(bool virtualLink) { bVirtual = virtualLink;}
54  bool isVirtual(){ return bVirtual; }
55 protected:
56 
57 private:
58  bool bVirtual;
59  float fWeight;
60  Node* connectTo;
61 };
62 
63 
64 
68 class Node {
69 
70 public:
71  Node(NodeType _type){
72  type = _type;
73  bSatisfied = false;
74  bVisited = false;
75  model = nullptr;
76  }
77  Node(NodeType _type, const char* szLabel ){
78  type = _type;
79  bSatisfied = false;
80  bVisited = false;
81  model = nullptr;
82  if(szLabel) { label = szLabel; }
83  }
84 
85  virtual ~Node() { model = nullptr; }
86 
87  void setSatisfied(bool sat) { bSatisfied = sat; }
88  bool isSatisfied() { return bSatisfied; }
89  void setVisited(bool vis) { bVisited = vis; }
90  bool isVisited() { return bVisited; }
91  bool isLeaf() {
92  return ((sucCount()==0) ? true : false);
93  }
94 
95  NodeType getType() { return type; }
96  void setLabel(const char* szLabel) { if(szLabel) { label = szLabel; } }
97  const char* getLabel() { return label.c_str(); }
98  int sucCount() { return static_cast<int>(sucessors.size()); }
99  Link &getLinkAt(int index) { return sucessors[index]; }
100 
101 
102  bool addSuc(Node* node, float weight, bool _virtual=false);
103  bool removeSuc(Node* node);
104  void removeAllSuc();
105  bool hasSuc(Node* node);
106  virtual Node* clone() = 0;
107 
108  GraphicModel* getModel() { return model;}
109  void setModel(GraphicModel* mdl) { model = mdl; };
110 
111 
112 protected:
113 
114 private:
115  LinkIterator findSuc(Node* node);
116  LinkContainer sucessors;
117  bool bSatisfied;
118  bool bVisited;
119  NodeType type;
120  std::string label;
121  GraphicModel* model;
122 };
123 
124 typedef std::vector<Node*> NodePVector;
125 typedef std::vector<Node*>::iterator NodePVIterator;
126 
127 } // namespace yarp
128 } // namespace manager
129 
130 
131 #endif // __YARP_MANAGER_NODE_
yarp::manager::GraphicModel::GraphicModel
GraphicModel()=default
yarp::manager::GraphicModel::~GraphicModel
virtual ~GraphicModel()=default
yarp::manager::NodePVector
std::vector< Node * > NodePVector
Definition: kbase.h:29
yarp::manager::Node::getLabel
const char * getLabel()
Definition: node.h:97
yarp::manager::Node::setLabel
void setLabel(const char *szLabel)
Definition: node.h:96
yarp::manager::Node::clone
virtual Node * clone()=0
yarp::manager::Node::setVisited
void setVisited(bool vis)
Definition: node.h:89
yarp::manager::Node::Node
Node(NodeType _type, const char *szLabel)
Definition: node.h:77
yarp::manager::LinkContainer
std::vector< Link > LinkContainer
Definition: node.h:23
yarp::manager::Node::sucCount
int sucCount()
Definition: node.h:98
yarp::manager::Node::removeAllSuc
void removeAllSuc()
Definition: node.cpp:42
yarp::manager::GraphicModel::points
std::vector< GyPoint > points
Definition: node.h:33
yarp::manager::Node::isLeaf
bool isLeaf()
Definition: node.h:91
yarp::manager::Node::getModel
GraphicModel * getModel()
Definition: node.h:108
yarp::manager::Node
a Node of a Graph
Definition: node.h:68
yarp::manager::Node::addSuc
bool addSuc(Node *node, float weight, bool _virtual=false)
class Node
Definition: node.cpp:18
yarp::manager::Node::getType
NodeType getType()
Definition: node.h:95
ymm-types.h
yarp::manager::Node::Node
Node(NodeType _type)
Definition: node.h:71
yarp::manager::Node::setModel
void setModel(GraphicModel *mdl)
Definition: node.h:109
yarp::manager::NodePVIterator
std::vector< Node * >::iterator NodePVIterator
Definition: kbase.h:30
yarp::manager::LinkIterator
std::vector< Link >::iterator LinkIterator
Definition: node.h:26
yarp::manager::Node::removeSuc
bool removeSuc(Node *node)
Definition: node.cpp:31
yarp::manager::Node::getLinkAt
Link & getLinkAt(int index)
Definition: node.h:99
yarp::manager::GraphicModel
Definition: node.h:28
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::manager::Node::~Node
virtual ~Node()
Definition: node.h:85
yarp::manager::Node::setSatisfied
void setSatisfied(bool sat)
Definition: node.h:87
yarp::manager::Node::hasSuc
bool hasSuc(Node *node)
Definition: node.cpp:49
yarp::manager::Node::isVisited
bool isVisited()
Definition: node.h:90
yarp::manager::NodeType
enum yarp::manager::__NodeType NodeType
yarp::manager::Node::isSatisfied
bool isSatisfied()
Definition: node.h:88