From: rousskov <> Date: Fri, 6 Apr 2007 10:40:58 +0000 (+0000) Subject: - Support printing refcounted pointers to ostreams. When X-Git-Tag: SQUID_3_0_PRE6~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c36d157827dad3bd98870497df369dd981c3f67;p=thirdparty%2Fsquid.git - Support printing refcounted pointers to ostreams. When 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. --- diff --git a/include/RefCount.h b/include/RefCount.h index cf47b5790c..5ccf56c6ae 100644 --- a/include/RefCount.h +++ b/include/RefCount.h @@ -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 + template 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 +inline std::ostream &operator <<(std::ostream &os, const RefCount &p) +{ + if (p != NULL) + return os << p.getRaw() << '*' << p->RefCountCount(); + else + return os << "NULL"; +} + #endif /* _SQUID_REFCOUNT_H_ */