Use the Range<> template we have for generic ranges.
Move the Range.h template definitio to src/base/. It is only used by
code in src/.
Also, include a small performance improvements for StoreMeta::validLength().
Storing the valid TLV length limits in a static instead of generating a
new object instance on each call.
#ifndef SQUID_HTTPHEADERRANGE_H
#define SQUID_HTTPHEADERRANGE_H
+#include "base/Range.h"
#include "mem/forward.h"
-#include "Range.h"
#include "SquidString.h"
#include <vector>
#define SQUID_STORE_H
#include "base/Packable.h"
+#include "base/Range.h"
#include "base/RefCount.h"
#include "comm/forward.h"
#include "CommRead.h"
#include "http/RequestMethod.h"
#include "HttpReply.h"
#include "MemObject.h"
-#include "Range.h"
#include "RemovalPolicy.h"
#include "store/Controller.h"
#include "store/forward.h"
#ifndef SQUID_STOREIOBUFFER_H
#define SQUID_STOREIOBUFFER_H
+#include "base/Range.h"
#include "MemBuf.h"
-#include "Range.h"
class StoreIOBuffer
{
/* DEBUG: section 20 Storage Manager Swapfile Metadata */
#include "squid.h"
+#include "base/Range.h"
#include "MemObject.h"
#include "Store.h"
#include "StoreMeta.h"
return true;
}
-class IntRange
-{
-
-public:
- IntRange (int minimum, int maximum) : _min (minimum), _max (maximum) {
- if (_min > _max) {
- int temp = _min;
- _min = _max;
- _max = temp;
- }
- }
-
- bool includes (int anInt) const {
- if (anInt < _min || anInt > _max)
- return false;
-
- return true;
- }
-
-private:
- int _min;
- int _max;
-};
-
const int StoreMeta::MinimumTLVLength = 0;
const int StoreMeta::MaximumTLVLength = 1 << 16;
bool
StoreMeta::validLength(int aLength) const
{
- if (!IntRange (MinimumTLVLength, MaximumTLVLength).includes(aLength)) {
- debugs(20, DBG_CRITICAL, "storeSwapMetaUnpack: insane length (" << aLength << ")!");
+ static const Range<int> TlvValidLengths = Range<int>(StoreMeta::MinimumTLVLength, StoreMeta::MaximumTLVLength);
+ if (!TlvValidLengths.contains(aLength)) {
+ debugs(20, DBG_CRITICAL, MYNAME << ": insane length (" << aLength << ")!");
return false;
}
#define SQUID_ACLINTRANGE_H
#include "acl/Data.h"
-#include "Range.h"
+#include "base/Range.h"
#include <list>
LruMap.h \
Packable.h \
PackableStream.h \
+ Range.h \
RegexPattern.cc \
RegexPattern.h \
RunnersRegistry.cc \
C start;
C end;
Range intersection (Range const &) const;
+ bool contains(C const &) const;
S size() const;
};
return result;
}
+template<class C, class S>
+bool
+Range<C, S>::contains(C const &value) const {
+ assert(start <= end);
+ return (start <= value && value <= end);
+}
+
template<class C, class S>
S
Range<C, S>::size() const
#ifndef SQUID_MEM_NODE_H
#define SQUID_MEM_NODE_H
+#include "base/Range.h"
#include "defines.h"
#include "mem/forward.h"
-#include "Range.h"
#include "StoreIOBuffer.h"
class mem_node
#ifndef SQUID_SNMPX_PDU_H
#define SQUID_SNMPX_PDU_H
+#include "base/Range.h"
#include "ipc/forward.h"
-#include "Range.h"
#include "snmp.h"
namespace Snmp
#ifndef SQUID_SNMPX_VAR_H
#define SQUID_SNMPX_VAR_H
+#include "base/Range.h"
#include "ipc/forward.h"
-#include "Range.h"
#include "snmp_vars.h"
namespace Snmp
#ifndef SQUID_STMEM_H
#define SQUID_STMEM_H
-#include "Range.h"
+#include "base/Range.h"
#include "splay.h"
class mem_node;