]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- Support printing refcounted pointers to ostreams. When
authorrousskov <>
Fri, 6 Apr 2007 10:40:58 +0000 (10:40 +0000)
committerrousskov <>
Fri, 6 Apr 2007 10:40:58 +0000 (10:40 +0000)
  printing, report the reference count after the raw pointer.
  This makes debugs() statements simpler and their output more
  informative. Null pointers are printed as a "NULL" string.

include/RefCount.h

index cf47b5790c78604ab03d65bb8153eb1b4bc6eac3..5ccf56c6ae287f4fc5ca3ce231764dcf4e182f82 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: RefCount.h,v 1.9 2005/11/21 22:45:16 wessels Exp $
+ * $Id: RefCount.h,v 1.10 2007/04/06 04:40:58 rousskov Exp $
  *
  * DEBUG: section xx    Refcount allocator
  * AUTHOR:  Robert Collins
@@ -36,6 +36,8 @@
 #ifndef _SQUID_REFCOUNT_H_
 #define _SQUID_REFCOUNT_H_
 
+#include <iostream>
+
 template <class C>
 
 class RefCount
@@ -139,10 +141,21 @@ struct RefCountable_
         return --count_;
     }
 
+    unsigned RefCountCount() const { return count_; } // for debugging only
+
 private:
     mutable unsigned count_;
 };
 
 #define RefCountable virtual RefCountable_
 
+template <class C>
+inline std::ostream &operator <<(std::ostream &os, const RefCount<C> &p)
+{
+    if (p != NULL)
+        return os << p.getRaw() << '*' << p->RefCountCount();
+    else
+        return os << "NULL";
+}
+
 #endif /* _SQUID_REFCOUNT_H_ */