MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / addLine

Method addLine

src/model/EnergyManagementSystemProgram.cpp:169–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167 }
168
169 bool EnergyManagementSystemProgram_Impl::addLine(const std::string& line) {
170 //add line to end of program body
171 bool result = true;
172 // TODO: JM 2019-01-03: This is unused
173 [[maybe_unused]] bool comment_result = false;
174 std::string comment;
175
176 // remove '\r' from the line string
177 std::string line_rn = line;
178 std::string::size_type pos = 0; // Must initialize
179 while ((pos = line_rn.find("\r", pos)) != std::string::npos) {
180 line_rn.erase(pos, 1);
181 }
182 // remove '\n'
183 pos = 0;
184 while ((pos = line_rn.find("\n", pos)) != std::string::npos) {
185 line_rn.erase(pos, 1);
186 }
187 //get extensibleGroup object
188 auto group = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>();
189
190 //split string on comment character !
191 std::vector<std::string> comments = splitString(line_rn, '!');
192 //make sure program line exists and insert
193 if (!comments.empty()) {
194 //remove whitespace at end of comments[0]
195 boost::trim_right(comments[0]);
196 //remove whitespace at beginning of comments[0]
197 boost::trim_left(comments[0]);
198 //remove ,
199 pos = 0;
200 while ((pos = comments[0].find(",", pos)) != std::string::npos) {
201 comments[0].erase(pos, 1);
202 }
203 //insert program line
204 result = group.setString(OS_EnergyManagementSystem_ProgramExtensibleFields::ProgramLine, comments[0]);
205 //check if comments exist
206 if (comments.size() > 1) {
207 //clear out the old comment
208 comment.clear();
209 //add comment to comment vector
210 comment.append(comments.at(1));
211 //combine any remaining comments for this line into one comment
212 if (comments.size() > 2) {
213 for (size_t j = 2; j < comments.size(); j++) {
214 comment.append(", " + comments.at(j));
215 }
216 }
217 comment_result = group.setFieldComment(OS_EnergyManagementSystem_ProgramExtensibleFields::ProgramLine, comment);
218 }
219 } else {
220 result = false;
221 }
222 return result;
223 }
224
225 std::vector<std::string> EnergyManagementSystemProgram_Impl::lines() const {
226 //return vector of lines from body

Callers 8

createInitProgramMethod · 0.45
createSimProgramMethod · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45

Calls 9

splitStringFunction · 0.85
pushExtensibleGroupMethod · 0.80
findMethod · 0.45
eraseMethod · 0.45
emptyMethod · 0.45
setStringMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
setFieldCommentMethod · 0.45

Tested by 4

TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36