Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
AstDOTStyleVisitor.h
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21#pragma once
22
23#include <map>
24#include <ostream>
25#include <utility>
26
27#include "antares/expressions/visitors/NodeVisitor.h"
28
29namespace Antares::Expressions::Visitors
30{
39{
46 std::string_view color;
47
54 std::string_view shape;
55
62 std::string_view style;
63};
64
77class AstDOTStyleVisitor: public NodeVisitor<void, std::ostream&>
78{
79public:
83 AstDOTStyleVisitor() = default;
84
93 void NewTreeGraph(std::ostream& os, const std::string& tree_name = "ExpressionTree");
94
102 void EndTreeGraph(std::ostream& os);
103
109 std::string name() const override;
110
120 void operator()(std::ostream& os, const Nodes::Node* root);
121
122private:
123 void visit(const Nodes::SumNode* node, std::ostream& os) override;
124 void visit(const Nodes::SubtractionNode* node, std::ostream& os) override;
125 void visit(const Nodes::MultiplicationNode* node, std::ostream& os) override;
126 void visit(const Nodes::DivisionNode* node, std::ostream& os) override;
127 void visit(const Nodes::EqualNode* node, std::ostream& os) override;
128 void visit(const Nodes::LessThanOrEqualNode* node, std::ostream& os) override;
129 void visit(const Nodes::GreaterThanOrEqualNode* node, std::ostream& os) override;
130 void visit(const Nodes::NegationNode* node, std::ostream& os) override;
131 void visit(const Nodes::VariableNode* node, std::ostream& os) override;
132 void visit(const Nodes::ParameterNode* node, std::ostream& os) override;
133 void visit(const Nodes::LiteralNode* node, std::ostream& os) override;
134 void visit(const Nodes::PortFieldNode* node, std::ostream& os) override;
135 void visit(const Nodes::PortFieldSumNode* node, std::ostream& os) override;
136 void visit(const Nodes::ComponentVariableNode* node, std::ostream& os) override;
137 void visit(const Nodes::ComponentParameterNode* node, std::ostream& os) override;
138
139 void computeNumberNodesPerType();
140 void makeLegend(std::ostream& os);
141
150 unsigned int getNodeID(const Nodes::Node* node);
151
163 void emitNode(unsigned int id,
164 const std::string& label,
165 const BoxStyle& box_style,
166 std::ostream& os);
167
179 void processBinaryOperation(const Nodes::BinaryNode* node,
180 const std::string& label,
181 const BoxStyle& box_style,
182 std::ostream& os);
183
189 std::map<const Nodes::Node*, unsigned int> nodeIds_;
190
196 std::map<std::string, unsigned int> nbNodesPerType_;
197
203 unsigned int nodeCount_ = 0;
204};
205} // namespace Antares::Expressions::Visitors
Definition BinaryNode.h:28
Represents a component parameter node in a syntax tree.
Definition ComponentNode.h:80
Represents a component variable node in a syntax tree.
Definition ComponentNode.h:66
Represents a division node in a syntax tree.
Definition DivisionNode.h:31
Represents an equality comparison node in a syntax tree.
Definition EqualNode.h:31
Represents a greater than or equal comparison node in a syntax tree.
Definition GreaterThanOrEqualNode.h:31
Represents a less than or equal comparison node in a syntax tree.
Definition LessThanOrEqualNode.h:31
Represents a literal node in a syntax tree, storing a double value.
Definition LiteralNode.h:11
Represents a multiplication node in a syntax tree.
Definition MultiplicationNode.h:31
Represents a negation node in a syntax tree.
Definition NegationNode.h:31
Base class for nodes in a syntax tree.
Definition Node.h:30
Represents a parameter node in a syntax tree, storing a string value.
Definition ParameterNode.h:19
Represents a port field node in a syntax tree.
Definition PortFieldNode.h:33
Represents a port field node where the expression is a sum.
Definition PortFieldSumNode.h:33
Represents a subtraction node in a syntax tree.
Definition SubtractionNode.h:31
Represents a variable node in a syntax tree, storing a string value.
Definition VariableNode.h:20
A visitor class for generating DOT style output for ASTs (Abstract Syntax Trees).
Definition AstDOTStyleVisitor.h:78
AstDOTStyleVisitor()=default
Default constructor.
void EndTreeGraph(std::ostream &os)
Ends the current tree graph.
Definition AstDOTStyleVisitor.cpp:244
void NewTreeGraph(std::ostream &os, const std::string &tree_name="ExpressionTree")
Begins a new tree graph.
Definition AstDOTStyleVisitor.cpp:238
std::string name() const override
Returns the name of this visitor.
Definition AstDOTStyleVisitor.cpp:185
void operator()(std::ostream &os, const Nodes::Node *root)
Outputs the DOT representation of a node to a stream.
Definition AstDOTStyleVisitor.cpp:261
Represents the style attributes for a box in a graph.
Definition AstDOTStyleVisitor.h:39
std::string_view style
The style of the box.
Definition AstDOTStyleVisitor.h:62
std::string_view shape
The shape of the box.
Definition AstDOTStyleVisitor.h:54
std::string_view color
The color of the box.
Definition AstDOTStyleVisitor.h:46