Core/HandledObject: Fix move assignement operator behavior
It will now unregister all previous handles (notifying about object destruction) before stealing moving object handles
This commit is contained in:
parent
05a5c4c42e
commit
830dae1b27
|
|
@ -86,12 +86,11 @@ namespace Nz
|
||||||
template<typename T>
|
template<typename T>
|
||||||
HandledObject<T>& HandledObject<T>::operator=(HandledObject&& object)
|
HandledObject<T>& HandledObject<T>::operator=(HandledObject&& object)
|
||||||
{
|
{
|
||||||
m_handles.reserve(m_handles.size() + object.m_handles.size());
|
UnregisterAllHandles();
|
||||||
for (ObjectHandle<T>* handle : object.m_handles)
|
|
||||||
{
|
m_handles = std::move(object.m_handles);
|
||||||
m_handles.push_back(handle);
|
for (ObjectHandle<T>* handle : m_handles)
|
||||||
handle->OnObjectMoved(static_cast<T*>(this));
|
handle->OnObjectMoved(static_cast<T*>(this));
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,13 +90,16 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]")
|
||||||
Nz::ObjectHandle<Test> otherHandle = other.CreateHandle();
|
Nz::ObjectHandle<Test> otherHandle = other.CreateHandle();
|
||||||
test = std::move(other);
|
test = std::move(other);
|
||||||
|
|
||||||
|
THEN("Handles to previous objects should be invalid")
|
||||||
|
{
|
||||||
|
CHECK_FALSE(handle1.IsValid());
|
||||||
|
CHECK_FALSE(handle2.IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
THEN("Handles should point to 4")
|
THEN("Handles should point to 4")
|
||||||
{
|
{
|
||||||
CHECK(handle1->i == moveValue);
|
|
||||||
CHECK(handle2->i == moveValue);
|
|
||||||
CHECK(otherHandle->i == moveValue);
|
|
||||||
CHECK(handle1.GetObject() == &test);
|
|
||||||
CHECK(otherHandle.GetObject() == &test);
|
CHECK(otherHandle.GetObject() == &test);
|
||||||
|
CHECK(otherHandle->i == moveValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue