]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Code cleanup: Implement proper copy-constructor for HttpHeader. Polished.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 18 Feb 2011 05:05:28 +0000 (22:05 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 18 Feb 2011 05:05:28 +0000 (22:05 -0700)
Besides being the Right Thing, this helps classes that have HttpHeader data
members to avoid defining explicit copy constructors.

Also fixed blindly copied assignment operator profile and polished another
constructor to prevent implicit integer-to-HttpHeader conversion.

src/HttpHeader.cc
src/HttpHeader.h

index 89f30209957eb9a8d4a076cdc1d9842cc13f11a7..8627fb064d5e30c3769336de3ea281c8f033086c 100644 (file)
@@ -383,19 +383,25 @@ HttpHeader::HttpHeader() : owner (hoNone), len (0)
     httpHeaderMaskInit(&mask, 0);
 }
 
-HttpHeader::HttpHeader(http_hdr_owner_type const &anOwner) : owner (anOwner), len (0)
+HttpHeader::HttpHeader(const http_hdr_owner_type anOwner): owner(anOwner), len(0)
 {
     assert(anOwner > hoNone && anOwner <= hoReply);
     debugs(55, 7, "init-ing hdr: " << this << " owner: " << owner);
     httpHeaderMaskInit(&mask, 0);
 }
 
+HttpHeader::HttpHeader(const HttpHeader &other): owner(other.owner), len(other.len)
+{
+    httpHeaderMaskInit(&mask, 0);
+    update(&other, NULL); // will update the mask as well
+}
+
 HttpHeader::~HttpHeader()
 {
     clean();
 }
 
-const HttpHeader &
+HttpHeader &
 HttpHeader::operator =(const HttpHeader &other)
 {
     if (this != &other) {
index b35ab62147ae8012d95e65cfd355d66c36c39779..a9cf983be19e379e3873674582db4a27d6a55e3f 100644 (file)
@@ -205,10 +205,11 @@ class HttpHeader
 
 public:
     HttpHeader();
-    HttpHeader(http_hdr_owner_type const &owner);
+    explicit HttpHeader(const http_hdr_owner_type owner);
+    HttpHeader(const HttpHeader &other);
     ~HttpHeader();
 
-    const HttpHeader &operator =(const HttpHeader &other);
+    HttpHeader &operator =(const HttpHeader &other);
 
     /* Interface functions */
     void clean();
@@ -274,8 +275,6 @@ protected:
 
 private:
     HttpHeaderEntry *findLastEntry(http_hdr_type id) const;
-    /// Made it non-copyable. Our destructor is a bit nasty...
-    HttpHeader(const HttpHeader &);
 };