GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 34 / 0 / 34
Functions: 100.0% 1 / 0 / 1
Branches: 88.6% 39 / 0 / 44

src/energyplus/ForwardTranslator/ForwardTranslateEnergyManagementSystemSubroutine.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 "../ForwardTranslator.hpp"
7
8 #include "../../model/Model.hpp"
9 #include "../../model/OutputVariable.hpp"
10 #include "../../model/OutputVariable_Impl.hpp"
11 #include "../../model/OutputMeter.hpp"
12 #include "../../model/OutputMeter_Impl.hpp"
13 #include "../../model/Schedule.hpp"
14 #include "../../model/Schedule_Impl.hpp"
15 #include "../../model/EnergyManagementSystemSubroutine.hpp"
16 #include "../../model/EnergyManagementSystemSubroutine_Impl.hpp"
17
18 #include "../../utilities/idf/IdfExtensibleGroup.hpp"
19 #include "../../utilities/core/UUID.hpp"
20 #include "../../utilities/core/StringHelpers.hpp"
21
22 #include <utilities/idd/OS_EnergyManagementSystem_Subroutine_FieldEnums.hxx>
23 #include <utilities/idd/EnergyManagementSystem_Subroutine_FieldEnums.hxx>
24 #include "../../utilities/idd/IddEnums.hpp"
25 #include <utilities/idd/IddEnums.hxx>
26 #include <utilities/idd/IddFactory.hxx>
27
28 using namespace openstudio::model;
29
30 using namespace std;
31
32 namespace openstudio {
33
34 namespace energyplus {
35
36 5 boost::optional<IdfObject> ForwardTranslator::translateEnergyManagementSystemSubroutine(EnergyManagementSystemSubroutine& modelObject) {
37 5 boost::optional<std::string> s;
38 5 const int subs[] = {1};
39 5 std::string possible_uid;
40 size_t pos;
41 5 std::string newline;
42
43
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 IdfObject idfObject(openstudio::IddObjectType::EnergyManagementSystem_Subroutine);
44
1/1
✓ Branch 1 taken 5 times.
5 m_idfObjects.push_back(idfObject);
45 //m_map.insert(std::make_pair(modelObject.handle(), idfObject));
46 //Name
47
1/1
✓ Branch 1 taken 5 times.
5 s = modelObject.name();
48
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (s) {
49
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 idfObject.setName(*s);
50 }
51
52
1/1
✓ Branch 1 taken 5 times.
5 const Model m = modelObject.model();
53 5 boost::optional<ModelObject> mObject;
54
55
3/3
✓ Branch 1 taken 5 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 5 times.
13 for (const IdfExtensibleGroup& eg : modelObject.extensibleGroups()) {
56
1/1
✓ Branch 1 taken 8 times.
8 IdfExtensibleGroup group = idfObject.pushExtensibleGroup();
57
1/1
✓ Branch 1 taken 8 times.
8 OptionalString line = eg.getString(OS_EnergyManagementSystem_SubroutineExtensibleFields::ProgramLine);
58
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (line) {
59 //find uids
60
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 newline = line.get();
61
4/4
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 9 taken 8 times.
✓ Branch 14 taken 8 times.
8 boost::sregex_token_iterator j(line.get().begin(), line.get().end(), uuidInString(), subs);
62
63
3/3
✓ Branch 2 taken 14 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 8 times.
14 while (j != boost::sregex_token_iterator()) {
64
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 possible_uid = *j++;
65 //look to see if uid is in the model and return the object
66
1/1
✓ Branch 1 taken 6 times.
6 UUID uid = toUUID(possible_uid);
67
1/1
✓ Branch 1 taken 6 times.
6 mObject = m.getModelObject<model::ModelObject>(uid);
68
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (mObject) {
69 //replace uid with namestring
70 6 pos = newline.find(possible_uid);
71
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 if (pos + 38 <= newline.length()) {
72
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 newline.replace(pos, 38, mObject.get().nameString());
73 }
74 }
75 }
76
1/1
✓ Branch 1 taken 8 times.
8 group.setString(OS_EnergyManagementSystem_SubroutineExtensibleFields::ProgramLine, newline);
77 8 }
78
1/1
✓ Branch 1 taken 8 times.
8 OptionalString comment = eg.fieldComment(OS_EnergyManagementSystem_SubroutineExtensibleFields::ProgramLine);
79
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (comment) {
80
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 group.setFieldComment(EnergyManagementSystem_SubroutineExtensibleFields::ProgramLine, comment.get());
81 }
82 13 }
83
1/1
✓ Branch 1 taken 5 times.
10 return idfObject;
84 5 }
85
86 } // namespace energyplus
87
88 } // namespace openstudio
89