From: Gunnar Beutner Date: Mon, 8 Dec 2014 08:12:40 +0000 (+0100) Subject: Improve output of ToString for type objects X-Git-Tag: v2.3.0~553 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf2b6e7ccc9be68eeff59ccb62635721207adde2;p=icinga2 Improve output of ToString for type objects fixes #8020 --- diff --git a/lib/base/object.cpp b/lib/base/object.cpp index b77175d8c..224516689 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -20,6 +20,7 @@ #include "base/object.hpp" #include "base/value.hpp" #include "base/primitivetype.hpp" +#include "base/utility.hpp" using namespace icinga; @@ -41,6 +42,14 @@ Object::Object(void) Object::~Object(void) { } +/** + * Returns a string representation for the object. + */ +String Object::ToString(void) const +{ + return "Object of type '" + Utility::GetTypeName(typeid(*this)) + "'"; +} + #ifdef _DEBUG /** * Checks if the calling thread owns the lock on this object. diff --git a/lib/base/object.hpp b/lib/base/object.hpp index 86f96119e..49b068a09 100644 --- a/lib/base/object.hpp +++ b/lib/base/object.hpp @@ -46,6 +46,7 @@ namespace icinga class Value; class Object; class Type; +class String; #define DECLARE_PTR_TYPEDEFS(klass) \ typedef intrusive_ptr Ptr @@ -92,6 +93,8 @@ public: Object(void); virtual ~Object(void); + virtual String ToString(void) const; + virtual void SetField(int id, const Value& value); virtual Value GetField(int id) const; diff --git a/lib/base/type.cpp b/lib/base/type.cpp index 1ca108cd7..5a9f1b7f7 100644 --- a/lib/base/type.cpp +++ b/lib/base/type.cpp @@ -22,6 +22,11 @@ using namespace icinga; +String Type::ToString(void) const +{ + return "type '" + GetName() + "'"; +} + void Type::Register(const Type::Ptr& type) { VERIFY(GetByName(type->GetName()) == NULL); diff --git a/lib/base/type.hpp b/lib/base/type.hpp index 065411361..8eb853d73 100644 --- a/lib/base/type.hpp +++ b/lib/base/type.hpp @@ -60,6 +60,8 @@ class I2_BASE_API Type : public Object public: DECLARE_PTR_TYPEDEFS(Type); + virtual String ToString(void) const; + virtual String GetName(void) const = 0; virtual Type::Ptr GetBaseType(void) const = 0; virtual int GetAttributes(void) const = 0; diff --git a/lib/base/value-operators.cpp b/lib/base/value-operators.cpp index 9b39c1e2f..8b5b7f771 100644 --- a/lib/base/value-operators.cpp +++ b/lib/base/value-operators.cpp @@ -59,7 +59,7 @@ Value::operator String(void) const return boost::get(m_Value); case ValueObject: object = boost::get(m_Value).get(); - return "Object of type '" + Utility::GetTypeName(typeid(*object)) + "'"; + return object->ToString(); default: BOOST_THROW_EXCEPTION(std::runtime_error("Unknown value type.")); }