@@ -40,74 +40,77 @@ class InvalidArguments : public PowerGridError {
40
40
41
41
template <std::same_as<TypeValuePair>... Options>
42
42
InvalidArguments (std::string const & method, std::string const & arguments) {
43
- append_msg (method + " is not implemented for " + arguments + " !\n " );
43
+ append_msg (std::format ( " {} is not implemented for {} !\n " , method, arguments) );
44
44
}
45
45
46
46
template <class ... Options>
47
47
requires (std::same_as<std::remove_cvref_t <Options>, TypeValuePair> && ...)
48
48
InvalidArguments (std::string const & method, Options const &... options)
49
49
: InvalidArguments{method, " the following combination of options" } {
50
- (append_msg (" " + options.name + " : " + options.value + " \n " ), ...);
50
+ (append_msg (std::format ( " {}: {} \n " , options.name , options.value ) ), ...);
51
51
}
52
52
};
53
53
54
54
class MissingCaseForEnumError : public InvalidArguments {
55
55
public:
56
56
template <typename T>
57
57
MissingCaseForEnumError (std::string const & method, T const & value)
58
- : InvalidArguments{method, std::string{ typeid (T). name ()} + " # " + detail::to_string ( static_cast <IntS>(value))} {
59
- }
58
+ : InvalidArguments{method,
59
+ std::format ( " {} #{} " , typeid (T). name (), detail::to_string ( static_cast <IntS>(value)))} { }
60
60
};
61
61
62
62
class ConflictVoltage : public PowerGridError {
63
63
public:
64
64
ConflictVoltage (ID id, ID id1, ID id2, double u1, double u2) {
65
- append_msg (" Conflicting voltage for line " + detail::to_string (id) + " \n voltage at from node " +
66
- detail::to_string (id1) + " is " + detail::to_string (u1) + " \n voltage at to node " +
67
- detail::to_string (id2) + " is " + detail::to_string (u2) + ' \n ' );
65
+ append_msg (std::format (
66
+ " Conflicting voltage for line {}\n voltage at from node {} is {}\n voltage at to node {} is {}\n " ,
67
+ detail::to_string (id), detail::to_string (id1), detail::to_string (u1), detail::to_string (id2),
68
+ detail::to_string (u2)));
68
69
}
69
70
};
70
71
71
72
class InvalidBranch : public PowerGridError {
72
73
public:
73
74
InvalidBranch (ID branch_id, ID node_id) {
74
- append_msg (" Branch " + detail::to_string (branch_id) + " has the same from- and to-node " +
75
- detail::to_string (node_id) + " , \n This is not allowed! \n " );
75
+ append_msg (std::format ( " Branch {} has the same from- and to-node {}, \n This is not allowed! \n " ,
76
+ detail::to_string (branch_id), detail::to_string (node_id)) );
76
77
}
77
78
};
78
79
79
80
class InvalidBranch3 : public PowerGridError {
80
81
public:
81
82
InvalidBranch3 (ID branch3_id, ID node_1_id, ID node_2_id, ID node_3_id) {
82
- append_msg (" Branch3 " + detail::to_string (branch3_id) +
83
- " is connected to the same node at least twice. Node 1/2/3: " + detail::to_string (node_1_id) + " /" +
84
- detail::to_string (node_2_id) + " /" + detail::to_string (node_3_id) + " ,\n This is not allowed!\n " );
83
+ append_msg (std::format (
84
+ " Branch3 {} is connected to the same node at least twice. Node 1/2/3: {}/{}/{},\n This is not allowed!\n " ,
85
+ detail::to_string (branch3_id), detail::to_string (node_1_id), detail::to_string (node_2_id),
86
+ detail::to_string (node_3_id)));
85
87
}
86
88
};
87
89
88
90
class InvalidTransformerClock : public PowerGridError {
89
91
public:
90
92
InvalidTransformerClock (ID id, IntS clock) {
91
- append_msg (" Invalid clock for transformer " + detail::to_string (id) + " , clock " + detail::to_string (clock ) +
92
- ' \n ' );
93
+ append_msg (std::format ( " Invalid clock for transformer {} , clock {} \n " , detail::to_string (id),
94
+ detail::to_string ( clock )) );
93
95
}
94
96
};
95
97
96
98
class SparseMatrixError : public PowerGridError {
97
99
public:
98
100
SparseMatrixError (Idx err, std::string const & msg = " " ) {
99
- append_msg (" Sparse matrix error with error code #" + detail::to_string (err) + " (possibly singular)\n " );
101
+ append_msg (
102
+ std::format (" Sparse matrix error with error code #{} (possibly singular)\n " , detail::to_string (err)));
100
103
if (!msg.empty ()) {
101
- append_msg (msg + " \n " );
104
+ append_msg (std::format ( " {} \n " , msg) );
102
105
}
103
106
append_msg (" If you get this error from state estimation, " );
104
107
append_msg (" it usually means the system is not fully observable, i.e. not enough measurements." );
105
108
}
106
109
SparseMatrixError () {
107
- append_msg (" Sparse matrix error, possibly singular matrix!\n " +
108
- std::string ( " If you get this error from state estimation, " ) +
109
- " it might mean the system is not fully observable, i.e. not enough measurements.\n " +
110
- " It might also mean that you are running into a corner case where PGM cannot resolve yet." +
110
+ append_msg (" Sparse matrix error, possibly singular matrix!\n "
111
+ " If you get this error from state estimation, "
112
+ " it might mean the system is not fully observable, i.e. not enough measurements.\n "
113
+ " It might also mean that you are running into a corner case where PGM cannot resolve yet."
111
114
" See https://github.com/PowerGridModel/power-grid-model/issues/864." );
112
115
}
113
116
};
@@ -117,7 +120,7 @@ class NotObservableError : public PowerGridError {
117
120
NotObservableError (std::string const & msg = " " ) {
118
121
append_msg (" Not enough measurements available for state estimation.\n " );
119
122
if (!msg.empty ()) {
120
- append_msg (msg + " \n " );
123
+ append_msg (std::format ( " {} \n " , msg) );
121
124
}
122
125
}
123
126
};
@@ -126,58 +129,59 @@ class IterationDiverge : public PowerGridError {
126
129
public:
127
130
IterationDiverge () = default ;
128
131
IterationDiverge (Idx num_iter, double max_dev, double err_tol) {
129
- append_msg (" Iteration failed to converge after " + detail::to_string (num_iter) +
130
- " iterations! Max deviation: " + detail::to_string (max_dev) +
131
- " , error tolerance: " + detail::to_string (err_tol) + " . \n " );
132
+ append_msg (
133
+ std::format ( " Iteration failed to converge after {} iterations! Max deviation: {}, error tolerance: {}. \n " ,
134
+ detail::to_string (num_iter), detail::to_string (max_dev), detail::to_string (err_tol)) );
132
135
}
133
136
};
134
137
135
138
class MaxIterationReached : public IterationDiverge {
136
139
public:
137
140
MaxIterationReached (std::string const & msg = " " ) {
138
- append_msg (" Maximum number of iterations reached" + msg + " \n " );
141
+ append_msg (std::format ( " Maximum number of iterations reached{} \n " , msg) );
139
142
}
140
143
};
141
144
142
145
class ConflictID : public PowerGridError {
143
146
public:
144
- explicit ConflictID (ID id) { append_msg (" Conflicting id detected: " + detail::to_string (id) + ' \n ' ); }
147
+ explicit ConflictID (ID id) { append_msg (std::format ( " Conflicting id detected: {} \n " , detail::to_string (id)) ); }
145
148
};
146
149
147
150
class IDNotFound : public PowerGridError {
148
151
public:
149
- explicit IDNotFound (ID id) { append_msg (" The id cannot be found: " + detail::to_string (id) + ' \n ' ); }
152
+ explicit IDNotFound (ID id) { append_msg (std::format ( " The id cannot be found: {} \n " , detail::to_string (id)) ); }
150
153
};
151
154
class Idx2DNotFound : public PowerGridError {
152
155
public:
153
156
explicit Idx2DNotFound (Idx2D id) {
154
- append_msg (" The idx 2d cannot be found: {" + detail::to_string (id. group ) + " , " + detail::to_string (id.pos ) +
155
- " }. \n " );
157
+ append_msg (std::format ( " The idx 2d cannot be found: {{{}, {}}}. \n " , detail::to_string (id.group ),
158
+ detail::to_string (id. pos )) );
156
159
}
157
160
};
158
161
159
162
class InvalidMeasuredObject : public PowerGridError {
160
163
public:
161
164
InvalidMeasuredObject (std::string const & object, std::string const & sensor) {
162
- append_msg (sensor + " measurement is not supported for object of type " + object);
165
+ append_msg (std::format ( " {} measurement is not supported for object of type {} " , sensor, object) );
163
166
}
164
167
};
165
168
166
169
class InvalidMeasuredTerminalType : public PowerGridError {
167
170
public:
168
171
InvalidMeasuredTerminalType (MeasuredTerminalType const terminal_type, std::string const & sensor) {
169
- append_msg (sensor + " measurement is not supported for object of type " +
170
- detail::to_string (static_cast <IntS>(terminal_type)));
172
+ append_msg (std::format ( " {} measurement is not supported for object of type {} " , sensor,
173
+ detail::to_string (static_cast <IntS>(terminal_type) )));
171
174
}
172
175
};
173
176
174
177
class InvalidRegulatedObject : public PowerGridError {
175
178
public:
176
179
InvalidRegulatedObject (std::string const & object, std::string const & regulator) {
177
- append_msg (regulator + " regulator is not supported for object of type " + object);
180
+ append_msg (std::format ( " {} regulator is not supported for object of type {} " , regulator, object) );
178
181
}
179
182
InvalidRegulatedObject (ID id, std::string const & regulator) {
180
- append_msg (regulator + " regulator is not supported for object with ID " + detail::to_string (id));
183
+ append_msg (
184
+ std::format (" {} regulator is not supported for object with ID {}" , regulator, detail::to_string (id)));
181
185
}
182
186
};
183
187
@@ -191,8 +195,9 @@ class DuplicativelyRegulatedObject : public PowerGridError {
191
195
class AutomaticTapCalculationError : public PowerGridError {
192
196
public:
193
197
AutomaticTapCalculationError (ID id) {
194
- append_msg (" Automatic tap changing regulator with tap_side at LV side is not supported. Found at id " +
195
- detail::to_string (id)); // NOSONAR
198
+ append_msg (
199
+ std::format (" Automatic tap changing regulator with tap_side at LV side is not supported. Found at id {}" ,
200
+ detail::to_string (id)));
196
201
}
197
202
};
198
203
@@ -205,7 +210,9 @@ class AutomaticTapInputError : public PowerGridError {
205
210
206
211
class IDWrongType : public PowerGridError {
207
212
public:
208
- explicit IDWrongType (ID id) { append_msg (" Wrong type for object with id " + detail::to_string (id) + ' \n ' ); }
213
+ explicit IDWrongType (ID id) {
214
+ append_msg (std::format (" Wrong type for object with id {}\n " , detail::to_string (id)));
215
+ }
209
216
};
210
217
211
218
class CalculationError : public PowerGridError {
@@ -235,22 +242,22 @@ class InvalidCalculationMethod : public CalculationError {
235
242
class InvalidShortCircuitType : public PowerGridError {
236
243
public:
237
244
explicit InvalidShortCircuitType (FaultType short_circuit_type) {
238
- append_msg (" The short circuit type (" + detail::to_string ( static_cast <IntS>(short_circuit_type)) +
239
- " ) is invalid! \n " );
245
+ append_msg (std::format ( " The short circuit type ({}) is invalid! \n " ,
246
+ detail::to_string ( static_cast <IntS>(short_circuit_type))) );
240
247
}
241
248
InvalidShortCircuitType (bool sym, FaultType short_circuit_type) {
242
- append_msg (" The short circuit type (" + detail::to_string ( static_cast <IntS>(short_circuit_type)) +
243
- " ) does not match the calculation type (symmetric= " + detail::to_string (static_cast <int >(sym)) +
244
- " ) \n " );
249
+ append_msg (std::format ( " The short circuit type ({}) does not match the calculation type (symmetric={}) \n " ,
250
+ detail::to_string (static_cast <IntS>(short_circuit_type)),
251
+ detail::to_string ( static_cast < int >(sym))) );
245
252
}
246
253
};
247
254
248
255
class InvalidShortCircuitPhases : public PowerGridError {
249
256
public:
250
257
InvalidShortCircuitPhases (FaultType short_circuit_type, FaultPhase short_circuit_phases) {
251
- append_msg (" The short circuit phases (" + detail::to_string ( static_cast <IntS>(short_circuit_phases)) +
252
- " ) do not match the short circuit type ( " +
253
- detail::to_string (static_cast <IntS>(short_circuit_type)) + " ) \n " );
258
+ append_msg (std::format ( " The short circuit phases ({}) do not match the short circuit type ({}) \n " ,
259
+ detail::to_string ( static_cast <IntS>(short_circuit_phases)),
260
+ detail::to_string (static_cast <IntS>(short_circuit_type))) );
254
261
}
255
262
};
256
263
@@ -268,7 +275,7 @@ class SerializationError : public PowerGridError {
268
275
269
276
class DatasetError : public PowerGridError {
270
277
public:
271
- explicit DatasetError (std::string const & msg) { append_msg (" Dataset error: " + msg); }
278
+ explicit DatasetError (std::string const & msg) { append_msg (std::format ( " Dataset error: {} " , msg) ); }
272
279
};
273
280
274
281
class ExperimentalFeature : public InvalidArguments {
@@ -283,19 +290,19 @@ class NotImplementedError : public PowerGridError {
283
290
class UnreachableHit : public PowerGridError {
284
291
public:
285
292
UnreachableHit (std::string const & method, std::string const & reason_for_assumption) {
286
- append_msg (" Unreachable code hit when executing " + method +
287
- " . \n The following assumption for unreachability was not met: " + reason_for_assumption +
288
- " . \n This may be a bug in the library \n " );
293
+ append_msg (std::format ( " Unreachable code hit when executing {}. \n The following assumption for unreachability "
294
+ " was not met: {}. \n This may be a bug in the library \n " ,
295
+ method, reason_for_assumption) );
289
296
}
290
297
};
291
298
292
299
class TapSearchStrategyIncompatibleError : public InvalidArguments {
293
300
public:
294
301
template <typename T1, typename T2>
295
302
TapSearchStrategyIncompatibleError (std::string const & method, T1 const & value1, T2 const & value2)
296
- : InvalidArguments{
297
- method, std::string{ typeid (T1). name ()} + " # " + detail::to_string (static_cast <IntS>(value1)) + " and " +
298
- std::string{ typeid (T2). name ()} + " # " + detail::to_string (static_cast <IntS>(value2))} {}
303
+ : InvalidArguments{method, std::format ( " {} #{} and {} #{} " , typeid (T1). name (),
304
+ detail::to_string (static_cast <IntS>(value1)), typeid (T2). name (),
305
+ detail::to_string (static_cast <IntS>(value2) ))} {}
299
306
};
300
307
301
308
} // namespace power_grid_model
0 commit comments