DPsim
Loading...
Searching...
No Matches
Graph.h
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <map>
12
13#include <graphviz/cgraph.h>
14
16
17namespace CPS {
18namespace Graph {
19
20enum class Type { undirected, directed };
21
22class Graph;
23
24class Element {
25
26protected:
27 void *mPtr;
28 int mKind;
29
30public:
31 void set(const String &key, const String &value, bool html = false);
32};
33
34class Node : public Element {
35public:
36 Agnode_t *mNode;
37
38 Node(Graph *g, const String &name);
39};
40
41class Edge : public Element {
42public:
43 Agedge_t *mEdge;
44
45 Edge(Graph *g, const String &name, Node *head, Node *tail);
46};
47
48// See: http://www.graphviz.org/pdf/libguide.pdf
49class Graph : public Element {
50
51protected:
52 std::map<String, Node *> mNodes;
53 std::map<String, Edge *> mEdges;
54
55public:
56 Agraph_t *mGraph;
57
58 Graph(const String &name, Type type, bool strict = false);
59 ~Graph();
60
61 void render(std::ostream &os, const String &layout = "dot",
62 const String &format = "svg");
63
64 Node *addNode(const String &name);
65 Edge *addEdge(const String &name, Node *head, Node *tail);
66
67 Node *node(const String &name);
68 Edge *edge(const String &name);
69};
70} // namespace Graph
71} // namespace CPS
Edge(Graph *g, const String &name, Node *head, Node *tail)
Definition Graph.cpp:93
Agedge_t * mEdge
Definition Graph.h:43
void set(const String &key, const String &value, bool html=false)
Definition Graph.cpp:75
Edge * addEdge(const String &name, Node *head, Node *tail)
Definition Graph.cpp:62
Edge * edge(const String &name)
Definition Graph.cpp:73
std::map< String, Edge * > mEdges
Definition Graph.h:53
Agraph_t * mGraph
Definition Graph.h:56
Node * node(const String &name)
Definition Graph.cpp:71
std::map< String, Node * > mNodes
Definition Graph.h:52
Node * addNode(const String &name)
Definition Graph.cpp:54
Graph(const String &name, Type type, bool strict=false)
Definition Graph.cpp:16
void render(std::ostream &os, const String &layout="dot", const String &format="svg")
Definition Graph.cpp:35
Agnode_t * mNode
Definition Graph.h:36
Node(Graph *g, const String &name)
Definition Graph.cpp:87
std::string String
Definition Definitions.h:65