]> granicus.if.org Git - icinga2/commitdiff
Improve output of ToString for type objects
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 8 Dec 2014 08:12:40 +0000 (09:12 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 8 Dec 2014 08:12:40 +0000 (09:12 +0100)
fixes #8020

lib/base/object.cpp
lib/base/object.hpp
lib/base/type.cpp
lib/base/type.hpp
lib/base/value-operators.cpp

index b77175d8c6300d6393592d3c2d1f2667f914e929..2245166893b19ea87068bedd858c600be27aecc5 100644 (file)
@@ -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.
index 86f96119e88bc78b6abf6ac6fa49d6b3ad946f97..49b068a092177a8835e5486ca98df0ddfe237308 100644 (file)
@@ -46,6 +46,7 @@ namespace icinga
 class Value;
 class Object;
 class Type;
+class String;
 
 #define DECLARE_PTR_TYPEDEFS(klass) \
        typedef intrusive_ptr<klass> 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;
 
index 1ca108cd79390ead4aade758e84b8a6225c66014..5a9f1b7f7142416d2f538900445886bd02cf2f40 100644 (file)
 
 using namespace icinga;
 
+String Type::ToString(void) const
+{
+       return "type '" + GetName() + "'";
+}
+
 void Type::Register(const Type::Ptr& type)
 {
        VERIFY(GetByName(type->GetName()) == NULL);
index 0654113615bb54cfa985c11efd0c355dcd092636..8eb853d735a871c39c386992d435854bf9696db1 100644 (file)
@@ -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;
index 9b39c1e2f8eee64d6a6230091c49d04f944960ec..8b5b7f771a68f19374b3e7a3256f2306b86cb3ad 100644 (file)
@@ -59,7 +59,7 @@ Value::operator String(void) const
                        return boost::get<String>(m_Value);
                case ValueObject:
                        object = boost::get<Object::Ptr>(m_Value).get();
-                       return "Object of type '" + Utility::GetTypeName(typeid(*object)) + "'";
+                       return object->ToString();
                default:
                        BOOST_THROW_EXCEPTION(std::runtime_error("Unknown value type."));
        }