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