| 83 | } |
| 84 | |
| 85 | bool EnergyManagementSystemProgram_Impl::setBody(const std::string& body) { |
| 86 | //set body of program to input string |
| 87 | bool result = false; |
| 88 | // TODO: JM 2019-01-03: This is unused |
| 89 | [[maybe_unused]] bool comment_result = false; |
| 90 | //if body string empty then return false |
| 91 | if (body.empty()) { |
| 92 | return false; |
| 93 | }; |
| 94 | |
| 95 | //clobber existing body |
| 96 | this->resetBody(); |
| 97 | |
| 98 | // remove '\r' from the body string |
| 99 | std::string body_minus_r = body; |
| 100 | std::string::size_type pos = 0; // Must initialize |
| 101 | while ((pos = body_minus_r.find("\r", pos)) != std::string::npos) { |
| 102 | body_minus_r.erase(pos, 1); |
| 103 | } |
| 104 | |
| 105 | //split the body string on newline characters and comments and insert program line for each string line |
| 106 | std::vector<std::string> body_minus_nl = splitString(body_minus_r, '\n'); |
| 107 | std::string body_minus_comment; |
| 108 | std::vector<std::string> comments; |
| 109 | std::string comment; |
| 110 | |
| 111 | //add program lines to body |
| 112 | for (size_t i = 0; i < body_minus_nl.size(); i++) { |
| 113 | //split string on comment character ! |
| 114 | comments = splitString(body_minus_nl.at(i), '!'); |
| 115 | |
| 116 | //make sure program line exists and insert |
| 117 | if (!comments.empty()) { |
| 118 | //remove leading and trailing whitespaces in program line (comments[0]) |
| 119 | boost::trim(comments[0]); |
| 120 | //remove , |
| 121 | pos = 0; |
| 122 | while ((pos = comments[0].find(",", pos)) != std::string::npos) { |
| 123 | comments[0].erase(pos, 1); |
| 124 | } |
| 125 | // insert program line only if not empty |
| 126 | if (!comments[0].empty()) { |
| 127 | |
| 128 | // Push an extensibleGroup object (we only want to that if there is something to put in) |
| 129 | auto group = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>(); |
| 130 | |
| 131 | result = group.setString(OS_EnergyManagementSystem_ProgramExtensibleFields::ProgramLine, comments[0]); |
| 132 | if (!result) { |
| 133 | return result; |
| 134 | } |
| 135 | //check if comments exist |
| 136 | if (comments.size() > 1) { |
| 137 | //clear out the old comment |
| 138 | comment.clear(); |
| 139 | //add comment to comment vector |
| 140 | comment.append(comments.at(1)); |
| 141 | //combine any remaining comments for this line into one comment |
| 142 | if (comments.size() > 2) { |