]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Alex Rousskov <rousskov@measurement-factory.com>
authorAmos Jeffries <amosjeffries@squid-cache.org>
Thu, 23 Sep 2010 13:51:14 +0000 (07:51 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Thu, 23 Sep 2010 13:51:14 +0000 (07:51 -0600)
Added HttpMsg::Pointer typedef and convenience HttpMsg::Pointer operators.

src/HttpMsg.h
src/HttpReply.h
src/HttpRequest.h

index 36876db547fa1e85a29f238661b8b8716f3224b9..1da6b011185b93f176f480b7097cff9ecbe648da 100644 (file)
 
 // common parts of HttpRequest and HttpReply
 
+template <class Msg>
+class HttpMsgPointerT;
+
+
 class HttpMsg
 {
 
 public:
+    typedef HttpMsgPointerT<HttpMsg> Pointer;
+
     HttpMsg(http_hdr_owner_type owner);
     virtual ~HttpMsg();
 
@@ -186,6 +192,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 <typename Other>
+    HttpMsgPointerT(const HttpMsgPointerT<Other> &o): msg(o.raw()) { lock(); }
+
+    /// support assigning a child msg pointer to a parent msg pointer
+    template <typename Other>
+    HttpMsgPointerT &operator =(const HttpMsgPointerT<Other> &o)
+    { if (msg != o.raw()) { unlock(); msg = o.raw(); lock(); } return *this; }
 
     Msg &operator *() { return *msg; }
     const Msg &operator *() const { return *msg; }
@@ -195,6 +212,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
index 9bd8c46ec11a2cae40ceaf9518a63afbefe9ca56..33b471d4a98a20331ae3b6f5c9d0e238f1cc06aa 100644 (file)
@@ -52,6 +52,8 @@ class HttpReply: public HttpMsg
 {
 
 public:
+    typedef HttpMsgPointerT<HttpReply> Pointer;
+
     MEMPROXY_CLASS(HttpReply);
     HttpReply();
     ~HttpReply();
index 6857bcdf31d8e8318ad017977e6384f97301a70f..119d63c0521d3eb7a4aef8c1fafcee41744ed8fc 100644 (file)
@@ -65,6 +65,8 @@ class HttpRequest: public HttpMsg
 {
 
 public:
+    typedef HttpMsgPointerT<HttpRequest> Pointer;
+
     MEMPROXY_CLASS(HttpRequest);
     HttpRequest();
     HttpRequest(const HttpRequestMethod& aMethod, protocol_t aProtocol, const char *aUrlpath);