From 16ef84fd35785a9ee24fee402ccea5ea7633deca Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 20 Mar 2015 08:15:07 +0100 Subject: [PATCH] Use TypeInstance field instead of looking up types by name fixes #8817 --- lib/base/dynamictype.cpp | 2 +- lib/base/scriptutils.cpp | 15 +-------------- lib/base/value.cpp | 2 +- lib/checker/checkercomponent.cpp | 6 +++--- lib/config/configitem.cpp | 5 ++--- lib/db_ido/idochecktask.cpp | 2 +- 6 files changed, 9 insertions(+), 23 deletions(-) diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index cbb0e0b5e..27b84eb31 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -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(); diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 3b743169d..cf4808903 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -217,20 +217,7 @@ Array::Ptr ScriptUtils::Range(const std::vector& 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(value)->GetReflectionType(); - default: - VERIFY(!"Invalid value type."); - } + return value.GetReflectionType(); } Array::Ptr ScriptUtils::Keys(const Dictionary::Ptr& dict) diff --git a/lib/base/value.cpp b/lib/base/value.cpp index 62a466c97..d050c86bd 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -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: diff --git a/lib/checker/checkercomponent.cpp b/lib/checker/checkercomponent.cpp index 1040a135a..89e5b015b 100644 --- a/lib/checker/checkercomponent.cpp +++ b/lib/checker/checkercomponent.cpp @@ -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(object); - Checkable::Ptr checkable = static_pointer_cast(object); + if (!checkable) + return; Zone::Ptr zone = Zone::GetByName(checkable->GetZoneName()); bool same_zone = (!zone || Zone::GetLocalZone() == zone); diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index aa4964425..b5ed42731 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -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()); } diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index ed9b4ffed..7020ef4be 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -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);