From db2603419800ec43d99cd20ef0f96b5bbdd7b67e Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Sat, 11 Sep 2010 17:56:07 -0600 Subject: [PATCH] Added HttpMsg::Pointer typedef and convenience HttpMsg::Pointer operators. --- src/HttpMsg.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 -- 2.47.2