Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
print.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#ifndef __SOLVER_VARIABLE_PRINT_H__
22#define __SOLVER_VARIABLE_PRINT_H__
23
24#include <yuni/yuni.h>
25
26namespace Antares::Solver::Variable
27{
29{
30public:
32 pIndent(0)
33 {
34 }
35
36 template<class VCardT>
37 void beginNode()
38 {
39 printVCard<VCardT, true>();
40 ++pIndent;
41 }
42
43 template<class VCardT>
44 void addVCard()
45 {
46 printVCard<VCardT, false>();
47 }
48
49 void endNode()
50 {
51 --pIndent;
52 }
53
54private:
55 template<class VCardT, bool IsNodeT>
56 void printVCard()
57 {
58 pBuffer.clear();
59 pBuffer.resize(1 + pBuffer.size() + pIndent * 4, " ");
60 pBuffer += (IsNodeT ? "+ " : " ");
61 pBuffer += VCardT::Caption();
62 pBuffer.resize(35, " ");
63 pBuffer += VCardT::Unit();
64 pBuffer.resize(50, " ");
65 pBuffer += VCardT::Description();
66 Antares::logs.info() << pBuffer;
67 }
68
69private:
70 uint pIndent;
71 Yuni::String pBuffer;
72};
73
74template<int I>
76{
77 static const char* Value()
78 {
79 return "%.6f";
80 }
81};
82
83template<>
85{
86 static const char* Value()
87 {
88 return "%.0f";
89 }
90};
91
92template<>
94{
95 static const char* Value()
96 {
97 return "%.1f";
98 }
99};
100
101template<>
103{
104 static const char* Value()
105 {
106 return "%.2f";
107 }
108};
109
110template<>
112{
113 static const char* Value()
114 {
115 return "%.3f";
116 }
117};
118
119template<>
121{
122 static const char* Value()
123 {
124 return "%.4f";
125 }
126};
127
128template<>
130{
131 static const char* Value()
132 {
133 return "%.5f";
134 }
135};
136
137template<class StringT>
138static inline void AssignPrecisionToPrintfFormat(StringT& out, uint precision)
139{
140 switch (precision)
141 {
142 case 0:
143 out.assign("%.0f", 4);
144 break;
145 case 1:
146 out.assign("%.1f", 4);
147 break;
148 case 2:
149 out.assign("%.2f", 4);
150 break;
151 case 3:
152 out.assign("%.3f", 4);
153 break;
154 case 4:
155 out.assign("%.4f", 4);
156 break;
157 case 5:
158 out.assign("%.5f", 4);
159 break;
160 default:
161 out.assign("%.6f", 4);
162 break;
163 }
164}
165
166} // namespace Antares::Solver::Variable
167
168#endif // __SOLVER_VARIABLE_PRINT_H__