Use TypeInstance field instead of looking up types by name

fixes #8817
This commit is contained in:
Gunnar Beutner 2015-03-20 08:15:07 +01:00
parent 0c0bae220b
commit 16ef84fd35
6 changed files with 9 additions and 23 deletions

View File

@ -41,7 +41,7 @@ DynamicType::Ptr DynamicType::GetByName(const String& name)
if (tt == InternalGetTypeMap().end()) {
Type::Ptr type = Type::GetByName(name);
if (!type || !Type::GetByName("DynamicObject")->IsAssignableFrom(type)
if (!type || !DynamicObject::TypeInstance->IsAssignableFrom(type)
|| type->IsAbstract())
return DynamicType::Ptr();

View File

@ -217,20 +217,7 @@ Array::Ptr ScriptUtils::Range(const std::vector<Value>& arguments)
Type::Ptr ScriptUtils::TypeOf(const Value& value)
{
switch (value.GetType()) {
case ValueEmpty:
return Type::GetByName("Object");
case ValueNumber:
return Type::GetByName("Number");
case ValueBoolean:
return Type::GetByName("Boolean");
case ValueString:
return Type::GetByName("String");
case ValueObject:
return static_cast<Object::Ptr>(value)->GetReflectionType();
default:
VERIFY(!"Invalid value type.");
}
return value.GetReflectionType();
}
Array::Ptr ScriptUtils::Keys(const Dictionary::Ptr& dict)

View File

@ -90,7 +90,7 @@ Type::Ptr Value::GetReflectionType(void) const
{
switch (GetType()) {
case ValueEmpty:
return Type::GetByName("Object");
return Object::TypeInstance;
case ValueNumber:
return Type::GetByName("Number");
case ValueBoolean:

View File

@ -255,10 +255,10 @@ void CheckerComponent::ResultTimerHandler(void)
void CheckerComponent::ObjectHandler(const DynamicObject::Ptr& object)
{
if (!Type::GetByName("Checkable")->IsAssignableFrom(object->GetReflectionType()))
return;
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
if (!checkable)
return;
Zone::Ptr zone = Zone::GetByName(checkable->GetZoneName());
bool same_zone = (!zone || Zone::GetLocalZone() == zone);

View File

@ -152,7 +152,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
/* Make sure the type is valid. */
Type::Ptr type = Type::GetByName(GetType());
ASSERT(type && Type::GetByName("DynamicObject")->IsAssignableFrom(type));
ASSERT(type && DynamicObject::TypeInstance->IsAssignableFrom(type));
if (IsAbstract())
return DynamicObject::Ptr();
@ -335,9 +335,8 @@ bool ConfigItem::CommitNewItems(WorkQueue& upq)
}
}
Type::Ptr dotype = Type::GetByName("DynamicObject");
BOOST_FOREACH(const Type::Ptr& type, all_types) {
if (dotype->IsAssignableFrom(type))
if (DynamicObject::TypeInstance->IsAssignableFrom(type))
types.insert(type->GetName());
}

View File

@ -80,7 +80,7 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
Type::Ptr type = Type::GetByName(idoType);
if (!type || !Type::GetByName("DbConnection")->IsAssignableFrom(type)) {
if (!type || !DbConnection::TypeInstance->IsAssignableFrom(type)) {
cr->SetOutput("IDO type '" + idoType + "' is invalid.");
cr->SetState(ServiceUnknown);
checkable->ProcessCheckResult(cr);