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 | 64 +++++++++++++++++++------------------- icinga/nagioschecktask.cpp | 7 +++-- 3 files changed, 38 insertions(+), 37 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,46 +45,46 @@ protected: void Hold(void); - SharedPtrHolder GetSelf(void); - -private: - Object(const Object& other); - Object operator=(const Object& rhs); - - 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 + /** + * 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); + shared_ptr other = dynamic_pointer_cast(m_Object); + assert(other); #else /* _DEBUG */ - shared_ptr other = static_pointer_cast(m_Object); + shared_ptr other = static_pointer_cast(m_Object); #endif /* _DEBUG */ - return other; - } + return other; + } - template - operator weak_ptr(void) const - { - return static_cast >(*this); - } + template + operator weak_ptr(void) const + { + return static_cast >(*this); + } + + private: + Object::Ptr m_Object; + }; + + SharedPtrHolder GetSelf(void); private: - shared_ptr m_Object; + Object(const Object& other); + Object operator=(const Object& rhs); + + static vector m_HeldObjects; }; /** 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); -- 2.40.0