Register type objects as global variables

fixes #8019
This commit is contained in:
Gunnar Beutner 2014-12-08 08:49:32 +01:00
parent 04ca634a16
commit 57f84741b9
2 changed files with 10 additions and 18 deletions

View File

@ -18,33 +18,30 @@
******************************************************************************/
#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);
it = GetTypes().find(name);
if (it == GetTypes().end())
if (!svtype)
return Type::Ptr();
return it->second;
Value ptype = svtype->GetData();
if (!ptype.IsObjectType<Type>())
return Type::Ptr();
return ptype;
}
Object::Ptr Type::Instantiate(void) const

View 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>