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

Method setPointerImpl

src/utilities/idf/WorkspaceObject.cpp:1080–1115  ·  view source on GitHub ↗

Pre-condition: targetHandle is null or in m_workspace. index is an object-list field. Post-condition: Field index points to object targetHandle.

Source from the content-addressed store, hash-verified

1078 // Pre-condition: targetHandle is null or in m_workspace. index is an object-list field.
1079 // Post-condition: Field index points to object targetHandle.
1080 Handle WorkspaceObject_Impl::setPointerImpl(unsigned index, const Handle& targetHandle) {
1081 OS_ASSERT(!m_handle.isNull());
1082 Handle result;
1083 // check current status
1084 auto fpIt = getIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index);
1085 if (fpIt == m_sourceData->pointers.end()) {
1086 /*bool result =*/IdfObject_Impl::setString(index, std::string(), false);
1087 } else { // entry exists
1088 if (!fpIt->targetHandle.isNull()) {
1089 result = fpIt->targetHandle;
1090 if (fpIt->targetHandle == targetHandle) {
1091 return result;
1092 } // nothing to do
1093 nullifyPointer(index); // takes care of reverse pointer
1094 }
1095 }
1096 // add pointer
1097 fpIt = getIteratorAtFieldIndex<SourceData>(m_sourceData->pointers, index);
1098 if (fpIt != m_sourceData->pointers.end()) {
1099 m_sourceData->pointers.erase(fpIt);
1100 }
1101 std::pair<SourceData::pointer_set::iterator, bool> insertResult;
1102 insertResult = m_sourceData->pointers.insert(ForwardPointer(index, targetHandle));
1103 OS_ASSERT(insertResult.second);
1104
1105 // add reverse pointer
1106 if (!targetHandle.isNull()) {
1107 OptionalWorkspaceObject target = m_workspace->getObject(targetHandle);
1108 OS_ASSERT(target);
1109 target->getImpl<WorkspaceObject_Impl>()->setReversePointer(m_handle, index);
1110 // forward references if is object-list and defines references simultaneously
1111 m_workspace->forwardReferences(m_handle, index, targetHandle);
1112 }
1113
1114 return result;
1115 }
1116
1117 boost::optional<Handle> WorkspaceObject_Impl::convertToTargetHandle(const std::string& name, const std::set<std::string>& referenceLists,
1118 bool checkValidity) const {

Callers

nothing calls this directly

Calls 8

ForwardPointerFunction · 0.85
isNullMethod · 0.80
setReversePointerMethod · 0.80
forwardReferencesMethod · 0.80
endMethod · 0.45
eraseMethod · 0.45
insertMethod · 0.45
getObjectMethod · 0.45

Tested by

no test coverage detected