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

Method removeForwardedReferences

src/utilities/idf/Workspace.cpp:1441–1486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1439 }
1440
1441 void Workspace_Impl::removeForwardedReferences(const Handle& sourceHandle, unsigned index, const WorkspaceObject& targetObject) {
1442 // get source object
1443 OptionalWorkspaceObject owo = getObject(sourceHandle);
1444 OS_ASSERT(owo);
1445 WorkspaceObject srcObj = *owo;
1446
1447 // only do something if references were forwarded
1448 OptionalIddField iddField = srcObj.iddObject().getField(index);
1449 if (!iddField->properties().references.empty()) {
1450 // get other source objects
1451 WorkspaceObjectVector sourceObjects = targetObject.sources();
1452 std::vector<UnsignedVector> sourceIndices;
1453 // get source index for each source object
1454 for (const WorkspaceObject& sourceObject : sourceObjects) {
1455 OS_ASSERT(sourceObject.handle() != sourceHandle); // pointer already nullified
1456 UnsignedVector temp = sourceObject.getSourceIndices(targetObject.handle());
1457 OS_ASSERT(!temp.empty());
1458 sourceIndices.push_back(temp);
1459 }
1460 // loop through reference names
1461 for (const std::string& referenceName : iddField->properties().references) {
1462 // see if name is forwarded by any other source objects
1463 bool found = false;
1464 auto indIt = sourceIndices.begin();
1465 for (auto objIt = sourceObjects.begin(), objItEnd = sourceObjects.end(); objIt != objItEnd; ++objIt, ++indIt) {
1466 for (unsigned index : *indIt) {
1467 OptionalIddField sourceIddField = (*objIt).iddObject().getField(index);
1468 OS_ASSERT(sourceIddField);
1469 StringVector sourceFieldRefs = sourceIddField->properties().references;
1470 if (std::find_if(sourceFieldRefs.cbegin(), sourceFieldRefs.cend(),
1471 [&referenceName](const auto& s) { return istringEqual(s, referenceName); })
1472 != sourceFieldRefs.end()) {
1473 found = true;
1474 break;
1475 }
1476 }
1477 }
1478 // if not, erase the reference
1479 if (!found) {
1480 auto it = m_idfReferencesMap[referenceName].find(targetObject.handle());
1481 OS_ASSERT(it != m_idfReferencesMap[referenceName].end());
1482 m_idfReferencesMap[referenceName].erase(it);
1483 }
1484 }
1485 }
1486 }
1487
1488 void Workspace_Impl::setFastNaming(bool fastNaming) {
1489 m_fastNaming = fastNaming;

Callers 1

nullifyPointerMethod · 0.80

Calls 15

istringEqualFunction · 0.85
iddObjectMethod · 0.80
sourcesMethod · 0.80
getSourceIndicesMethod · 0.80
beginMethod · 0.80
cbeginMethod · 0.80
cendMethod · 0.80
getObjectFunction · 0.70
getFieldMethod · 0.45
emptyMethod · 0.45
handleMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected