mirror of https://github.com/Icinga/icinga2.git
parent
2a6151e935
commit
ba6f64a0ec
|
@ -37,7 +37,7 @@ DynamicType::Ptr DynamicType::GetByName(const String& name)
|
|||
if (tt == InternalGetTypeMap().end()) {
|
||||
const Type *type = Type::GetByName(name);
|
||||
|
||||
if (!type || !GetType<DynamicObject>()->IsAssignableFrom(type)
|
||||
if (!type || !Type::GetByName("DynamicObject")->IsAssignableFrom(type)
|
||||
|| type->IsAbstract())
|
||||
return DynamicType::Ptr();
|
||||
|
||||
|
|
|
@ -54,9 +54,10 @@ Object::Ptr Type::Instantiate(void) const
|
|||
|
||||
bool Type::IsAssignableFrom(const Type *other) const
|
||||
{
|
||||
for (const Type *t = other; t; t = t->GetBaseType())
|
||||
for (const Type *t = other; t; t = t->GetBaseType()) {
|
||||
if (t == this)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -74,12 +74,6 @@ class TypeImpl
|
|||
{
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Type *GetType(void)
|
||||
{
|
||||
return TypeImpl<T>::GetInstance();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
shared_ptr<T> ObjectFactory(void)
|
||||
{
|
||||
|
@ -99,9 +93,9 @@ struct FactoryHelper
|
|||
namespace { \
|
||||
void RegisterType(void) \
|
||||
{ \
|
||||
icinga::Type *t = icinga::GetType<type>(); \
|
||||
icinga::Type *t = new TypeImpl<type>(); \
|
||||
t->SetFactory(FactoryHelper<type>().GetFactory()); \
|
||||
icinga::Type::Register(GetType<type>()); \
|
||||
icinga::Type::Register(t); \
|
||||
} \
|
||||
\
|
||||
INITIALIZE_ONCE(RegisterType); \
|
||||
|
|
|
@ -32,15 +32,15 @@ BOOST_AUTO_TEST_SUITE(base_type)
|
|||
|
||||
BOOST_AUTO_TEST_CASE(gettype)
|
||||
{
|
||||
const Type *t = GetType<Application>();
|
||||
const Type *t = Type::GetByName("Application");
|
||||
|
||||
BOOST_CHECK(t);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assign)
|
||||
{
|
||||
const Type *t1 = GetType<Application>();
|
||||
const Type *t2 = GetType<DynamicObject>();
|
||||
const Type *t1 = Type::GetByName("Application");
|
||||
const Type *t2 = Type::GetByName("DynamicObject");
|
||||
|
||||
BOOST_CHECK(t1->IsAssignableFrom(t1));
|
||||
BOOST_CHECK(t2->IsAssignableFrom(t1));
|
||||
|
|
|
@ -88,7 +88,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
|
|||
/* TypeImpl */
|
||||
std::cout << "template<>" << std::endl
|
||||
<< "class TypeImpl<" << klass.Name << ">"
|
||||
<< " : public Type, public Singleton<TypeImpl<" << klass.Name << "> >" << std::endl
|
||||
<< " : public Type" << std::endl
|
||||
<< "{" << std::endl
|
||||
<< "public:" << std::endl;
|
||||
|
||||
|
@ -111,7 +111,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
|
|||
std::cout << "\t\t" << "return ";
|
||||
|
||||
if (!klass.Parent.empty())
|
||||
std::cout << "Singleton<TypeImpl<" << klass.Parent << "> >::GetInstance()";
|
||||
std::cout << "Type::GetByName(\"" << klass.Parent << "\")";
|
||||
else
|
||||
std::cout << "NULL";
|
||||
|
||||
|
@ -220,7 +220,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
|
|||
/* GetReflectionType */
|
||||
std::cout << "\t" << "virtual const Type *GetReflectionType(void) const" << std::endl
|
||||
<< "\t" << "{" << std::endl
|
||||
<< "\t\t" << "return TypeImpl<" << klass.Name << ">::GetInstance();" << std::endl
|
||||
<< "\t\t" << "return Type::GetByName(\"" << klass.Name << "\");" << std::endl
|
||||
<< "\t" << "}" << std::endl << std::endl;
|
||||
|
||||
if (!klass.Fields.empty()) {
|
||||
|
@ -408,7 +408,6 @@ void ClassCompiler::CompileStream(const std::string& path, std::istream *stream)
|
|||
|
||||
std::cout << "#include \"base/object.h\"" << std::endl
|
||||
<< "#include \"base/type.h\"" << std::endl
|
||||
<< "#include \"base/singleton.h\"" << std::endl
|
||||
<< "#include \"base/debug.h\"" << std::endl
|
||||
<< "#include \"base/value.h\"" << std::endl
|
||||
<< "#include \"base/array.h\"" << std::endl
|
||||
|
|
Loading…
Reference in New Issue