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

Method update

src/osversion/VersionTranslator.cpp:481–528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479 }
480
481 void VersionTranslator::update(const VersionString& startVersion) {
482 auto start = m_map.find(startVersion);
483 if (start != m_map.end()) {
484
485 bool is_component_update_needed = false; // To avoid constantly comparing VersionString
486
487 std::string translatedIdf;
488 VersionString lastVersion("0.0.0");
489 boost::optional<IddFileAndFactoryWrapper> oIddFile;
490 for (auto it = m_updateMethods.begin(), itEnd = m_updateMethods.end(); it != itEnd; ++it) {
491 // make sure map iteration is behaving as expected
492 OS_ASSERT(lastVersion < it->first);
493 lastVersion = it->first;
494 if (startVersion < it->first) {
495 oIddFile = getIddFile(it->first);
496 translatedIdf = it->second(this, start->second, *oIddFile);
497 break;
498 }
499 }
500
501 if (translatedIdf.empty()) {
502 LOG(Error, "Unable to complete translation from " << startVersion.str() << " to " << lastVersion.str()
503 << ". Unable to find and execute the appropriate update method.");
504 return;
505 }
506 std::stringstream ss(translatedIdf);
507 OptionalIdfFile oIdfFile;
508 if (oIddFile->iddFileType() == IddFileType::UserCustom) {
509 oIdfFile = IdfFile::load(ss, oIddFile->iddFile());
510 } else {
511 oIdfFile = IdfFile::load(ss, oIddFile->iddFileType());
512 }
513 if (!oIdfFile) {
514 LOG(Error, "Unable to complete translation from " << startVersion.str() << " to " << lastVersion.str()
515 << ". Could not load translated IDF using the "
516 << "latter version's IddFile. Translated text: " << '\n'
517 << translatedIdf);
518 return;
519 }
520 IdfFile idfFile = *oIdfFile;
521 if (m_isComponent && (is_component_update_needed || (lastVersion > VersionString(0, 7, 4)))) {
522 is_component_update_needed = true;
523 updateComponentData(idfFile);
524 }
525 m_map[oIdfFile->version()] = idfFile;
526 LOG(Debug, "Translation to " << lastVersion.str() << " model has " << oIdfFile->numObjects() << " objects.");
527 }
528 }
529
530 void VersionTranslator::updateComponentData(IdfFile& idfFile) {
531 if (OptionalIddObject oIddObject = idfFile.iddFile().getObject("OS:ComponentData")) {

Callers

nothing calls this directly

Calls 10

beginMethod · 0.80
VersionStringClass · 0.50
findMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
strMethod · 0.45
iddFileTypeMethod · 0.45
iddFileMethod · 0.45
versionMethod · 0.45
numObjectsMethod · 0.45

Tested by

no test coverage detected