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