GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 75.0% 15 / 1 / 21
Functions: 60.0% 3 / 1 / 6
Branches: 71.4% 5 / 1 / 8

src/utilities/filetypes/WorkflowStep.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_WORKFLOWSTEP_HPP
7 #define UTILITIES_FILETYPES_WORKFLOWSTEP_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "../core/Logger.hpp"
12 #include "../data/Variant.hpp"
13
14 #include <json/json.h>
15
16 namespace openstudio {
17 namespace detail {
18 class WorkflowStep_Impl;
19 class WorkflowJSON_Impl;
20 class MeasureStep_Impl;
21 } // namespace detail
22
23 class MeasureType;
24 class WorkflowStepResult;
25
26 /** Base class for defining a step in an OpenStudio Workflow. */
27 class UTILITIES_API WorkflowStep
28 {
29 public:
30 4510 virtual ~WorkflowStep() = default;
31
32 /// Construct from JSON formatted string
33 static boost::optional<WorkflowStep> fromString(const std::string& s);
34
35 /// Serialize to JSON formatted string
36 std::string string() const;
37
38 Json::Value toJSON() const;
39
40 /// Returns the optional WorkflowStepResult
41 boost::optional<WorkflowStepResult> result() const;
42
43 /// Sets the optional WorkflowStepResult
44 void setResult(const WorkflowStepResult& result);
45
46 /// Resets the optional WorkflowStepResult
47 void resetResult();
48
49 /// Tests pointer equality
50 bool operator==(const WorkflowStep& other) const;
51
52 /// cast to type T, can throw std::bad_cast
53 template <typename T>
54 413 T cast() const {
55 413 std::shared_ptr<typename T::ImplType> impl = this->getImpl<typename T::ImplType>();
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 413 times.
413 if (!impl) {
57 ✗ throw(std::bad_cast());
58 }
59
1/1
✓ Branch 3 taken 413 times.
826 return T(std::move(impl));
60 413 }
61
62 /// cast to optional of type T
63 template <typename T>
64 742 boost::optional<T> optionalCast() const {
65 742 boost::optional<T> thisResult;
66 742 std::shared_ptr<typename T::ImplType> impl = this->getImpl<typename T::ImplType>();
67
1/2
✓ Branch 1 taken 742 times.
✗ Branch 2 not taken.
742 if (impl) {
68
2/2
✓ Branch 3 taken 742 times.
✓ Branch 6 taken 742 times.
742 thisResult = T(std::move(impl));
69 }
70 1484 return thisResult;
71 742 }
72
73 protected:
74 // get the impl
75 template <typename T>
76 6057 std::shared_ptr<T> getImpl() const {
77 6057 return std::dynamic_pointer_cast<T>(m_impl);
78 }
79
80 friend class detail::WorkflowStep_Impl;
81 friend class detail::WorkflowJSON_Impl;
82
83 /** Protected constructor from impl. */
84 WorkflowStep(std::shared_ptr<detail::WorkflowStep_Impl> impl);
85
86 private:
87 // configure logging
88 − REGISTER_LOGGER("openstudio.WorkflowStep");
89
90 // pointer to implementation
91 std::shared_ptr<detail::WorkflowStep_Impl> m_impl;
92 };
93
94 /** Base class for defining a step in an OpenStudio Workflow. */
95 class UTILITIES_API MeasureStep : public WorkflowStep
96 {
97 public:
98 // Makes no sense really, providing it for SWIG only now, really for WorkflowJSON::getMeasureStepsWithIndex
99 MeasureStep();
100
101 MeasureStep(const std::string& measureDirName);
102
103 std::string measureDirName() const;
104
105 boost::optional<std::string> name() const;
106 bool setName(const std::string& name);
107 void resetName();
108
109 boost::optional<std::string> description() const;
110 bool setDescription(const std::string& description);
111 void resetDescription();
112
113 boost::optional<std::string> modelerDescription() const;
114 bool setModelerDescription(const std::string& modelerDescription);
115 void resetModelerDescription();
116
117 std::map<std::string, Variant> arguments() const;
118 boost::optional<Variant> getArgument(const std::string& name) const;
119
120 void setArgument(const std::string& name, const Variant& value);
121 void setArgument(const std::string& name, bool value);
122 void setArgument(const std::string& name, double value);
123 void setArgument(const std::string& name, int value);
124 void setArgument(const std::string& name, const char* value);
125 void setArgument(const std::string& name, const std::string& value);
126
127 void removeArgument(const std::string& name);
128
129 void clearArguments();
130
131 protected:
132 MeasureStep(std::shared_ptr<detail::MeasureStep_Impl> impl);
133
134 bool setMeasureDirName(const std::string& measureDirName);
135
136 private:
137 using ImplType = detail::MeasureStep_Impl;
138
139 friend class WorkflowStep;
140 friend class detail::WorkflowJSON_Impl;
141
142 // configure logging
143 REGISTER_LOGGER("openstudio.MeasureStep");
144 };
145
146 UTILITIES_API std::ostream& operator<<(std::ostream& os, const WorkflowStep& workflowStep);
147
148 } // namespace openstudio
149
150 #endif //UTILITIES_FILETYPES_WORKFLOWSTEP_HPP
151