]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: repalce several CbDataLIst uses with std::list
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 20 Nov 2014 09:34:09 +0000 (01:34 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 20 Nov 2014 09:34:09 +0000 (01:34 -0800)
Most of the uses of CbDataList appear to be abusing it for regular
list storage without any real need for CBDATA to be involved at all.

Also includes some documentation and syntax polishing cleanup.

src/Notes.h
src/acl/AtStepData.h
src/acl/HierCodeData.h
src/acl/IntRange.cc
src/acl/IntRange.h
src/acl/MethodData.cc
src/acl/MethodData.h
src/acl/ProtocolData.cc
src/acl/ProtocolData.h
src/auth/QueueNode.h

index 15cf288e7dcca68d7cafb394f0f991e482068f05..6f17e0f33402316c7e900fc096a8a015c256a346 100644 (file)
@@ -10,7 +10,6 @@
 #define SQUID_NOTES_H
 
 #include "acl/forward.h"
-#include "base/CbDataList.h"
 #include "base/RefCount.h"
 #include "format/Format.h"
 #include "MemPool.h"
index 459aa9e95217d81ed837f99b4ba73edde0b79537..bd735061f1fe0ee0439f70ce088fab1335268b35 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "base/CbDataList.h"
 #include "ssl/support.h"
 
 #include <list>
@@ -31,7 +30,7 @@ public:
     virtual SBufList dump() const;
     void parse();
     bool empty() const;
-    virtual  ACLAtStepData *clone() const;
+    virtual ACLAtStepData *clone() const;
 
     std::list<Ssl::BumpStep> values;
 };
index 5cf25ab253a3f90153846f651b75c0a79c3f3086..00d8d358d3da44cf4977079c6ddc7ee7269a92d2 100644 (file)
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "base/CbDataList.h"
 #include "hier_code.h"
 
-/// \ingroup ACLAPI
 class ACLHierCodeData : public ACLData<hier_code>
 {
     MEMPROXY_CLASS(ACLHierCodeData);
@@ -30,7 +28,7 @@ public:
     bool empty() const;
     virtual ACLData<hier_code> *clone() const;
 
-    // mask of codes this ACL might match.
+    /// mask of codes this ACL might match.
     bool values[HIER_MAX];
 };
 
index fb148298a05020d90cba201e9627918de1d52f17..d4dadff9e3d191ab589ee36969334a0bcff87bb4 100644 (file)
 #include "Debug.h"
 #include "Parsing.h"
 
