void ComponentWatcher_Impl::relationshipChange(int index,Handle newHandle,Handle oldHandle) { OS_ASSERT(newHandle != oldHandle); // if oldHandle is in the Component nullify the component HandleVector hs = getHandles<ModelObject>(m_componentObjects); if (std::find(hs.begin(),hs.end(),oldHandle) != hs.end()) { mf_removeComponent(); return; } // otherwise, change version mf_changeComponentVersion(); return; }
// Test in context of Workspace, since order needs objectGetter. TEST_F(IdfFixture,WorkspaceObjectOrder) { Workspace workspace(IdfFixture::epIdfFile,openstudio::StrictnessLevel::Draft); WorkspaceObjectOrder wsOrder = workspace.order(); EXPECT_TRUE(wsOrder.inOrder(workspace.objects()[0].handle())); // save current order OptionalHandleVector workspaceOrder = wsOrder.directOrder(); ASSERT_TRUE(workspaceOrder); // order by enum wsOrder.setOrderByIddEnum(); WorkspaceObjectVector objects = workspace.objects(true); for (WorkspaceObjectVector::const_iterator it = objects.begin(), itEnd = objects.end() - 1; it != itEnd; ++ it) { WorkspaceObjectVector::const_iterator nxt = it; ++nxt; EXPECT_TRUE(it->iddObject().type() <= nxt->iddObject().type()); } // restore order wsOrder.setDirectOrder(*workspaceOrder); HandleVector handles = workspace.handles(true); // handles does not include version object, while direct order does HandleVector tempOrder = *workspaceOrder; HandleVector::iterator it = std::find(tempOrder.begin(),tempOrder.end(),workspace.versionObject()->handle()); tempOrder.erase(it); EXPECT_TRUE(tempOrder == handles); // move objects directly wsOrder.insert(handles[32],handles[12]); HandleVector newOrder = workspace.handles(true); EXPECT_EQ(handles.size(),newOrder.size()); EXPECT_TRUE(handles[32] == newOrder[12]); EXPECT_TRUE(handles[12] == newOrder[13]); wsOrder.swap(handles[80],handles[100]); newOrder = workspace.handles(true); EXPECT_EQ(handles.size(),newOrder.size()); EXPECT_TRUE(handles[80] == newOrder[100]); EXPECT_TRUE(handles[100] == newOrder[80]); }