From 688e64ce405c0c82545ed363ed28518c644400c7 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 14 Jan 2015 09:51:44 +0100 Subject: [PATCH] Add missing meta type class for the Type class refs #8169 --- lib/base/type.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++ lib/base/type.hpp | 18 +++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/lib/base/type.cpp b/lib/base/type.cpp index ae8faa2c3..93ae1b9bd 100644 --- a/lib/base/type.cpp +++ b/lib/base/type.cpp @@ -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; +} + diff --git a/lib/base/type.hpp b/lib/base/type.hpp index be51c4269..30fd671a5 100644 --- a/lib/base/type.hpp +++ b/lib/base/type.hpp @@ -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 class TypeImpl { -- 2.40.0