]> granicus.if.org Git - icinga2/commitdiff
Register type objects as global variables
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 8 Dec 2014 07:49:32 +0000 (08:49 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 8 Dec 2014 07:49:32 +0000 (08:49 +0100)
fixes #8019

lib/base/type.cpp
lib/base/type.hpp

index e1e933678c5183160e5f624d5f90f5679fdb3310..1ca108cd79390ead4aade758e84b8a6225c66014 100644 (file)
  ******************************************************************************/
 
 #include "base/type.hpp"
+#include "base/scriptvariable.hpp"
 
 using namespace icinga;
 
-Type::TypeMap& Type::GetTypes(void)
-{
-       static TypeMap types;
-
-       return types;
-}
-
 void Type::Register(const Type::Ptr& type)
 {
        VERIFY(GetByName(type->GetName()) == NULL);
 
-       GetTypes()[type->GetName()] = type;
+       ScriptVariable::Set(type->GetName(), type, true, true);
 }
 
 Type::Ptr Type::GetByName(const String& name)
 {
-       std::map<String, Type::Ptr>::const_iterator it;
+       ScriptVariable::Ptr svtype = ScriptVariable::GetByName(name);
+
+       if (!svtype)
+               return Type::Ptr();
 
-       it = GetTypes().find(name);
+       Value ptype = svtype->GetData();
 
-       if (it == GetTypes().end())
+       if (!ptype.IsObjectType<Type>())
                return Type::Ptr();
 
-       return it->second;
+       return ptype;
 }
 
 Object::Ptr Type::Instantiate(void) const
index 2ae18547892b6914bcfbdf38b1a42207bd44aa9c..0654113615bb54cfa985c11efd0c355dcd092636 100644 (file)
@@ -78,11 +78,6 @@ public:
 
 protected:
        virtual ObjectFactory GetFactory(void) const = 0;
-
-private:
-       typedef std::map<String, Type::Ptr> TypeMap;
-
-       static TypeMap& GetTypes(void);
 };
 
 template<typename T>