YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Graph.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_PROFILER_GRAP_H
7#define YARP_PROFILER_GRAP_H
8
9#include<yarp/os/Property.h>
10
11#include <iostream>
12#include <vector>
13#include <string>
14
16class Vertex;
17class Edge;
18class Graph;
19class Algorithm;
20class GraphicVertex;
21class OwnedVertex;
22class ProcessVertex;
23class PortVertex;
24class MachineVertex;
25
26} // namespace yarp::profiler::graph
27
28
29typedef std::vector<yarp::profiler::graph::Edge> edge_set;
30typedef edge_set::iterator edge_iterator;
31typedef edge_set::const_iterator edge_const_iterator;
32
33typedef std::vector<yarp::profiler::graph::Vertex*> pvertex_set;
34typedef pvertex_set::iterator pvertex_iterator;
35typedef pvertex_set::const_iterator pvertex_const_iterator;
36
37typedef std::vector<pvertex_set> graph_subset;
38typedef graph_subset::iterator graph_subset_iterator;
39typedef graph_subset::const_iterator graph_subset_const_iterator;
40
41
46public:
47
49 const yarp::profiler::graph::Vertex& secondV,
51
52 Edge(const Edge& edge);
53
54 virtual ~Edge();
55
58 virtual bool operator == (const yarp::profiler::graph::Edge &edge) const;
59
60public:
62
63private:
64 const yarp::profiler::graph::Vertex* firstVertex;
65 const yarp::profiler::graph::Vertex* secondVertex;
66};
67
68
73
74public:
75 Vertex(const yarp::os::Property &prop);
77 virtual ~Vertex();
78
79 const edge_set& outEdges() const { return outs; }
80 const edge_set& inEdges() const { return ins; }
81 size_t degree() const { return ins.size() + outs.size(); }
82
83 virtual bool operator == (const yarp::profiler::graph::Vertex &v1) const = 0;
84 virtual bool operator<(const Vertex &v1) const;
85
86 friend class Graph;
87
88public:
90
91private:
92 void insertOuts(const yarp::profiler::graph::Edge& edge);
93 void insertIns(const yarp::profiler::graph::Edge& edge);
94
95private:
96 edge_set outs;
97 edge_set ins;
98};
99
100
105
106public:
108 //Graph(yarp::profiler::graph::Graph& graph);
109 virtual ~Graph();
110
111 //void insert(Vertex *vertex);
112 pvertex_iterator insert(const Vertex &vertex);
113 void remove(const Vertex &vertex);
114 void remove(const pvertex_iterator vi);
115
116 void insertEdge(const Vertex &v1, const Vertex &v2,
117 const yarp::os::Property &property="");
118
119 void insertEdge(const pvertex_iterator vi1, const pvertex_iterator vi2,
120 const yarp::os::Property &property="");
121
122 const pvertex_iterator find(const Vertex &v1);
123
124 size_t size();
125 size_t nodesCount();
126 const pvertex_set& vertices() { return mVertices; }
127 size_t order() { return mVertices.size(); }
128
129 void clear();
130
131private:
132 pvertex_set mVertices;
133};
134
135
137public:
143 static bool calcSCC(yarp::profiler::graph::Graph& graph, graph_subset &scc);
144};
145
147{
148public:
149 GraphicVertex(const yarp::os::Property &prop) : yarp::profiler::graph::Vertex(prop){
150 graphicItem = nullptr;
151 }
152 void setGraphicItem(void* item) { graphicItem= item; }
153 void* getGraphicItem() { return graphicItem; }
154
155private:
156 void* graphicItem;
157};
158
160{
161public:
162 OwnedVertex(const yarp::os::Property &prop) : yarp::profiler::graph::GraphicVertex(prop)
163 {
164 owner = nullptr;
165 }
167 if (_owner)
168 {
169 owner = _owner;
170 return true;
171 }
172 return false;
173 }
175private:
177
178};
179
181{
182public:
183 PortVertex(const std::string name) : yarp::profiler::graph::OwnedVertex("(type port)") {
184 property.put("name", name);
185 }
186 virtual ~PortVertex(){}
187
188 bool operator == (const yarp::profiler::graph::Vertex &v1) const override {
189 return property.find("name").asString() == v1.property.find("name").asString();
190 }
191
192};
193
195{
196public:
197 ProcessVertex(int pid, const std::string hostname) : yarp::profiler::graph::OwnedVertex("(type process)") {
198 property.put("hostname", hostname);
199 property.put("pid", pid);
200 }
201 virtual ~ProcessVertex(){}
202
203 bool operator == (const yarp::profiler::graph::Vertex &v1) const override {
204 return property.find("hostname").asString() == v1.property.find("hostname").asString() &&
205 property.find("pid").asInt32() == v1.property.find("pid").asInt32();
206 }
207
208};
209
211{
212public:
213 MachineVertex(std::string os, const std::string hostname) : yarp::profiler::graph::GraphicVertex("(type machine)") {
214 property.put("hostname", hostname);
215 property.put("os", os);
216 }
217 virtual ~MachineVertex() {}
218
219 bool operator == (const yarp::profiler::graph::Vertex &v1) const override {
220 return property.find("hostname").asString() == v1.property.find("hostname").asString() &&
221 property.find("os").asString() == v1.property.find("os").asString() &&
222 property.find("type").asString() == v1.property.find("type").asString() ;
223 }
224};
225
226
227#endif // YARP_PROFILER_GRAP_H
graph_subset::const_iterator graph_subset_const_iterator
Definition Graph.h:39
std::vector< pvertex_set > graph_subset
Definition Graph.h:37
edge_set::iterator edge_iterator
Definition Graph.h:30
edge_set::const_iterator edge_const_iterator
Definition Graph.h:31
pvertex_set::const_iterator pvertex_const_iterator
Definition Graph.h:35
graph_subset::iterator graph_subset_iterator
Definition Graph.h:38
std::vector< yarp::profiler::graph::Vertex * > pvertex_set
Definition Graph.h:33
pvertex_set::iterator pvertex_iterator
Definition Graph.h:34
std::vector< yarp::profiler::graph::Edge > edge_set
Definition Graph.h:29
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition Value.cpp:204
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
static bool calcSCC(yarp::profiler::graph::Graph &graph, graph_subset &scc)
calcSCC
Definition Graph.cpp:249
The yarp::profiler::graph::Edge class.
Definition Graph.h:45
virtual bool operator==(const yarp::profiler::graph::Edge &edge) const
Definition Graph.cpp:49
const yarp::profiler::graph::Vertex & second() const
Definition Graph.cpp:44
yarp::os::Property property
Definition Graph.h:61
const yarp::profiler::graph::Vertex & first() const
Definition Graph.cpp:40
The yarp::profiler::graph::Graph class.
Definition Graph.h:104
void insertEdge(const Vertex &v1, const Vertex &v2, const yarp::os::Property &property="")
Definition Graph.cpp:144
const pvertex_set & vertices()
Definition Graph.h:126
const pvertex_iterator find(const Vertex &v1)
Definition Graph.cpp:160
void remove(const Vertex &vertex)
Definition Graph.cpp:131
Graph()
yarp::profiler::graph::Graph
pvertex_iterator insert(const Vertex &vertex)
Definition Graph.cpp:120
GraphicVertex(const yarp::os::Property &prop)
Definition Graph.h:149
void setGraphicItem(void *item)
Definition Graph.h:152
MachineVertex(std::string os, const std::string hostname)
Definition Graph.h:213
bool operator==(const yarp::profiler::graph::Vertex &v1) const override
Definition Graph.h:219
yarp::profiler::graph::Vertex * getOwner()
Definition Graph.h:174
OwnedVertex(const yarp::os::Property &prop)
Definition Graph.h:162
bool setOwner(yarp::profiler::graph::Vertex *_owner)
Definition Graph.h:166
PortVertex(const std::string name)
Definition Graph.h:183
bool operator==(const yarp::profiler::graph::Vertex &v1) const override
Definition Graph.h:188
bool operator==(const yarp::profiler::graph::Vertex &v1) const override
Definition Graph.h:203
ProcessVertex(int pid, const std::string hostname)
Definition Graph.h:197
The yarp::profiler::graph::Vertex class.
Definition Graph.h:72
yarp::os::Property property
Definition Graph.h:89
virtual bool operator<(const Vertex &v1) const
Definition Graph.cpp:86
const edge_set & outEdges() const
Definition Graph.h:79
virtual bool operator==(const yarp::profiler::graph::Vertex &v1) const =0
Vertex(const yarp::profiler::graph::Vertex &vertex)
size_t degree() const
Definition Graph.h:81
const edge_set & inEdges() const
Definition Graph.h:80
The main, catch-all namespace for YARP.
Definition dirs.h:16