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