Improve output of ToString for type objects

fixes #8020
This commit is contained in:
Gunnar Beutner 2014-12-08 09:12:40 +01:00
parent 57f84741b9
commit cf2b6e7ccc
5 changed files with 20 additions and 1 deletions

View 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.

View 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;

View File

@ -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);

View 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;

View 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."));
}