From: Christos Tsantilas Date: Tue, 1 Feb 2011 08:49:56 +0000 (+0200) Subject: Range::size() returned value type X-Git-Tag: take03^2~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c16f948beb714eb74a2650e6b45573b3fa35ba6f;p=thirdparty%2Fsquid.git Range::size() returned value type 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. --- diff --git a/include/Range.h b/include/Range.h index 7229729677..a77147513a 100644 --- a/include/Range.h +++ b/include/Range.h @@ -42,7 +42,7 @@ /* represents [start, end) */ -template +template class Range { @@ -52,35 +52,35 @@ public: C start; C end; Range intersection (Range const &) const; - C size() const; + S size() const; }; -template -std::ostream& operator << (std::ostream &os, Range const &aRange) +template +std::ostream& operator << (std::ostream &os, Range const &aRange) { os << "[" << aRange.start << "," << aRange.end << ")"; return os; } -template -Range::Range () : start(), end() {} +template +Range::Range () : start(), end() {} -template -Range::Range (C start_, C end_) : start(start_), end(end_) {} +template +Range::Range (C start_, C end_) : start(start_), end(end_) {} -template -Range -Range::intersection (Range const &rhs) const +template +Range +Range::intersection (Range const &rhs) const { - Range result (max(start, rhs.start), min(end, rhs.end)); + Range result (max(start, rhs.start), min(end, rhs.end)); return result; } -template -C -Range::size() const +template +S +Range::size() const { - return end > start ? end - start : 0; + return (S) (end > start ? end - start : 0); } #endif /* SQUID_RANGE_H */ diff --git a/src/HttpHeaderRange.h b/src/HttpHeaderRange.h index 6c37749381..e9b79d8801 100644 --- a/src/HttpHeaderRange.h +++ b/src/HttpHeaderRange.h @@ -48,7 +48,7 @@ class HttpHdrRangeSpec public: MEMPROXY_CLASS(HttpHdrRangeSpec); - typedef Range HttpRange; + typedef Range HttpRange; static int64_t const UnknownPosition; HttpHdrRangeSpec(); diff --git a/src/client_side.cc b/src/client_side.cc index f2d90a2609..65a9563b9c 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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; diff --git a/src/client_side.h b/src/client_side.h index cbacbe26f7..ab7b6c3cec 100644 --- a/src/client_side.h +++ b/src/client_side.h @@ -50,9 +50,6 @@ class clientStreamNode; class ChunkedCodingParser; class HttpParser; -template -class Range; - class ClientSocketContext : public RefCountable {