From 0a96b3d223c1ddf63d845802db3d21aca3a7c2df Mon Sep 17 00:00:00 2001 From: prozacx Date: Tue, 10 Mar 2009 19:36:24 +0000 Subject: [PATCH] Pulled in changes for CSmartPtr which include GetClientCount(), operator bool(), and ability to Attach() to NULL pointers git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1421 726aef4b-f618-498e-8847-2d620e286838 --- Utils.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Utils.h b/Utils.h index 2adf97d5..2f251009 100644 --- a/Utils.h +++ b/Utils.h @@ -328,10 +328,10 @@ public: /** * @brief Attach() to a raw pointer - * @param p The raw pointer to keep track of, ***WARNING*** Do _NOT_ allow more than one CSmartPtr keep track of the same raw pointer + * @param pRawPtr The raw pointer to keep track of, ***WARNING*** Do _NOT_ allow more than one CSmartPtr keep track of the same raw pointer * @return Reference to self */ - CSmartPtr& operator =(T* p) { Attach(p); return *this; } + CSmartPtr& operator =(T* pRawPtr) { Attach(pRawPtr); return *this; } /** * @brief Copies an existing CSmartPtr adding another reference to the counter @@ -359,6 +359,14 @@ public: } // !Overloaded operators + /** + * @brief Implicit type conversion to bool for things like if (!ptr) {} and if (ptr) {} + * @return @see IsNull() + */ + operator bool() const { + return !IsNull(); + } + /** * @brief Check to see if the underlying raw pointer is null * @return Whether or not underlying raw pointer is null @@ -373,8 +381,6 @@ public: * @return Reference to self */ CSmartPtr& Attach(T* pRawPtr) { - assert(pRawPtr); - if (pRawPtr != m_pType) { // Check for assignment to self Release(); // Release the current pointer m_pType = pRawPtr; // Point to the passed raw pointer @@ -408,6 +414,7 @@ public: // Getters T* GetPtr() const { return m_pType; } unsigned int* GetCount() const { return m_puCount; } + unsigned int GetClientCount() const { return (m_puCount) ? *m_puCount : 0; } // !Getters private: T* m_pType; //!< Raw pointer to the class being referenced