From 7d630249ccaf7d1560d988528bba9501c8fed0fe Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 16 Jun 2012 16:54:55 +0200 Subject: [PATCH] Code cleanup. --- base/object.cpp | 4 +-- base/object.h | 66 +++++++++++++++++++------------------- icinga/nagioschecktask.cpp | 7 ++-- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/base/object.cpp b/base/object.cpp index 924cc9842..ccc9ac171 100644 --- a/base/object.cpp +++ b/base/object.cpp @@ -55,7 +55,7 @@ void Object::ClearHeldObjects(void) m_HeldObjects.clear(); } -SharedPtrHolder Object::GetSelf(void) +Object::SharedPtrHolder Object::GetSelf(void) { - return SharedPtrHolder(shared_from_this()); + return Object::SharedPtrHolder(shared_from_this()); } diff --git a/base/object.h b/base/object.h index ca8170e33..d0287947c 100644 --- a/base/object.h +++ b/base/object.h @@ -45,6 +45,39 @@ protected: void Hold(void); + /** + * Holds a shared pointer and provides support for implicit upcasts. + */ + class SharedPtrHolder + { + public: + explicit SharedPtrHolder(const Object::Ptr& object) + : m_Object(object) + { } + + template + operator shared_ptr(void) const + { +#ifdef _DEBUG + shared_ptr other = dynamic_pointer_cast(m_Object); + assert(other); +#else /* _DEBUG */ + shared_ptr other = static_pointer_cast(m_Object); +#endif /* _DEBUG */ + + return other; + } + + template + operator weak_ptr(void) const + { + return static_cast >(*this); + } + + private: + Object::Ptr m_Object; + }; + SharedPtrHolder GetSelf(void); private: @@ -54,39 +87,6 @@ private: static vector m_HeldObjects; }; -/** - * Holds a shared pointer and provides support for implicit upcasts. - */ -class SharedPtrHolder -{ -public: - explicit SharedPtrHolder(const shared_ptr& object) - : m_Object(object) - { } - - template - operator shared_ptr(void) const - { -#ifdef _DEBUG - shared_ptr other = dynamic_pointer_cast(m_Object); - assert(other); -#else /* _DEBUG */ - shared_ptr other = static_pointer_cast(m_Object); -#endif /* _DEBUG */ - - return other; - } - - template - operator weak_ptr(void) const - { - return static_cast >(*this); - } - -private: - shared_ptr m_Object; -}; - /** * Compares a weak pointer with a raw pointer. */ diff --git a/icinga/nagioschecktask.cpp b/icinga/nagioschecktask.cpp index 26868806b..92c992d05 100644 --- a/icinga/nagioschecktask.cpp +++ b/icinga/nagioschecktask.cpp @@ -25,7 +25,7 @@ CheckResult NagiosCheckTask::Execute(void) const fp = popen(command.c_str(), "r"); #endif /* _MSC_VER */ - stringstream output; + stringstream outputbuf; while (!feof(fp)) { char buffer[128]; @@ -34,10 +34,11 @@ CheckResult NagiosCheckTask::Execute(void) const if (read == 0) break; - output << string(buffer, buffer + read); + outputbuf << string(buffer, buffer + read); } - cr.Output = output.str(); + cr.Output = outputbuf.str(); + boost::algorithm::trim(cr.Output); Application::Log(LogDebug, "icinga", "Nagios plugin output: " + cr.Output);