refs #684, #766, #776 Support %OwnerName% in cache keys by allowing CCached::m_element to be a dummy

and by using a trick with explicit destructor call and placement new to reconstruct CCached when owner's name changes.
This commit is contained in:
Mathew Sutcliffe
2016-10-15 20:37:00 +01:00
parent 9acfb89e65
commit 8a65a33384
5 changed files with 61 additions and 5 deletions

View File

@@ -43,6 +43,16 @@ namespace BlackMisc
};
//! \endcond
/*!
* \private Destroy an object and reconstruct it with the given constructor arguments.
*/
template <typename T, typename... Args>
void reconstruct(T *object, Args &&... args)
{
object->~T();
new (object) T(std::forward<Args>(args)...);
}
/*!
* \private QObject subclass used by CCached<T> class template for signal/slot communication with CValueCache.
* An instance of this class is shared between all CCached<T> referring to the same CValueCache and owned by the same QObject,
@@ -76,6 +86,9 @@ namespace BlackMisc
//! Set the functor to call to notify that the value corresponding to the element's key was modified.
void setNotifySlot(Element &element, NotifySlot slot);
//! True if the currently paged value corresponds to a valid key.
bool isInitialized(const Element &element) const;
//! True if the currently paged value is a valid instance of the given type.
//! \threadsafe
bool isValid(const Element &element, int typeId) const;