-/* explicit instantiation required for some systems */
-/** \cond AUTODOCS_IGNORE */
-template cbdata_type CbDataList< Range<int> >::CBDATA_CbDataList;
-/** \endcond */
-
 void
 ACLIntRange::parse()
 {
@@ -41,9 +36,7 @@ ACLIntRange::parse()
             port2 = port1;
 
         if (port2 >= port1) {
-            RangeType temp (0,0);
-            temp.start = port1;
-            temp.end = port2+1;
+            RangeType temp(port1, port2+1);
             ranges.push_back(temp);
         } else {
             debugs(28, DBG_CRITICAL, "ACLIntRange::parse: Invalid port value");
@@ -61,12 +54,10 @@ ACLIntRange::empty() const
 bool
 ACLIntRange::match(int i)
 {
-    RangeType const toFind (i, i+1);
-    CbDataListIterator<RangeType> iter(ranges);
-
-    while (!iter.end()) {
-        const RangeType & element = iter.next();
-        RangeType result = element.intersection (toFind);
+    RangeType const toFind(i, i+1);
+    for (std::list<RangeType>::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) {
+        const RangeType & element = *iter;
+        RangeType result = element.intersection(toFind);
 
         if (result.size())
             return true;
@@ -81,7 +72,7 @@ ACLIntRange::clone() const
     if (!ranges.empty())
         fatal("ACLIntRange::clone: attempt to clone used ACL");
 
-    return new ACLIntRange (*this);
+    return new ACLIntRange(*this);
 }
 
 ACLIntRange::~ACLIntRange()
@@ -91,11 +82,9 @@ SBufList
 ACLIntRange::dump() const
 {
     SBufList sl;
-    CbDataListIterator<RangeType> iter(ranges);
-
-    while (!iter.end()) {
+    for (std::list<RangeType>::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) {
         SBuf sb;
-        const RangeType & element = iter.next();
+        const RangeType & element = *iter;
 
         if (element.size() == 1)
             sb.Printf("%d", element.start);
@@ -107,4 +96,3 @@ ACLIntRange::dump() const
 
     return sl;
 }
-
index df9605a116d4d7de2b7685f8da5261cd7203efee..bca4acffac4f7f54e6edce3086f5a748e1d9ba49 100644 (file)
 #define SQUID_ACLINTRANGE_H
 
 #include "acl/Data.h"
-#include "base/CbDataList.h"
 #include "Range.h"
 
-/// \ingroup ACLAPI
+#include <list>
+
 class ACLIntRange : public ACLData<int>
 {
 
 public:
-    ACLIntRange() {};
+    ACLIntRange() {}
 
     virtual ~ACLIntRange();
     virtual bool match(int);
@@ -29,7 +29,7 @@ public:
 
 private:
     typedef Range<int> RangeType;
-    CbDataListContainer <RangeType> ranges;
+    std::list<RangeType> ranges;
 };
 
 #endif /* SQUID_ACLINTRANGE_H */
index 16cd9c8757fe97fa86ae7a305fe2fce135eaa0a8..17086a08bcc1bd680dec612c807c646791ec363a 100644 (file)
 
 int ACLMethodData::ThePurgeCount = 0;
 
-ACLMethodData::ACLMethodData() : values (NULL)
-{}
-
-ACLMethodData::ACLMethodData(ACLMethodData const &old) : values (NULL)
+ACLMethodData::ACLMethodData(ACLMethodData const &old)
 {
-    assert (!old.values);
+    assert(old.values.empty());
 }
 
 ACLMethodData::~ACLMethodData()
 {
-    if (values)
-        delete values;
+    values.clear();
 }
 
-/// todo make this a pass-by-reference now that HTTPRequestMethods a full class?
 bool
 ACLMethodData::match(HttpRequestMethod toFind)
 {
-    return values->findAndTune(toFind);
+    for (std::list<HttpRequestMethod>::const_iterator i = values.begin(); i != values.end(); ++i) {
+        if (*i == toFind) {
+            // tune the list for LRU ordering
+            values.erase(i);
+            values.push_front(toFind);
+            return true;
+        }
+    }
+    return false;
 }
 
-/* explicit instantiation required for some systems */
-
-/// \cond AUTODOCS_IGNORE
-template cbdata_type CbDataList<HttpRequestMethod>::CBDATA_CbDataList;
-/// \endcond
-
 SBufList
 ACLMethodData::dump() const
 {
     SBufList sl;
-    CbDataList<HttpRequestMethod> *data = values;
-
-    while (data != NULL) {
-        sl.push_back(data->element.image());
-        data = data->next;
+    for (std::list<HttpRequestMethod>::const_iterator i = values.begin(); i != values.end(); ++i) {
+        sl.push_back((*i).image());
     }
 
     return sl;
@@ -60,30 +54,18 @@ ACLMethodData::dump() const
 void
 ACLMethodData::parse()
 {
-    CbDataList<HttpRequestMethod> **Tail;
-    char *t = NULL;
-
-    for (Tail = &values; *Tail; Tail = &((*Tail)->next));
-    while ((t = strtokFile())) {
+    while (char *t = strtokFile()) {
         HttpRequestMethod m;
         m.HttpRequestMethodXXX(t);
-        CbDataList<HttpRequestMethod> *q = new CbDataList<HttpRequestMethod>(m);
-        if (q->element == Http::METHOD_PURGE)
+        values.push_back(m);
+        if (values.back() == Http::METHOD_PURGE)
             ++ThePurgeCount; // configuration code wants to know
-        *(Tail) = q;
-        Tail = &q->next;
     }
 }
 
-bool
-ACLMethodData::empty() const
-{
-    return values == NULL;
-}
-
 ACLData<HttpRequestMethod> *
 ACLMethodData::clone() const
 {
-    assert (!values);
+    assert(values.empty());
     return new ACLMethodData(*this);
 }
index a3c02dcafb6fe53884e017106a1a2fc9e62503b6..bca112e91861d240ce611417e49ad69ae94b83d0 100644 (file)
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "base/CbDataList.h"
 #include "http/RequestMethod.h"
 
+#include <list>
+
 class ACLMethodData : public ACLData<HttpRequestMethod>
 {
     MEMPROXY_CLASS(ACLMethodData);
 
 public:
-    ACLMethodData();
+    ACLMethodData() {}
     ACLMethodData(ACLMethodData const &);
     ACLMethodData &operator= (ACLMethodData const &);
     virtual ~ACLMethodData();
     bool match(HttpRequestMethod);
     virtual SBufList dump() const;
     void parse();
-    bool empty() const;
+    bool empty() const {return values.empty();}
     virtual ACLData<HttpRequestMethod> *clone() const;
 
-    CbDataList<HttpRequestMethod> *values;
+    std::list<HttpRequestMethod> values;
 
     static int ThePurgeCount; ///< PURGE methods seen by parse()
 };
index 388b2c102ef2456210004950735b342af5bb75fb..6f8080e36a49412c0ca01710b0d4a685967b5d0c 100644 (file)
 #include "Debug.h"
 #include "wordlist.h"
 
-ACLProtocolData::ACLProtocolData() : values (NULL)
-{}
-
-ACLProtocolData::ACLProtocolData(ACLProtocolData const &old) : values (NULL)
+ACLProtocolData::ACLProtocolData(ACLProtocolData const &old)
 {
-    assert (!old.values);
+    assert(old.values.empty());
 }
 
 ACLProtocolData::~ACLProtocolData()
 {
-    if (values)
-        delete values;
+    values.clear();
 }
 
 bool
 ACLProtocolData::match(AnyP::ProtocolType toFind)
 {
-    return values->findAndTune (toFind);
+    for (std::list<AnyP::ProtocolType>::const_iterator itr = values.begin(); itr != values.end(); ++itr) {
+        if (*itr == toFind) {
+            // tune the list for LRU ordering
+            values.erase(itr);
+            values.push_front(toFind);
+            return true;
+        }
+    }
+    return false;
 }
 
-/* explicit instantiation required for some systems */
-
-/// \cond AUTODOCS_IGNORE
-template cbdata_type CbDataList<AnyP::ProtocolType>::CBDATA_CbDataList;
-/// \endcond
-
 SBufList
 ACLProtocolData::dump() const
 {
     SBufList sl;
-    CbDataList<AnyP::ProtocolType> *data = values;
-
-    while (data != NULL) {
-        sl.push_back(SBuf(AnyP::ProtocolType_str[data->element]));
-        data = data->next;
+    for (std::list<AnyP::ProtocolType>::const_iterator itr = values.begin(); itr != values.end(); ++itr) {
+        sl.push_back(SBuf(AnyP::ProtocolType_str[*itr]));
     }
 
     return sl;
@@ -58,17 +53,11 @@ ACLProtocolData::dump() const
 void
 ACLProtocolData::parse()
 {
-    CbDataList<AnyP::ProtocolType> **Tail;
-    char *t = NULL;
-
-    for (Tail = &values; *Tail; Tail = &((*Tail)->next));
-    while ((t = strtokFile())) {
+    while (char *t = strtokFile()) {
         int p = AnyP::PROTO_NONE;
         for (; p < AnyP::PROTO_UNKNOWN; ++p) {
             if (strcasecmp(t, AnyP::ProtocolType_str[p]) == 0) {
-                CbDataList<AnyP::ProtocolType> *q = new CbDataList<AnyP::ProtocolType>(static_cast<AnyP::ProtocolType>(p));
-                *(Tail) = q;
-                Tail = &q->next;
+                values.push_back(static_cast<AnyP::ProtocolType>(p));
                 break;
             }
         }
@@ -79,16 +68,10 @@ ACLProtocolData::parse()
     }
 }
 
-bool
-ACLProtocolData::empty() const
-{
-    return values == NULL;
-}
-
 ACLData<AnyP::ProtocolType> *
 ACLProtocolData::clone() const
 {
     /* Splay trees don't clone yet. */
-    assert (!values);
+    assert(values.empty());
     return new ACLProtocolData(*this);
 }
index 05d054cf6e169479d7dc7cec86c57baebe822917..90f263940309acee4e6f5e053e50a19575d2abcf 100644 (file)
 #include "acl/Acl.h"
 #include "acl/Data.h"
 #include "anyp/ProtocolType.h"
-#include "base/CbDataList.h"
+
+#include <list>
 
 class ACLProtocolData : public ACLData<AnyP::ProtocolType>
 {
     MEMPROXY_CLASS(ACLProtocolData);
 
 public:
-    ACLProtocolData();
+    ACLProtocolData() {}
     ACLProtocolData(ACLProtocolData const &);
     ACLProtocolData &operator= (ACLProtocolData const &);
     virtual ~ACLProtocolData();
     bool match(AnyP::ProtocolType);
     virtual SBufList dump() const;
     void parse();
-    bool empty() const;
+    bool empty() const {return values.empty();}
     virtual ACLData<AnyP::ProtocolType> *clone() const;
 
-    CbDataList<AnyP::ProtocolType> *values;
+    std::list<AnyP::ProtocolType> values;
 };
 
 #endif /* SQUID_ACLPROTOCOLDATA_H */
index 5854b120b33ac52dfe6d6a8fdae1361051e1fbd6..1f52e0545da643209186e52c2c4642e56b43a045 100644 (file)
@@ -9,6 +9,8 @@
 #ifndef SQUID_SRC_AUTH_QUEUENODE_H
 #define SQUID_SRC_AUTH_QUEUENODE_H
 
+#include "cbdata.h"
+
 namespace Auth
 {