From: Alex Rousskov Date: Sat, 11 Sep 2010 23:56:07 +0000 (-0600) Subject: Added HttpMsg::Pointer typedef and convenience HttpMsg::Pointer operators. X-Git-Tag: take1~276 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=db2603419800ec43d99cd20ef0f96b5bbdd7b67e;p=thirdparty%2Fsquid.git Added HttpMsg::Pointer typedef and convenience HttpMsg::Pointer operators. --- diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 5d528e7cba..25e8928117 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -41,10 +41,16 @@ // common parts of HttpRequest and HttpReply +template +class HttpMsgPointerT; + + class HttpMsg { public: + typedef HttpMsgPointerT Pointer; + HttpMsg(http_hdr_owner_type owner); virtual ~HttpMsg(); @@ -198,6 +204,17 @@ public: HttpMsgPointerT(const HttpMsgPointerT &p): msg(p.msg) { lock(); } HttpMsgPointerT &operator =(const HttpMsgPointerT &p) { if (msg != p.msg) { unlock(); msg = p.msg; lock(); } return *this; } + HttpMsgPointerT &operator =(Msg *newM) + { if (msg != newM) { unlock(); msg = newM; lock(); } return *this; } + + /// support converting a child msg pointer into a parent msg pointer + template + HttpMsgPointerT(const HttpMsgPointerT &o): msg(o.raw()) { lock(); } + + /// support assigning a child msg pointer to a parent msg pointer + template + HttpMsgPointerT &operator =(const HttpMsgPointerT &o) + { if (msg != o.raw()) { unlock(); msg = o.raw(); lock(); } return *this; } Msg &operator *() { return *msg; } const Msg &operator *() const { return *msg; } @@ -207,6 +224,9 @@ public: operator const Msg *() const { return msg; } // add more as needed + /// public access for HttpMsgPointerT copying and assignment; avoid + Msg *raw() const { return msg; } + protected: void lock() { if (msg) HTTPMSGLOCK(msg); } ///< prevent msg destruction void unlock() { HTTPMSGUNLOCK(msg); } ///< allows/causes msg destruction