Avoid using ConfigItem::GetObject when possible.

Refs #5327
This commit is contained in:
Gunnar Beutner 2013-12-10 20:01:38 +01:00 committed by Gunnar Beutner
parent 37179cdf32
commit b5792a0b81
3 changed files with 13 additions and 5 deletions

View File

@ -219,6 +219,17 @@ ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name)
return ConfigItem::Ptr();
}
bool ConfigItem::HasObject(const String& type, const String& name)
{
boost::mutex::scoped_lock lock(m_Mutex);
ConfigItem::ItemMap::iterator it;
it = m_Items.find(std::make_pair(type, name));
return (it != m_Items.end());
}
void ConfigItem::ValidateItem(void)
{
if (m_Validated)

View File

@ -58,6 +58,7 @@ public:
static ConfigItem::Ptr GetObject(const String& type,
const String& name);
static bool HasObject(const String& type, const String& name);
void ValidateItem(void);

View File

@ -45,8 +45,6 @@ bool TypeRule::MatchName(const String& name) const
bool TypeRule::MatchValue(const Value& value, String *hint) const
{
ConfigItem::Ptr item;
if (value.IsEmpty())
return true;
@ -78,9 +76,7 @@ bool TypeRule::MatchValue(const Value& value, String *hint) const
if (!value.IsScalar())
return false;
item = ConfigItem::GetObject(m_NameType, value);
if (!item) {
if (!ConfigItem::HasObject(m_NameType, value)) {
*hint = "Object '" + value + "' of type '" + m_NameType + "' does not exist.";
return false;
}