| 363 | } |
| 364 | |
| 365 | std::vector<std::string> Building_Impl::suggestedStandardsBuildingTypes() const { |
| 366 | // If standardsTemplate isn't set, return empty |
| 367 | boost::optional<std::string> standardsTemplate = this->standardsTemplate(); |
| 368 | if (!standardsTemplate) { |
| 369 | return {}; |
| 370 | } else { |
| 371 | |
| 372 | boost::optional<std::string> standardsBuildingType = this->standardsBuildingType(); |
| 373 | |
| 374 | // Make a dummy Model and a dummy space Type, |
| 375 | // and call suggestedStandardsTemplates from it, so we don't have to repeat code here |
| 376 | Model tempModel; |
| 377 | SpaceType tempSpaceType(tempModel); |
| 378 | // We set the standards template to the value |
| 379 | tempSpaceType.setStandardsTemplate(standardsTemplate.get()); |
| 380 | std::vector<std::string> result = tempSpaceType.suggestedStandardsBuildingTypes(); |
| 381 | |
| 382 | // include values from model |
| 383 | for (const SpaceType& other : this->model().getConcreteModelObjects<SpaceType>()) { |
| 384 | if (boost::optional<std::string> otherBuildingType = other.standardsBuildingType()) { |
| 385 | result.push_back(*otherBuildingType); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | // remove standardsBuildingType |
| 390 | IstringFind finder; |
| 391 | if (standardsBuildingType) { |
| 392 | finder.addTarget(*standardsBuildingType); |
| 393 | } |
| 394 | auto it = std::remove_if(result.begin(), result.end(), finder); |
| 395 | result.resize(std::distance(result.begin(), it)); |
| 396 | |
| 397 | // sort, unique only works on consecutive elements |
| 398 | std::sort(result.begin(), result.end(), IstringCompare()); |
| 399 | // make unique |
| 400 | it = std::unique(result.begin(), result.end(), IstringEqual()); |
| 401 | result.resize(std::distance(result.begin(), it)); |
| 402 | |
| 403 | // add current to front |
| 404 | if (standardsBuildingType) { |
| 405 | result.insert(result.begin(), *standardsBuildingType); |
| 406 | } |
| 407 | return result; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | bool Building_Impl::setStandardsBuildingType(const std::string& standardsBuildingType) { |
| 412 | bool result = setString(OS_BuildingFields::StandardsBuildingType, standardsBuildingType); |