Add missing meta type class for the Type class

refs #8169
This commit is contained in:
Gunnar Beutner 2015-01-14 09:51:44 +01:00
parent 9c36f40656
commit 688e64ce40
2 changed files with 76 additions and 0 deletions

View File

@ -22,6 +22,15 @@
using namespace icinga;
static void RegisterTypeType(void)
{
Type::Ptr type = new TypeType();
Type::TypeInstance = type;
Type::Register(type);
}
INITIALIZE_ONCE(RegisterTypeType);
String Type::ToString(void) const
{
return "type '" + GetName() + "'";
@ -79,3 +88,52 @@ void Type::SetPrototype(const Object::Ptr& object)
m_Prototype = object;
}
Value Type::GetField(int id) const
{
if (id == 0)
return GetPrototype();
return Object::GetField(id);
}
String TypeType::GetName(void) const
{
return "Type";
}
Type::Ptr TypeType::GetBaseType(void) const
{
return Type::Ptr();
}
int TypeType::GetAttributes(void) const
{
return 0;
}
int TypeType::GetFieldId(const String& name) const
{
if (name == "prototype")
return 0;
return -1;
}
Field TypeType::GetFieldInfo(int id) const
{
if (id == 0)
return Field(0, "Object", "prototype", 0);
throw std::runtime_error("Invalid field ID.");
}
int TypeType::GetFieldCount(void) const
{
return 1;
}
ObjectFactory TypeType::GetFactory(void) const
{
return NULL;
}

View File

@ -81,6 +81,8 @@ public:
static void Register(const Type::Ptr& type);
static Type::Ptr GetByName(const String& name);
virtual Value GetField(int id) const;
protected:
virtual ObjectFactory GetFactory(void) const = 0;
@ -88,6 +90,22 @@ private:
Object::Ptr m_Prototype;
};
class I2_BASE_API TypeType : public Type
{
public:
DECLARE_PTR_TYPEDEFS(Type);
virtual String GetName(void) const;
virtual Type::Ptr GetBaseType(void) const;
virtual int GetAttributes(void) const;
virtual int GetFieldId(const String& name) const;
virtual Field GetFieldInfo(int id) const;
virtual int GetFieldCount(void) const;
protected:
virtual ObjectFactory GetFactory(void) const;
};
template<typename T>
class TypeImpl
{