GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 81.8% 9 / 2 / 13
Functions: 77.8% 7 / 2 / 11
Branches: 59.1% 13 / 2 / 24

src/utilities/filetypes/WorkflowStepResult.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_FILETYPES_WORKFLOWSTEPRESULT_HPP
7 #define UTILITIES_FILETYPES_WORKFLOWSTEPRESULT_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "../core/Enum.hpp"
12 #include "../core/Logger.hpp"
13 #include "../core/Path.hpp"
14 #include "../data/Variant.hpp"
15
16 namespace Json {
17 class Value;
18 }
19
20 namespace openstudio {
21
22 namespace detail {
23 class WorkflowStepValue_Impl;
24 class WorkflowStepResult_Impl;
25 } // namespace detail
26 class DateTime;
27 class Variant;
28 class MeasureType;
29 class UUID;
30
31 // Attribute is deprecated
32 class Attribute;
33
34 // clang-format off
35
36 /** \class StepResult
37 * \brief Possible outcomes of running a WorkflowStep.
38 * \details See the OPENSTUDIO_ENUM documentation in utilities/core/Enum.hpp. The actual
39 * macro call is:
40 * \code
41 OPENSTUDIO_ENUM( StepResult,
42 ((Skip)(Skipped)(-2))
43 ((NA)(NotApplicable)(-1))
44 ((Success)(Pass)(0))
45 ((Fail)(Fail)(1))
46 );
47 * \endcode */
48
13/22
openstudio::StepResult::buildStringVec[abi:cxx11](bool):
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 172 times.
✓ Branch 3 taken 64 times.
✓ Branch 6 taken 64 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 64 times.
✓ Branch 12 taken 64 times.
✓ Branch 17 taken 172 times.
✓ Branch 20 taken 172 times.
✓ Branch 23 taken 177 times.
✓ Branch 24 taken 118 times.
✓ Branch 25 taken 59 times.
✓ Branch 26 taken 59 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 59 times.
openstudio::StepResult::enumName[abi:cxx11]():
✗ Branch 1 not taken.
openstudio::operator<<(std::ostream&, openstudio::StepResult const&):
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
685 OPENSTUDIO_ENUM(StepResult,
49 ((Skip)(Skipped)(-2))
50 ((NA)(NotApplicable)(-1))
51 ((Success)(Pass)(0))
52 ((Fail)(Fail)(1))
53 );
54
55 // clang-format on
56
57 /** Class for storing a value set by OSRunner::registerValue. */
58 class UTILITIES_API WorkflowStepValue
59 {
60 public:
61 /** @name Constructors and Destructors */
62 //@{
63
64 WorkflowStepValue(const std::string& name, const Variant& value);
65 WorkflowStepValue(const std::string& name, const std::string& value);
66 WorkflowStepValue(const std::string& name, const char* value);
67 WorkflowStepValue(const std::string& name, double value);
68 WorkflowStepValue(const std::string& name, int value);
69 WorkflowStepValue(const std::string& name, bool value);
70
71 /// Construct from JSON formatted string
72 static boost::optional<WorkflowStepValue> fromString(const std::string& s);
73
74 Json::Value toJSON() const;
75
76 /// Serialize to JSON formatted string
77 std::string string() const;
78
79 //@}
80 /** @name Getters */
81 //@{
82
83 std::string name() const;
84
85 std::string displayName() const;
86
87 boost::optional<std::string> units() const;
88
89 /// get the variant value type
90 VariantType variantType() const;
91
92 /// get value as a Variant
93 Variant valueAsVariant() const;
94
95 /// get value as a bool
96 bool valueAsBoolean() const;
97
98 /// get value as int
99 int valueAsInteger() const;
100
101 /// get value as double
102 double valueAsDouble() const;
103
104 /// get value as string
105 std::string valueAsString() const;
106
107 Json::Value valueAsJSON() const;
108
109 //@}
110 /** @name Setters */
111 //@{
112
113 void setName(const std::string& name);
114
115 void setDisplayName(const std::string& displayName);
116 void resetDisplayName();
117
118 void setUnits(const std::string& units);
119 void resetUnits();
120
121 //@}
122
123 protected:
124 // get the impl
125 template <typename T>
126 1410 std::shared_ptr<T> getImpl() const {
127 1410 return std::dynamic_pointer_cast<T>(m_impl);
128 }
129
130 friend class detail::WorkflowStepValue_Impl;
131
132 /** Protected constructor from impl. */
133 WorkflowStepValue(std::shared_ptr<detail::WorkflowStepValue_Impl> impl);
134
135 private:
136 − REGISTER_LOGGER("openstudio.WorkflowStepValue");
137
138 std::shared_ptr<detail::WorkflowStepValue_Impl> m_impl;
139 };
140
141 /** Class for documenting the outcome of running a UserScript or a Ruleset. There is an overall
142 * result flag (available from value()), and a number of message types. */
143 class UTILITIES_API WorkflowStepResult
144 {
145 public:
146 /** @name Constructors and Destructors */
147 //@{
148
149 /** Default constructor. */
150 WorkflowStepResult();
151
152 /** Copy constructor. */
153 WorkflowStepResult(const WorkflowStepResult& other);
154
155 /// Construct from JSON formatted string
156 static boost::optional<WorkflowStepResult> fromString(const std::string& s);
157
158 Json::Value toJSON() const;
159
160 /// Serialize to JSON formatted string
161 std::string string() const;
162
163 //@}
164 /** @name Getters */
165 //@{
166
167 boost::optional<DateTime> startedAt() const;
168
169 boost::optional<DateTime> completedAt() const;
170
171 boost::optional<MeasureType> measureType() const;
172
173 boost::optional<std::string> measureName() const;
174
175 boost::optional<std::string> measureId() const;
176
177 boost::optional<UUID> measureUUID() const;
178
179 boost::optional<std::string> measureVersionId() const;
180
181 boost::optional<UUID> measureVersionUUID() const;
182
183 boost::optional<DateTime> measureVersionModified() const;
184
185 boost::optional<std::string> measureXmlChecksum() const;
186
187 boost::optional<std::string> measureClassName() const;
188
189 boost::optional<std::string> measureDisplayName() const;
190
191 boost::optional<std::string> measureTaxonomy() const;
192
193 boost::optional<StepResult> stepResult() const;
194
195 boost::optional<std::string> stepInitialCondition() const;
196
197 boost::optional<std::string> stepFinalCondition() const;
198
199 std::vector<std::string> stepErrors() const;
200
201 std::vector<std::string> stepWarnings() const;
202
203 std::vector<std::string> stepInfo() const;
204
205 std::vector<WorkflowStepValue> stepValues() const;
206
207 std::vector<openstudio::path> stepFiles() const;
208
209 boost::optional<std::string> stdOut() const;
210
211 boost::optional<std::string> stdErr() const;
212
213 // method for backwards compatibility with OpenStudio 1.X
214 // returns StepResult if initialized, if not initialized returns Success for backwards compatibility
215 StepResult value() const;
216
217 // method for backwards compatibility with OpenStudio 1.X
218 std::vector<LogMessage> errors() const;
219
220 // method for backwards compatibility with OpenStudio 1.X
221 std::vector<LogMessage> warnings() const;
222
223 // method for backwards compatibility with OpenStudio 1.X
224 std::vector<LogMessage> info() const;
225
226 // method for backwards compatibility with OpenStudio 1.X
227 boost::optional<LogMessage> initialCondition() const;
228
229 // method for backwards compatibility with OpenStudio 1.X
230 boost::optional<LogMessage> finalCondition() const;
231
232 // method for backwards compatibility with OpenStudio 1.X
233 std::vector<Attribute> attributes() const;
234
235 //@}
236 /** @name Setters */
237 //@{
238
239 void setStartedAt(const DateTime& dateTime);
240 void resetStartedAt();
241
242 void setCompletedAt(const DateTime& dateTime);
243 void resetCompletedAt();
244
245 bool setMeasureType(const MeasureType& measureType);
246 void resetMeasureType();
247
248 bool setMeasureName(const std::string& name);
249 void resetMeasureName();
250
251 bool setMeasureId(const std::string& id);
252 void resetMeasureId();
253
254 bool setMeasureUUID(const UUID& uuid);
255 void resetMeasureUUID();
256
257 bool setMeasureVersionId(const std::string& id);
258 void resetMeasureVersionId();
259
260 bool setMeasureVersionUUID(const UUID& uuid);
261 void resetMeasureVersionUUID();
262
263 bool setMeasureVersionModified(const DateTime& versionModified);
264 void resetMeasureVersionModified();
265
266 bool setMeasureXmlChecksum(const std::string& checksum);
267 void resetMeasureXmlChecksum();
268
269 bool setMeasureClassName(const std::string& className);
270 void resetMeasureClassName();
271
272 bool setMeasureDisplayName(const std::string& displayName);
273 void resetMeasureDisplayName();
274
275 bool setMeasureTaxonomy(const std::string& taxonomy);
276 void resetMeasureTaxonomy();
277
278 void setStepResult(const StepResult& result);
279 void resetStepResult();
280
281 void setStepInitialCondition(const std::string& initialCondition);
282 void resetStepInitialCondition();
283
284 void setStepFinalCondition(const std::string& finalCondition);
285 void resetStepFinalCondition();
286
287 void addStepError(const std::string& error);
288 void resetStepErrors();
289
290 void addStepWarning(const std::string& warning);
291 void resetStepWarnings();
292
293 void addStepInfo(const std::string& info);
294 void resetStepInfo();
295
296 void addStepValue(const WorkflowStepValue& value);
297 void resetStepValues();
298
299 void addStepFile(const openstudio::path& path);
300 void resetStepFiles();
301
302 void setStdOut(const std::string& stdOut);
303 void resetStdOut();
304
305 void setStdErr(const std::string& stdErr);
306 void resetStdErr();
307
308 //@}
309 /** @name Other */
310 //@{
311
312 // Print the result to stdout
313 void showOutput() const;
314
315 //@}
316
317 protected:
318 // get the impl
319 template <typename T>
320 2854 std::shared_ptr<T> getImpl() const {
321 2854 return std::dynamic_pointer_cast<T>(m_impl);
322 }
323
324 friend class detail::WorkflowStepResult_Impl;
325
326 /** Protected constructor from impl. */
327 WorkflowStepResult(std::shared_ptr<detail::WorkflowStepResult_Impl> impl);
328
329 private:
330 − REGISTER_LOGGER("openstudio.WorkflowStepResult");
331
332 std::shared_ptr<detail::WorkflowStepResult_Impl> m_impl;
333 };
334
335 UTILITIES_API std::ostream& operator<<(std::ostream& os, const WorkflowStepResult& workflowStepResult);
336
337 } // namespace openstudio
338
339 #endif // UTILITIES_FILETYPES_WORKFLOWSTEPRESULT_HPP
340