diff options
Diffstat (limited to 'src/BlockTypeRegistry.cpp')
-rw-r--r-- | src/BlockTypeRegistry.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/BlockTypeRegistry.cpp b/src/BlockTypeRegistry.cpp index 45ad20082..cc6945e27 100644 --- a/src/BlockTypeRegistry.cpp +++ b/src/BlockTypeRegistry.cpp @@ -56,6 +56,33 @@ AString BlockInfo::hintValue( +void BlockInfo::setHint(const AString & aHintKey, const AString & aHintValue) +{ + mHints[aHintKey] = aHintValue; + + // Warn if the hint is already provided by a callback (aHintValue will be ignored when evaluating the hint): + auto itrC = mHintCallbacks.find(aHintKey); + if (itrC != mHintCallbacks.end()) + { + LOGINFO("Setting a static hint %s for block type %s, but there's already a callback for that hint. The static hint will be ignored.", + aHintKey.c_str(), mBlockTypeName.c_str() + ); + } +} + + + + + +void BlockInfo::removeHint(const AString & aHintKey) +{ + mHints.erase(aHintKey); +} + + + + + //////////////////////////////////////////////////////////////////////////////// // BlockTypeRegistry: @@ -123,6 +150,43 @@ void BlockTypeRegistry::removeAllByPlugin(const AString & aPluginName) +void BlockTypeRegistry::setBlockTypeHint( + const AString & aBlockTypeName, + const AString & aHintKey, + const AString & aHintValue +) +{ + cCSLock lock(mCSRegistry); + auto blockInfo = mRegistry.find(aBlockTypeName); + if (blockInfo == mRegistry.end()) + { + throw NotRegisteredException(aBlockTypeName, aHintKey, aHintValue); + } + blockInfo->second->setHint(aHintKey, aHintValue); +} + + + + + +void BlockTypeRegistry::removeBlockTypeHint( + const AString & aBlockTypeName, + const AString & aHintKey +) +{ + cCSLock lock(mCSRegistry); + auto blockInfo = mRegistry.find(aBlockTypeName); + if (blockInfo == mRegistry.end()) + { + return; + } + blockInfo->second->removeHint(aHintKey); +} + + + + + //////////////////////////////////////////////////////////////////////////////// // BlockTypeRegistry::AlreadyRegisteredException: @@ -151,3 +215,24 @@ AString BlockTypeRegistry::AlreadyRegisteredException::message( aPreviousRegistration->pluginName().c_str() ); } + + + + + +//////////////////////////////////////////////////////////////////////////////// +// BlockTypeRegistry::NotRegisteredException: + +BlockTypeRegistry::NotRegisteredException::NotRegisteredException( + const AString & aBlockTypeName, + const AString & aHintKey, + const AString & aHintValue +): + Super(Printf( + "Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = %s\n\tHintKey = %s\n\tHintValue = %s", + aBlockTypeName.c_str(), + aHintKey.c_str(), + aHintValue.c_str() + )) +{ +} |