]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Range::size() returned value type
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Tue, 1 Feb 2011 08:49:56 +0000 (10:49 +0200)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Tue, 1 Feb 2011 08:49:56 +0000 (10:49 +0200)
This patch allow the user of the Range template class to define the type of
the returned value of Range::size() method, adding a second template argument.
The default type of the return value of Range::size() method is size_t, which
in most cases is enough (but not always, eg  HttpRange).
This patch will allow Range template to be used with non numeric types.

include/Range.h
src/HttpHeaderRange.h
src/client_side.cc
src/client_side.h

index 7229729677d28c7d36b765bc29f934a65f99ce12..a77147513a54a587c02241f98e261475604c8477 100644 (file)
@@ -42,7 +42,7 @@
 
 /* represents [start, end) */
 
-template <class C>
+template <class C, class S = size_t>
 class Range
 {
 
@@ -52,35 +52,35 @@ public:
     C start;
     C end;
     Range intersection (Range const &) const;
-    C size() const;
+    S size() const;
 };
 
-template <class C>
-std::ostream& operator << (std::ostream &os, Range<C> const &aRange)
+template <class C, class S>
+std::ostream& operator << (std::ostream &os, Range<C, S> const &aRange)
 {
     os << "[" << aRange.start << "," << aRange.end << ")";
     return os;
 }
 
-template<class C>
-Range<C>::Range () : start(), end() {}
+template<class C, class S>
+Range<C, S>::Range () : start(), end() {}
 
-template<class C>
-Range<C>::Range (C start_, C end_) : start(start_), end(end_) {}
+template<class C, class S>
+Range<C, S>::Range (C start_, C end_) : start(start_), end(end_) {}
 
-template<class C>
-Range<C>
-Range<C>::intersection (Range const &rhs) const
+template<class C, class S>
+Range<C, S>
+Range<C, S>::intersection (Range const &rhs) const
 {
-    Range<C> result (max(start, rhs.start), min(end, rhs.end));
+    Range<C, S> result (max(start, rhs.start), min(end, rhs.end));
     return result;
 }
 
-template<class C>
-C
-Range<C>::size() const
+template<class C, class S>
+S
+Range<C, S>::size() const
 {
-    return end > start ? end - start : 0;
+    return (S) (end > start ? end - start : 0);
 }
 
 #endif /* SQUID_RANGE_H */
index 6c377493817d8503ded8fcb20af5d34622a315ec..e9b79d880160a458c78e17271a5fd5897aa27ad8 100644 (file)
@@ -48,7 +48,7 @@ class HttpHdrRangeSpec
 
 public:
     MEMPROXY_CLASS(HttpHdrRangeSpec);
-    typedef Range<int64_t> HttpRange;
+    typedef Range<int64_t, uint64_t> HttpRange;
     static int64_t const UnknownPosition;
 
     HttpHdrRangeSpec();
index f2d90a260966c86801928b51f1f5407ad8159133..65a9563b9c643df7aa7748165cffcdd61711fee1 100644 (file)
@@ -1055,7 +1055,7 @@ ClientSocketContext::packRange(StoreIOBuffer const &source, MemBuf * mb)
              * intersection of "have" and "need" ranges must not be empty
              */
             assert(http->out.offset < i->currentSpec()->offset + i->currentSpec()->length);
-            assert(http->out.offset + available.size() > i->currentSpec()->offset);
+            assert(http->out.offset + available.size() > (uint64_t)i->currentSpec()->offset);
 
             /*
              * put boundary and headers at the beginning of a range in a
@@ -1113,7 +1113,7 @@ ClientSocketContext::packRange(StoreIOBuffer const &source, MemBuf * mb)
         /* adjust for not to be transmitted bytes */
         http->out.offset = nextOffset;
 
-        if (available.size() <= skip)
+        if (available.size() <= (uint64_t)skip)
             return;
 
         available.start += skip;
index cbacbe26f7f470c229db79eb082a4c3968d00487..ab7b6c3cec0164be8e18b35650d0e9c3e564ed16 100644 (file)
@@ -50,9 +50,6 @@ class clientStreamNode;
 class ChunkedCodingParser;
 class HttpParser;
 
-template <class T>
-class Range;
-
 class ClientSocketContext : public RefCountable
 {