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

Method suggestedStandardsTemplates

src/model/SpaceType.cpp:242–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240 }
241
242 std::vector<std::string> SpaceType_Impl::suggestedStandardsTemplates() const {
243 // TODO: JM 2018-11-07 replace with a std::unordered_set?
244 std::vector<std::string> result;
245
246 boost::optional<std::string> standardsTemplate = this->standardsTemplate();
247
248 // Find the possible template names
249 // standardsJSON is an array of hashes (no nested levels)
250 for (const auto& v : getStandardsJSON()) {
251 const Json::Value _template = v["template"];
252 if (_template.isString()) {
253 result.emplace_back(_template.asString());
254 }
255 }
256
257 // include values from model
258
259 boost::optional<Building> building = this->model().getOptionalUniqueModelObject<Building>();
260 boost::optional<std::string> buildingStandardsTemplate;
261 if (building) {
262 buildingStandardsTemplate = building->standardsTemplate();
263 }
264
265 for (const SpaceType& other : this->model().getConcreteModelObjects<SpaceType>()) {
266 if (other.handle() == this->handle()) {
267 continue;
268 }
269 boost::optional<std::string> otherTemplate = other.standardsTemplate();
270 if (otherTemplate) {
271 result.emplace_back(*otherTemplate);
272 }
273 }
274
275 // remove buildingStandardsTemplate and standardsTemplate
276 IstringFind finder;
277 if (buildingStandardsTemplate) {
278 finder.addTarget(*buildingStandardsTemplate);
279 }
280 if (standardsTemplate) {
281 finder.addTarget(*standardsTemplate);
282 }
283 auto it = std::remove_if(result.begin(), result.end(), finder);
284 result.resize(std::distance(result.begin(), it));
285
286 // sort
287 std::sort(result.begin(), result.end(), IstringCompare());
288
289 // make unique
290 // DLM: have to sort before calling unique, unique only works on consecutive elements
291 it = std::unique(result.begin(), result.end(), IstringEqual());
292 result.resize(std::distance(result.begin(), it));
293
294 // add building value to front
295 if (buildingStandardsTemplate) {
296 result.insert(result.begin(), *buildingStandardsTemplate);
297 }
298
299 // add current to front

Callers

nothing calls this directly

Calls 8

standardsTemplateMethod · 0.95
addTargetMethod · 0.80
beginMethod · 0.80
resizeMethod · 0.80
modelMethod · 0.45
handleMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected