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

Method suggestedStandardsBuildingTypes

src/model/SpaceType.cpp:334–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332 }
333
334 std::vector<std::string> SpaceType_Impl::suggestedStandardsBuildingTypes() const {
335 std::vector<std::string> result;
336
337 const boost::optional<std::string> standardsTemplate = this->standardsTemplate();
338 const boost::optional<std::string> standardsBuildingType = this->standardsBuildingType();
339
340 // include values from json if template is already set
341 if (standardsTemplate) {
342 // Find the possible building_type names that have the template name
343 // standardsJSON is an array of hashes (no nested levels)
344 for (const auto& v : getStandardsJSON()) {
345 const auto thisTemplate = v["template"].asString();
346 if (thisTemplate == standardsTemplate.get()) {
347 const Json::Value _buildingType = v["building_type"];
348 if (_buildingType.isString()) {
349 result.emplace_back(_buildingType.asString());
350 }
351 }
352 }
353 }
354
355 // include values from model
356
357 boost::optional<Building> building = this->model().getOptionalUniqueModelObject<Building>();
358 boost::optional<std::string> buildingStandardsBuildingType;
359 if (building) {
360 buildingStandardsBuildingType = building->standardsBuildingType();
361 }
362
363 for (const SpaceType& other : this->model().getConcreteModelObjects<SpaceType>()) {
364 if (other.handle() == this->handle()) {
365 continue;
366 }
367 boost::optional<std::string> otherBuildingType = other.standardsBuildingType();
368 if (otherBuildingType) {
369 result.emplace_back(*otherBuildingType);
370 }
371 }
372
373 // remove buildingStandardsBuildingType and standardsBuildingType
374 IstringFind finder;
375 if (buildingStandardsBuildingType) {
376 finder.addTarget(*buildingStandardsBuildingType);
377 }
378 if (standardsBuildingType) {
379 finder.addTarget(*standardsBuildingType);
380 }
381 auto it = std::remove_if(result.begin(), result.end(), finder);
382 result.resize(std::distance(result.begin(), it));
383
384 // sort
385 std::sort(result.begin(), result.end(), IstringCompare());
386
387 // make unique
388 // DLM: have to sort before calling unique, unique only works on consecutive elements
389 it = std::unique(result.begin(), result.end(), IstringEqual());
390 result.resize(std::distance(result.begin(), it));
391

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected