YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
14
15
16namespace yarp::manager {
17
18class Node;
19class Link;
20
21typedef std::vector<Link> LinkContainer;
22typedef std::vector<Link>::iterator LinkIterator;
23
25
26public:
27 GraphicModel() = default;
28 virtual ~GraphicModel() = default;
29 std::vector<GyPoint> points;
30};
31
32
33
37class Link {
38
39public:
40 Link(Node* to, float weight, bool virtualLink=false) {
41 fWeight = weight;
42 connectTo = to;
43 bVirtual = virtualLink;
44 }
45 virtual ~Link(){}
46 Node* to() { return connectTo; }
47 void setWeight(float w) { fWeight = w; }
48 float weight() { return fWeight; }
49 void setVirtual(bool virtualLink) { bVirtual = virtualLink;}
50 bool isVirtual(){ return bVirtual; }
51protected:
52
53private:
54 bool bVirtual;
55 float fWeight;
56 Node* connectTo;
57};
58
59
60
64class Node {
65
66public:
67 Node(NodeType _type){
68 type = _type;
69 bSatisfied = false;
70 bVisited = false;
71 model = nullptr;
72 }
73 Node(NodeType _type, const char* szLabel ){
74 type = _type;
75 bSatisfied = false;
76 bVisited = false;
77 model = nullptr;
78 if(szLabel) { label = szLabel; }
79 }
80
81 virtual ~Node() { model = nullptr; }
82
83 void setSatisfied(bool sat) { bSatisfied = sat; }
84 bool isSatisfied() { return bSatisfied; }
85 void setVisited(bool vis) { bVisited = vis; }
86 bool isVisited() { return bVisited; }
87 bool isLeaf() {
88 return ((sucCount()==0) ? true : false);
89 }
90
91 NodeType getType() { return type; }
92 void setLabel(const char* szLabel) { if(szLabel) { label = szLabel; } }
93 const char* getLabel() { return label.c_str(); }
94 int sucCount() { return static_cast<int>(sucessors.size()); }
95 Link &getLinkAt(int index) { return sucessors[index]; }
96
97
98 bool addSuc(Node* node, float weight, bool _virtual=false);
99 bool removeSuc(Node* node);
100 void removeAllSuc();
101 bool hasSuc(Node* node);
102 virtual Node* clone() = 0;
103
104 GraphicModel* getModel() { return model;}
105 void setModel(GraphicModel* mdl) { model = mdl; };
106
107
108protected:
109
110private:
111 LinkIterator findSuc(Node* node);
112 LinkContainer sucessors;
113 bool bSatisfied;
114 bool bVisited;
115 NodeType type;
116 std::string label;
117 GraphicModel* model;
118};
119
120typedef std::vector<Node*> NodePVector;
121typedef std::vector<Node*>::iterator NodePVIterator;
122
123} // namespace yarp::manager
124
125
126#endif // __YARP_MANAGER_NODE_
std::vector< GyPoint > points
Definition node.h:29
virtual ~GraphicModel()=default
a Node of a Graph
Definition node.h:64
NodeType getType()
Definition node.h:91
virtual Node * clone()=0
bool isVisited()
Definition node.h:86
void removeAllSuc()
Definition node.cpp:40
GraphicModel * getModel()
Definition node.h:104
Link & getLinkAt(int index)
Definition node.h:95
void setSatisfied(bool sat)
Definition node.h:83
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:73
Node(NodeType _type)
Definition node.h:67
bool isLeaf()
Definition node.h:87
void setModel(GraphicModel *mdl)
Definition node.h:105
bool isSatisfied()
Definition node.h:84
bool removeSuc(Node *node)
Definition node.cpp:28
virtual ~Node()
Definition node.h:81
void setLabel(const char *szLabel)
Definition node.h:92
void setVisited(bool vis)
Definition node.h:85
const char * getLabel()
Definition node.h:93
std::vector< Link >::iterator LinkIterator
Definition node.h:22
std::vector< Node * > NodePVector
Definition kbase.h:25
enum yarp::manager::__NodeType NodeType
std::vector< Node * >::iterator NodePVIterator
Definition kbase.h:26
std::vector< Link > LinkContainer
Definition node.h:21