DDRange.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * DDRange is the functional equivalent of a 64 bit NSRange.
  3. * The HTTP Server is designed to support very large files.
  4. * On 32 bit architectures (ppc, i386) NSRange uses unsigned 32 bit integers.
  5. * This only supports a range of up to 4 gigabytes.
  6. * By defining our own variant, we can support a range up to 16 exabytes.
  7. *
  8. * All effort is given such that DDRange functions EXACTLY the same as NSRange.
  9. **/
  10. #import <Foundation/NSValue.h>
  11. #import <Foundation/NSObjCRuntime.h>
  12. @class NSString;
  13. typedef struct _DDRange {
  14. UInt64 location;
  15. UInt64 length;
  16. } DDRange;
  17. typedef DDRange *DDRangePointer;
  18. NS_INLINE DDRange DDMakeRange(UInt64 loc, UInt64 len) {
  19. DDRange r;
  20. r.location = loc;
  21. r.length = len;
  22. return r;
  23. }
  24. NS_INLINE UInt64 DDMaxRange(DDRange range) {
  25. return (range.location + range.length);
  26. }
  27. NS_INLINE BOOL DDLocationInRange(UInt64 loc, DDRange range) {
  28. return (loc - range.location < range.length);
  29. }
  30. NS_INLINE BOOL DDEqualRanges(DDRange range1, DDRange range2) {
  31. return ((range1.location == range2.location) && (range1.length == range2.length));
  32. }
  33. FOUNDATION_EXPORT DDRange DDUnionRange(DDRange range1, DDRange range2);
  34. FOUNDATION_EXPORT DDRange DDIntersectionRange(DDRange range1, DDRange range2);
  35. FOUNDATION_EXPORT NSString *DDStringFromRange(DDRange range);
  36. FOUNDATION_EXPORT DDRange DDRangeFromString(NSString *aString);
  37. NSInteger DDRangeCompare(DDRangePointer pDDRange1, DDRangePointer pDDRange2);
  38. @interface NSValue (NSValueDDRangeExtensions)
  39. + (NSValue *)valueWithDDRange:(DDRange)range;
  40. - (DDRange)ddrangeValue;
  41. - (NSInteger)ddrangeCompare:(NSValue *)ddrangeValue;
  42. @end