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
43
44public:
45
46 inline
47 DotLayout() : SprinterLayout("*","[ ]", "=", "\"\""){};
48
49 // inline
50 // DotLayout(const DotLayout & layout) : SprinterLayout("*","[ ]", "=", "\"\""){};
51
52};
53
55typedef std::map<std::string,std::string> amap_t; //map_t m2 = {{"koe", 123.45}};
57
58
59class DotEntity {
60
61public:
62
63 typedef std::initializer_list<std::pair<const char *,const Variable> > init_t;
64 // typedef std::initializer_list<std::pair<const char *,const char *> > init_t;
65
66
67 void setAttributes(const init_t & args);
68
69 drain::VariableMap attributes;
70
73 static
74 const std::string fill;
75
76};
77
78
79
80class DotNode : public DotEntity {
81
82public:
83
84
85
86 template<typename ... TT>
87 DotNode(const TT &... args){
88 setName(args...);
89 }
90
91 DotNode(init_t args){
92 //setName(args...);
93 //attributes["label"] = "";
94 setAttributes(args);
95 }
96
97
98
99 template<typename ... TT>
100 void setName(const TT &... args){
101 std::stringstream sstr;
102 _setName(sstr, args...);
103 name = sstr.str();
104 }
105
107
110 const std::string & getName() const {
111 return name;
112 }
113
114
115protected:
116
117 std::string name;
118
119 template<typename T, typename ... TT>
120 void _setName(std::stringstream & sstr, const T & arg, const TT &... args){
121 sstr << arg;
122 _setName(sstr, args...);
123 }
124
125 void _setName(std::stringstream & sstr){
126 }
127
128
129
130 void _setAttributes(std::stringstream & sstr){
131 name = sstr.str();
132 }
133
134
135 template<typename T, typename ... TT>
136 void _setAttributes(std::stringstream & sstr, const T & arg, const TT &... args){
137 sstr << arg;
138 _setAttributes(sstr, args...);
139 // name = sstr.str();
140 }
141
142
143};
144
145class DotBullit : public DotNode {
146
147public:
148
149 template<typename ... TT>
150 DotBullit(const TT &... args) : DotNode(args...){
151 setAttributes({{"shape","point"}});
152 }
153
154 DotBullit(int index) : DotNode("_B", index){
155 setAttributes({{"shape","point"}});
156 }
157
158};
159
160class DotRankNode : public DotNode {
161
162public:
163
164 DotRankNode(int rank=0) : DotNode("_R", rank){
165 setAttributes({{"style","invis"}});
166 }
167
168};
169
170
171
172std::ostream & operator<<(std::ostream & ostr, const DotNode & node);
173
174class DotHeader : public DotEntity {
175
176public:
177
178
179 inline
180 DotHeader(const init_t & args = {}, const init_t & nodeArgs = {}){
181 setAttributes(args);
182 nodeStyle.setAttributes(nodeArgs);
183 }
184
185
186 void setNodeAttributes(const init_t & args){
187 nodeStyle.setAttributes(args);
188 }
189
190 inline
191 const drain::VariableMap & getNodeAttributes() const {
192 return nodeStyle.attributes;
193 }
194
195protected:
196
197 //DotNode styleNode;
198 DotEntity nodeStyle;
199
200};
201
202std::ostream & operator<<(std::ostream & ostr, const DotHeader & header);
203
204
206
207public:
208
209 DotComment(const std::string & s = "") : comment(s){
210 }
211
212 inline
213 const std::string & str() const {
214 return comment;
215 };
216
217protected:
218
219 std::string comment;
220
221};
222
223
224
225std::ostream & operator<<(std::ostream & ostr, const DotComment & comment);
226
227
228class DotLink : public DotEntity {
229
230public:
231
232 inline
233 DotLink(const DotNode &n1, const DotNode &n2, init_t args = {}): node1(n1), node2(n2){
234 setAttributes(args);
235 }
236
237 const DotNode &node1;
238 const DotNode &node2;
239
240};
241
242std::ostream & operator<<(std::ostream & ostr, const DotLink & link);
243
244class DotRank {
245
246public:
247
248 DotRank(const std::string & s = "same") : rank(s){
249 }
250
251 inline
252 const std::string & str() const {
253 return rank;
254 };
255
256 inline
257 void add(const DotNode & node){
258 nodes.push_back(&node);
259 }
260
261 std::list<const DotNode *> nodes;
262
263
264protected:
265
266 std::string rank;
267
268};
269
270
271
272std::ostream & operator<<(std::ostream & ostr, const DotRank & rank);
273
274
275
276} // ::drain
277
278#endif
279
Definition DotGraph.h:145
Definition DotGraph.h:205
Definition DotGraph.h:59
static const std::string fill
Definition DotGraph.h:74
Definition DotGraph.h:174
Definition DotGraph.h:42
Definition DotGraph.h:80
const std::string & getName() const
Returns the key of this entity.
Definition DotGraph.h:110
Definition DotGraph.h:160
Definition DotGraph.h:244
Definition Sprinter.h:603
A map of Variables.
Definition VariableMap.h:61
Definition DataSelector.cpp:1277
Definition Sprinter.h:137