GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 94.6% 35 / 0 / 37
Functions: 100.0% 1 / 0 / 1
Branches: 75.9% 41 / 0 / 54

src/energyplus/ForwardTranslator/ForwardTranslateEnergyManagementSystemInternalVariable.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/EnergyManagementSystemInternalVariable.hpp"
16 #include "../../model/EnergyManagementSystemInternalVariable_Impl.hpp"
17
18 #include <utilities/idd/EnergyManagementSystem_InternalVariable_FieldEnums.hxx>
19 #include "../../utilities/idd/IddEnums.hpp"
20 #include <utilities/idd/IddEnums.hxx>
21
22 using namespace openstudio::model;
23
24 using namespace std;
25
26 namespace openstudio {
27
28 namespace energyplus {
29
30 3 boost::optional<IdfObject> ForwardTranslator::translateEnergyManagementSystemInternalVariable(EnergyManagementSystemInternalVariable& modelObject) {
31 3 boost::optional<int> i;
32 3 boost::optional<std::string> s;
33
34
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 IdfObject idfObject(openstudio::IddObjectType::EnergyManagementSystem_InternalVariable);
35
1/1
✓ Branch 1 taken 3 times.
3 m_idfObjects.push_back(idfObject);
36 //Name
37
1/1
✓ Branch 1 taken 3 times.
3 s = modelObject.name();
38
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (s) {
39
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 idfObject.setName(*s);
40 }
41 // look for UID and if found replace with object name; otherwise just use string value
42
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 s = modelObject.internalDataIndexKeyName();
43
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (s) {
44 //find uids
45 3 const int subs[] = {1};
46
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 std::string newline = s.get();
47 3 std::string possible_uid;
48 size_t pos;
49 3 bool is_uuid = false;
50
1/1
✓ Branch 1 taken 3 times.
3 const Model m = modelObject.model();
51 3 boost::optional<ModelObject> mObject;
52
53
4/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 9 taken 3 times.
✓ Branch 14 taken 3 times.
3 boost::sregex_token_iterator j(s.get().begin(), s.get().end(), uuidInString(), subs);
54
55
3/3
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 3 times.
4 while (j != boost::sregex_token_iterator()) {
56
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 possible_uid = *j++;
57 //look to see if uid is in the model and return the object
58
1/1
✓ Branch 1 taken 1 time.
1 UUID uid = toUUID(possible_uid);
59
1/1
✓ Branch 1 taken 1 time.
1 mObject = m.getModelObject<model::ModelObject>(uid);
60
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (mObject) {
61 1 is_uuid = true;
62 //replace uid with namestring
63 1 pos = newline.find(possible_uid);
64
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 if (pos + 38 <= newline.length()) {
65
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 newline.replace(pos, 38, mObject.get().nameString());
66
1/1
✓ Branch 1 taken 1 time.
1 idfObject.setString(EnergyManagementSystem_InternalVariableFields::InternalDataIndexKeyName, newline);
67 }
68 } else {
69 //did not find an object with the UID so do not FT
70 ✗ LOG(Error, "InternalIndexDataKeyName for EMS:InternalVariable '" << modelObject.nameString()
71 << "' is UID but does not exist, it will not be translated.");
72 ✗ return boost::none;
73 }
74 }
75 //string is not a uuid so just translate its value for the EMSVariableName
76
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
3 if (!is_uuid) {
77
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 idfObject.setString(EnergyManagementSystem_InternalVariableFields::InternalDataIndexKeyName, s.get());
78 }
79 3 }
80
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 s = modelObject.internalDataType();
81
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (s) {
82
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 idfObject.setString(EnergyManagementSystem_InternalVariableFields::InternalDataType, s.get());
83 }
84
85
1/1
✓ Branch 1 taken 3 times.
3 return idfObject;
86 3 }
87
88 } // namespace energyplus
89
90 } // namespace openstudio
91