GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 69.1% 112 / 0 / 162
Functions: 57.6% 19 / 0 / 33
Branches: 53.0% 132 / 0 / 249

src/model/RunPeriodControlSpecialDays.cpp
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 #include "RunPeriodControlSpecialDays.hpp"
7 #include "RunPeriodControlSpecialDays_Impl.hpp"
8 #include "Model.hpp"
9 #include "Model_Impl.hpp"
10 #include "YearDescription.hpp"
11 #include "YearDescription_Impl.hpp"
12
13 #include <utilities/idd/OS_RunPeriodControl_SpecialDays_FieldEnums.hxx>
14 #include <utilities/idd/IddEnums.hxx>
15 #include <utilities/idd/IddFactory.hxx>
16
17 #include "../utilities/time/Date.hpp"
18 #include "../utilities/core/Assert.hpp"
19
20 #include <boost/regex.hpp>
21
22 namespace openstudio {
23 namespace model {
24
25 namespace detail {
26
27 146 RunPeriodControlSpecialDays_Impl::RunPeriodControlSpecialDays_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
28 146 : ModelObject_Impl(idfObject, model, keepHandle) {
29
4/6
✓ Branch 1 taken 146 times.
✓ Branch 4 taken 146 times.
✓ Branch 7 taken 146 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 146 times.
✗ Branch 13 not taken.
146 OS_ASSERT(idfObject.iddObject().type() == RunPeriodControlSpecialDays::iddObjectType());
30 146 }
31
32 50 RunPeriodControlSpecialDays_Impl::RunPeriodControlSpecialDays_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model,
33 50 bool keepHandle)
34 50 : ModelObject_Impl(other, model, keepHandle) {
35
4/6
✓ Branch 1 taken 50 times.
✓ Branch 4 taken 50 times.
✓ Branch 7 taken 50 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 50 times.
✗ Branch 13 not taken.
50 OS_ASSERT(other.iddObject().type() == RunPeriodControlSpecialDays::iddObjectType());
36 50 }
37
38 13 RunPeriodControlSpecialDays_Impl::RunPeriodControlSpecialDays_Impl(const RunPeriodControlSpecialDays_Impl& other, Model_Impl* model,
39 13 bool keepHandle)
40 13 : ModelObject_Impl(other, model, keepHandle) {}
41
42 20 Date RunPeriodControlSpecialDays_Impl::startDate() const {
43
1/1
✓ Branch 1 taken 20 times.
20 Date result;
44
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 YearDescription yd = this->model().getUniqueModelObject<YearDescription>();
45
1/1
✓ Branch 1 taken 20 times.
20 boost::optional<std::string> text = getString(OS_RunPeriodControl_SpecialDaysFields::StartDate);
46
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 4 not taken.
20 OS_ASSERT(text);
47
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
40 return getDate(*text);
48 20 }
49
50 ✗ unsigned RunPeriodControlSpecialDays_Impl::duration() const {
51 ✗ boost::optional<int> result = getInt(OS_RunPeriodControl_SpecialDaysFields::Duration, true);
52 ✗ OS_ASSERT(result);
53 ✗ return *result;
54 }
55
56 ✗ std::string RunPeriodControlSpecialDays_Impl::specialDayType() const {
57 ✗ boost::optional<std::string> result = getString(OS_RunPeriodControl_SpecialDaysFields::SpecialDayType, true);
58 ✗ OS_ASSERT(result);
59 ✗ return *result;
60 ✗ }
61
62 80 bool RunPeriodControlSpecialDays_Impl::setStartDate(const std::string& startDate) {
63 80 bool result = false;
64 try {
65
1/1
✓ Branch 1 taken 80 times.
80 getDate(startDate);
66
1/1
✓ Branch 1 taken 80 times.
80 result = setString(OS_RunPeriodControl_SpecialDaysFields::StartDate, startDate);
67 ✗ } catch (...) {
68 ✗ }
69 80 return result;
70 }
71
72 6 bool RunPeriodControlSpecialDays_Impl::setStartDate(const openstudio::MonthOfYear& monthOfYear, unsigned day) {
73
1/1
✓ Branch 1 taken 6 times.
6 std::stringstream ss;
74
4/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
6 ss << monthOfYear.value() << "/" << day;
75
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
12 return setString(OS_RunPeriodControl_SpecialDaysFields::StartDate, ss.str());
76 6 }
77
78 12 bool RunPeriodControlSpecialDays_Impl::setStartDate(const openstudio::NthDayOfWeekInMonth& nth, const openstudio::DayOfWeek& dayOfWeek,
79 const openstudio::MonthOfYear& monthOfYear) {
80
1/1
✓ Branch 1 taken 12 times.
12 std::stringstream ss;
81 // Note: MonthOfYear::Jul => valueName() is "Jul", valueDescription is "July"
82
6/7
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
12 switch (nth.value()) {
83 3 case NthDayOfWeekInMonth::first:
84
6/6
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 16 taken 3 times.
3 ss << "1st " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
85 3 break;
86 1 case NthDayOfWeekInMonth::second:
87
6/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
1 ss << "2nd " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
88 1 break;
89 2 case NthDayOfWeekInMonth::third:
90
6/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
2 ss << "3rd " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
91 2 break;
92 2 case NthDayOfWeekInMonth::fourth:
93
6/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
2 ss << "4th " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
94 2 break;
95 4 case NthDayOfWeekInMonth::fifth:
96
6/6
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
4 ss << "5th " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
97 4 break;
98 ✗ default:
99 ✗ OS_ASSERT(false);
100 }
101
102
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
24 return setString(OS_RunPeriodControl_SpecialDaysFields::StartDate, ss.str());
103 12 }
104
105 82 bool RunPeriodControlSpecialDays_Impl::setDuration(unsigned duration) {
106 82 return setUnsigned(OS_RunPeriodControl_SpecialDaysFields::Duration, duration);
107 }
108
109 2 bool RunPeriodControlSpecialDays_Impl::setSpecialDayType(const std::string& specialDayType) {
110 2 return setString(OS_RunPeriodControl_SpecialDaysFields::SpecialDayType, specialDayType);
111 }
112
113 ✗ void RunPeriodControlSpecialDays_Impl::ensureNoLeapDays() {
114 ✗ LOG(Warn, "Ensure no leap days is not yet implemented for run control special days");
115 ✗ }
116
117 // return the parent object in the hierarchy
118 ✗ boost::optional<ParentObject> RunPeriodControlSpecialDays_Impl::parent() const {
119 ✗ boost::optional<ParentObject> result(model().getOptionalUniqueModelObject<YearDescription>());
120 ✗ return result;
121 }
122
123 // set the parent, child may have to call methods on the parent
124 ✗ bool RunPeriodControlSpecialDays_Impl::setParent(ParentObject& newParent) {
125 ✗ if (newParent.optionalCast<YearDescription>() && (newParent.model() == model())) {
126 ✗ return true;
127 }
128 ✗ return false;
129 }
130
131 // Get all output variable names that could be associated with this object.
132 ✗ const std::vector<std::string>& RunPeriodControlSpecialDays_Impl::outputVariableNames() const {
133 ✗ static const std::vector<std::string> result;
134 ✗ return result;
135 }
136
137 ✗ IddObjectType RunPeriodControlSpecialDays_Impl::iddObjectType() const {
138 ✗ return RunPeriodControlSpecialDays::iddObjectType();
139 }
140
141 100 openstudio::Date RunPeriodControlSpecialDays_Impl::getDate(const std::string& text) const {
142
1/1
✓ Branch 1 taken 100 times.
100 Date result;
143
2/2
✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
100 YearDescription yd = this->model().getUniqueModelObject<YearDescription>();
144
145 /*
146 \note <number>/<number> (month/day)
147 \note <number> <Month>
148 \note <Month> <number>
149 \note <Nth> <Weekday> in <Month)
150 \note Last <WeekDay> in <Month>
151 \note <Month> can be January, February, March, April, May, June, July, August, September, October, November, December
152 \note Months can be the first 3 letters of the month
153 \note <Weekday> can be Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
154 \note <Nth> can be 1 or 1st, 2 or 2nd, etc. up to 5(?)
155 */
156
1/1
✓ Branch 1 taken 100 times.
100 boost::smatch matches;
157
4/4
✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 96 times.
100 if (boost::regex_search(text, matches, boost::regex("(\\d+)\\s?\\/\\s?(\\d+)"))) {
158
159
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
4 std::string monthString(matches[1].first, matches[1].second);
160
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 MonthOfYear monthOfYear(boost::lexical_cast<unsigned>(monthString));
161
162
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
4 std::string dayOfMonthString(matches[2].first, matches[2].second);
163
1/1
✓ Branch 1 taken 4 times.
4 auto dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString);
164
165
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 result = yd.makeDate(monthOfYear, dayOfMonth);
166
1/1
✓ Branch 1 taken 4 times.
4 return result;
167
1/1
✓ Branch 3 taken 96 times.
100 } else if (boost::regex_search(text, matches,
168
2/3
✓ Branch 1 taken 96 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 96 times.
192 boost::regex("(\\d+)\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|"
169 "July|August|September|October|November|December)",
170 boost::regex::icase))) {
171
172 ✗ std::string dayOfMonthString(matches[1].first, matches[1].second);
173 ✗ auto dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString);
174 ✗ std::string monthString(matches[2].first, matches[2].second);
175
176 ✗ result = yd.makeDate(monthOfYear(monthString), dayOfMonth);
177 ✗ return result;
178
1/1
✓ Branch 3 taken 96 times.
96 } else if (boost::regex_search(text, matches,
179
3/3
✓ Branch 1 taken 96 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 64 times.
192 boost::regex("(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|July|"
180 "August|September|October|November|December)\\s+(\\d+)",
181 boost::regex::icase))) {
182
183
3/3
✓ Branch 1 taken 32 times.
✓ Branch 4 taken 32 times.
✓ Branch 7 taken 32 times.
64 std::string monthString(matches[1].first, matches[1].second);
184
3/3
✓ Branch 1 taken 32 times.
✓ Branch 4 taken 32 times.
✓ Branch 7 taken 32 times.
32 std::string dayOfMonthString(matches[2].first, matches[2].second);
185
1/1
✓ Branch 1 taken 32 times.
32 auto dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString);
186
187
3/3
✓ Branch 1 taken 32 times.
✓ Branch 4 taken 32 times.
✓ Branch 7 taken 32 times.
32 result = yd.makeDate(monthOfYear(monthString), dayOfMonth);
188
1/1
✓ Branch 1 taken 32 times.
32 return result;
189
1/1
✓ Branch 3 taken 64 times.
96 } else if (boost::regex_search(text, matches,
190
2/3
✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
128 boost::regex("(1|2|3|4|5|1st|2nd|3rd|4th|5th|Last)\\s+(Sun|Mon|Tue|Wed|Thu|Fri|Sat|Sunday|Monday|Tuesday|"
191 "Wednesday|Thursday|Friday|Saturday)\\s+in\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|"
192 "January|February|March|April|May|June|July|August|September|October|November|December)",
193 boost::regex::icase))) {
194
195
3/3
✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 64 times.
128 std::string nthString(matches[1].first, matches[1].second);
196
3/3
✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 64 times.
128 std::string dayOfWeekString(matches[2].first, matches[2].second);
197
3/3
✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 64 times.
64 std::string monthString(matches[3].first, matches[3].second);
198
199
5/5
✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 64 times.
✓ Branch 10 taken 64 times.
✓ Branch 13 taken 64 times.
64 result = yd.makeDate(nthDayOfWeekInMonth(nthString), dayOfWeek(dayOfWeekString), monthOfYear(monthString));
200
1/1
✓ Branch 1 taken 64 times.
64 return result;
201 64 }
202
203 ✗ LOG_AND_THROW("Could not determine date for startDate = '" << text << "'");
204 return {};
205 100 }
206
207 } // namespace detail
208
209 80 RunPeriodControlSpecialDays::RunPeriodControlSpecialDays(const std::string& startDate, Model& model)
210 80 : ModelObject(RunPeriodControlSpecialDays::iddObjectType(), model) {
211
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 80 times.
✗ Branch 5 not taken.
80 OS_ASSERT(getImpl<detail::RunPeriodControlSpecialDays_Impl>());
212
1/1
✓ Branch 3 taken 80 times.
80 bool test = getImpl<detail::RunPeriodControlSpecialDays_Impl>()->setStartDate(startDate);
213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80 times.
80 if (!test) {
214 ✗ LOG_AND_THROW("'" << startDate << "' is not correctly formatted");
215 }
216 80 }
217
218 6 RunPeriodControlSpecialDays::RunPeriodControlSpecialDays(const openstudio::MonthOfYear& monthOfYear, unsigned day, Model& model)
219 6 : ModelObject(RunPeriodControlSpecialDays::iddObjectType(), model) {
220
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 5 not taken.
6 OS_ASSERT(getImpl<detail::RunPeriodControlSpecialDays_Impl>());
221
1/1
✓ Branch 3 taken 6 times.
6 getImpl<detail::RunPeriodControlSpecialDays_Impl>()->setStartDate(monthOfYear, day);
222 6 }
223
224 10 RunPeriodControlSpecialDays::RunPeriodControlSpecialDays(const openstudio::NthDayOfWeekInMonth& nth, const openstudio::DayOfWeek& dayOfWeek,
225 10 const openstudio::MonthOfYear& monthOfYear, Model& model)
226 10 : ModelObject(RunPeriodControlSpecialDays::iddObjectType(), model) {
227
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 5 not taken.
10 OS_ASSERT(getImpl<detail::RunPeriodControlSpecialDays_Impl>());
228
1/1
✓ Branch 3 taken 10 times.
10 getImpl<detail::RunPeriodControlSpecialDays_Impl>()->setStartDate(nth, dayOfWeek, monthOfYear);
229 10 }
230
231 ✗ std::vector<std::string> RunPeriodControlSpecialDays::specialDayTypeValues() {
232 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_RunPeriodControl_SpecialDaysFields::SpecialDayType);
233 }
234
235 ✗ std::vector<std::string> RunPeriodControlSpecialDays::validSpecialDayTypeValues() {
236 ✗ return specialDayTypeValues();
237 }
238
239 20 Date RunPeriodControlSpecialDays::startDate() const {
240
1/1
✓ Branch 3 taken 20 times.
20 return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->startDate();
241 }
242
243 ✗ unsigned RunPeriodControlSpecialDays::duration() const {
244 ✗ return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->duration();
245 }
246
247 ✗ std::string RunPeriodControlSpecialDays::specialDayType() const {
248 ✗ return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->specialDayType();
249 }
250
251 ✗ bool RunPeriodControlSpecialDays::setStartDate(const std::string& startDate) {
252 ✗ return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->setStartDate(startDate);
253 }
254
255 ✗ bool RunPeriodControlSpecialDays::setStartDate(const openstudio::MonthOfYear& monthOfYear, unsigned day) {
256 ✗ return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->setStartDate(monthOfYear, day);
257 }
258
259 2 bool RunPeriodControlSpecialDays::setStartDate(const openstudio::NthDayOfWeekInMonth& nth, const openstudio::DayOfWeek& dayOfWeek,
260 const openstudio::MonthOfYear& monthOfYear) {
261
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->setStartDate(nth, dayOfWeek, monthOfYear);
262 }
263
264 82 bool RunPeriodControlSpecialDays::setDuration(unsigned duration) {
265
1/1
✓ Branch 3 taken 82 times.
82 return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->setDuration(duration);
266 }
267
268 2 bool RunPeriodControlSpecialDays::setSpecialDayType(const std::string& specialDayType) {
269
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->setSpecialDayType(specialDayType);
270 }
271
272 ✗ void RunPeriodControlSpecialDays::ensureNoLeapDays() {
273 ✗ getImpl<detail::RunPeriodControlSpecialDays_Impl>()->ensureNoLeapDays();
274 ✗ }
275
276 13 RunPeriodControlSpecialDays::RunPeriodControlSpecialDays(std::shared_ptr<detail::RunPeriodControlSpecialDays_Impl> impl)
277
1/1
✓ Branch 3 taken 13 times.
13 : ModelObject(std::move(impl)) {}
278
279 7892 IddObjectType RunPeriodControlSpecialDays::iddObjectType() {
280
1/1
✓ Branch 1 taken 7892 times.
7892 IddObjectType result(IddObjectType::OS_RunPeriodControl_SpecialDays);
281 7892 return result;
282 }
283
284 } // namespace model
285 } // namespace openstudio
286