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

@@ -74,7 +74,12 @@ namespace BlackMisc
template <typename T>
CSetting(T *owner) :
CSetting::CCached(CSettingsCache::instance(), Trait::key(), Trait::humanReadable(), Trait::isValid, Trait::defaultValue(), owner)
{}
{
if (! this->isInitialized())
{
this->onOwnerNameChanged([this, owner] { Private::reconstruct(this, owner); });
}
}
//! Constructor.
//! \param owner Will be the parent of the internal QObject used to access the value.