Loading...
Searching...
No Matches
DotGraph.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31#ifndef DOT_GRAPH_H_
32#define DOT_GRAPH_H_
33
34// #include <pair>
35#include "VariableMap.h"
36
37
38namespace drain
39{
40
41
44
45public:
46
47 inline
48 DotLayout() : SprinterLayout("*","[ ]", "=", "\"\""){};
49
50 // inline
51 // DotLayout(const DotLayout & layout) : SprinterLayout("*","[ ]", "=", "\"\""){};
52
53};
54
56typedef std::map<std::string,std::string> amap_t; //map_t m2 = {{"koe", 123.45}};
58
59
61class DotEntity {
62
63public:
64
65 typedef std::initializer_list<std::pair<const char *,const Variable> > init_t;
66 // typedef std::initializer_list<std::pair<const char *,const char *> > init_t;
67
68
69 void setAttributes(const init_t & args);
70
71 drain::VariableMap attributes;
72
75 static
76 const std::string fill;
77
78};
79
80
81
83class DotNode : public DotEntity {
84
85public:
86
87
88
89 template<typename ... TT>
90 DotNode(const TT &... args){
91 setName(args...);
92 }
93
94 DotNode(init_t args){
95 //setName(args...);
96 //attributes["label"] = "";
97 setAttributes(args);
98 }
99
100
101
102 template<typename ... TT>
103 void setName(const TT &... args){
104 std::stringstream sstr;
105 _setName(sstr, args...);
106 name = sstr.str();
107 }
108
110
113 const std::string & getName() const {
114 return name;
115 }
116
117
118protected:
119
120 std::string name;
121
122 template<typename T, typename ... TT>
123 void _setName(std::stringstream & sstr, const T & arg, const TT &... args){
124 sstr << arg;
125 _setName(sstr, args...);
126 }
127
128 void _setName(std::stringstream & sstr){
129 }
130
131
132
133 void _setAttributes(std::stringstream & sstr){
134 name = sstr.str();
135 }
136
137
138 template<typename T, typename ... TT>
139 void _setAttributes(std::stringstream & sstr, const T & arg, const TT &... args){
140 sstr << arg;
141 _setAttributes(sstr, args...);
142 // name = sstr.str();
143 }
144
145
146};
147
149class DotBullit : public DotNode {
150
151public:
152
153 template<typename ... TT>
154 DotBullit(const TT &... args) : DotNode(args...){
155 setAttributes({{"shape","point"}});
156 }
157
158 DotBullit(int index) : DotNode("_B", index){
159 setAttributes({{"shape","point"}});
160 }
161
162};
163
165class DotRankNode : public DotNode {
166
167public:
168
169 DotRankNode(int rank=0) : DotNode("_R", rank){
170 setAttributes({{"style","invis"}});
171 }
172
173};
174
175
176
177std::ostream & operator<<(std::ostream & ostr, const DotNode & node);
178
180class DotHeader : public DotEntity {
181
182public:
183
184
185 inline
186 DotHeader(const init_t & args = {}, const init_t & nodeArgs = {}){
187 setAttributes(args);
188 nodeStyle.setAttributes(nodeArgs);
189 }
190
191
192 void setNodeAttributes(const init_t & args){
193 nodeStyle.setAttributes(args);
194 }
195
196 inline
197 const drain::VariableMap & getNodeAttributes() const {
198 return nodeStyle.attributes;
199 }
200
201protected:
202
203 //DotNode styleNode;
204 DotEntity nodeStyle;
205
206};
207
208std::ostream & operator<<(std::ostream & ostr, const DotHeader & header);
209
210
213
214public:
215
216 DotComment(const std::string & s = "") : comment(s){
217 }
218
219 inline
220 const std::string & str() const {
221 return comment;
222 };
223
224protected:
225
226 std::string comment;
227
228};
229
230
231
232std::ostream & operator<<(std::ostream & ostr, const DotComment & comment);
233
234
236class DotLink : public DotEntity {
237
238public:
239
240 inline
241 DotLink(const DotNode &n1, const DotNode &n2, init_t args = {}): node1(n1), node2(n2){
242 setAttributes(args);
243 }
244
245 const DotNode &node1;
246 const DotNode &node2;
247
248};
249
250std::ostream & operator<<(std::ostream & ostr, const DotLink & link);
251
253class DotRank {
254
255public:
256
257 DotRank(const std::string & s = "same") : rank(s){
258 }
259
260 inline
261 const std::string & str() const {
262 return rank;
263 };
264
265 inline
266 void add(const DotNode & node){
267 nodes.push_back(&node);
268 }
269
270 std::list<const DotNode *> nodes;
271
272
273protected:
274
275 std::string rank;
276
277};
278
279
280
281std::ostream & operator<<(std::ostream & ostr, const DotRank & rank);
282
283
284
285} // ::drain
286
287#endif
288
DOC: Add class description.
Definition DotGraph.h:149
DOC: Add class description.
Definition DotGraph.h:212
DOC: Add class description.
Definition DotGraph.h:61
static const std::string fill
Definition DotGraph.h:76
DOC: Add class description.
Definition DotGraph.h:180
DOC: Add class description.
Definition DotGraph.h:43
DOC: Add class description.
Definition DotGraph.h:83
const std::string & getName() const
Returns the key of this entity.
Definition DotGraph.h:113
DOC: Add class description.
Definition DotGraph.h:165
DOC: Add class description.
Definition DotGraph.h:253
Definition Sprinter.h:605
A map of Variables.
Definition VariableMap.h:61
Definition Data.h:1473
Definition Sprinter.h:136