]> granicus.if.org Git - icinga2/commitdiff
Use TypeInstance field instead of looking up types by name
authorGunnar Beutner <gunnar@beutner.name>
Fri, 20 Mar 2015 07:15:07 +0000 (08:15 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 20 Mar 2015 07:15:07 +0000 (08:15 +0100)
fixes #8817

lib/base/dynamictype.cpp
lib/base/scriptutils.cpp
lib/base/value.cpp
lib/checker/checkercomponent.cpp
lib/config/configitem.cpp
lib/db_ido/idochecktask.cpp

index cbb0e0b5e27115ff9a2c4b6c81ebe73e449e1424..27b84eb31217772e410f04c6a848b2f7514b8627 100644 (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();
 
index 3b743169d286e4d1bb9fee101d8dd0cd03c54ebe..cf48089030d4efe1095edf7c5fb5fb40d8c7708d 100644 (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)
index 62a466c976273cec7edfe8155b3f3683964cd916..d050c86bdcb887eae6d9289e3d1e2c588e4f7549 100644 (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:
index 1040a135ac99b63a7cc6945984b3bf6a7aaa788d..89e5b015b4e49604a40ba61d9df36806e18a8a2e 100644 (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);
index aa49644258b16624724e15e26e15c49d82f17148..b5ed42731b37b23d387433673ba235f0d469e8d0 100644 (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());
        }
 
index ed9b4ffedde164906fe23129366b5da37ebcb206..7020ef4becac8108191b1721057b6da19558b13e 100644 (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);