YARP
Yet Another Robot Platform
node.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 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_
std::vector< GyPoint > points
Definition: node.h:33
virtual ~GraphicModel()=default
a Node of a Graph
Definition: node.h:68
NodeType getType()
Definition: node.h:95
GraphicModel * getModel()
Definition: node.h:108
int sucCount()
Definition: node.h:98
bool isVisited()
Definition: node.h:90
void removeAllSuc()
Definition: node.cpp:42
void setSatisfied(bool sat)
Definition: node.h:87
bool addSuc(Node *node, float weight, bool _virtual=false)
class Node
Definition: node.cpp:18
bool hasSuc(Node *node)
Definition: node.cpp:49
Node(NodeType _type, const char *szLabel)
Definition: node.h:77
Node(NodeType _type)
Definition: node.h:71
bool isLeaf()
Definition: node.h:91
Link & getLinkAt(int index)
Definition: node.h:99
void setModel(GraphicModel *mdl)
Definition: node.h:109
bool isSatisfied()
Definition: node.h:88
bool removeSuc(Node *node)
Definition: node.cpp:31
virtual ~Node()
Definition: node.h:85
void setLabel(const char *szLabel)
Definition: node.h:96
const char * getLabel()
Definition: node.h:97
void setVisited(bool vis)
Definition: node.h:89
virtual Node * clone()=0
std::vector< Link >::iterator LinkIterator
Definition: node.h:26
std::vector< Node * > NodePVector
Definition: kbase.h:29
enum yarp::manager::__NodeType NodeType
std::vector< Node * >::iterator NodePVIterator
Definition: kbase.h:30
std::vector< Link > LinkContainer
Definition: node.h:23
The main, catch-all namespace for YARP.
Definition: dirs.h:19