Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.9 KiB

  1. //
  2. // RANGE.H
  3. //
  4. // 2-20-96: (EricAn)
  5. // Hacked from the Route66 source tree, eliminated stuff we don't use.
  6. // Original copyright below - where did this thing come from?
  7. // 8-96: Functions added to facilitate finding of "anti" lists
  8. //
  9. // -*- C -*-
  10. //--------------------------------------------------------------------------------------
  11. //
  12. // Module: range.h
  13. //
  14. // Description: Definition of a class to manipulate range lists
  15. // (e.g. 1-6,7,10-11,19,24,33-40 ...)
  16. //
  17. // Copyright Microsoft Corporation 1995, All Rights Reserved
  18. //
  19. //--------------------------------------------------------------------------------------
  20. #ifndef _RANGE_H
  21. #define _RANGE_H
  22. //
  23. // Copyright 1992 Software Innovations, Inc
  24. // All Rights Reserved
  25. //
  26. // $Source: D:\CLASS\INCLUDE\range.h-v $
  27. // $Author: martin $
  28. // $Date: 92/07/15 04:56:38 $
  29. // $Revision: 1.1 $
  30. //
  31. #define RANGE_ERROR ((ULONG)-1)
  32. #define rlLAST_MESSAGE ((ULONG)-2)
  33. // a CRangeList is a dynamic array of these...
  34. typedef struct {
  35. ULONG low;
  36. ULONG high;
  37. } RangeType;
  38. class CRangeList
  39. {
  40. public:
  41. CRangeList();
  42. //CRangeList(CRangeList&);
  43. ~CRangeList();
  44. ULONG AddRef(void);
  45. ULONG Release(void);
  46. void Clear() { m_numRanges = 0; };
  47. BOOL IsInRange(const ULONG value) const; // is `value' in one of the ranges
  48. // in this CRangeList?
  49. ULONG Min(void) const; // return the minimum in-range value
  50. ULONG Max(void) const; // return the maximum in-range value
  51. BOOL Save(LPBYTE *const, ULONG *const) const;
  52. BOOL Load(const LPBYTE, const ULONG);
  53. // void AddRange(const char *);
  54. // a string in the form "low-high,..."
  55. // or just "value,..."
  56. BOOL AddRange(const ULONG low, const ULONG high);
  57. BOOL AddRange(const ULONG value);
  58. BOOL AddRange(const RangeType);
  59. BOOL AddRange(RangeType*, int);
  60. BOOL AddRange(CRangeList&);
  61. // void DeleteRange(const char *);
  62. // (same form as for AddRange(char *)
  63. BOOL DeleteRange(const ULONG low, const ULONG high);
  64. BOOL DeleteRange(const ULONG value);
  65. BOOL DeleteRange(const RangeType);
  66. BOOL DeleteRange(CRangeList&);
  67. // finds the range "value" is in and returns the min/max of that
  68. ULONG MinOfRange(const ULONG value) const;
  69. ULONG MaxOfRange(const ULONG value) const;
  70. // computes a range of values not in the RangeList
  71. BOOL HighestAntiRange(RangeType *const rt) const;
  72. BOOL LowestAntiRange(RangeType *const rt) const;
  73. // finds the range containing "value" and computes the next range of missing values
  74. BOOL NextHigherAntiRange(const ULONG value, RangeType *const rt) const;
  75. BOOL NextLowerAntiRange(const ULONG value, RangeType *const rt) const;
  76. #ifdef DEBUG
  77. LPTSTR RangeToString(); // return a string representing the rangelist
  78. void DebugOutput(LPTSTR);
  79. #endif
  80. // next() returns the smallest in-range value greater than `current', or -1
  81. ULONG Next(const ULONG current) const;
  82. // prev() returns the largest in-range value less than `current', or -1
  83. ULONG Prev(const ULONG current) const;
  84. ULONG Cardinality(void) const; // return the cardinality of the set of
  85. // in-range values
  86. private:
  87. BOOL Expand();
  88. int BinarySearch(const ULONG value) const;
  89. void ShiftLeft(int low, int distance);
  90. void ShiftRight(int low, int distance);
  91. void SubsumeDown(int&);
  92. void SubsumeUpwards(const int);
  93. protected:
  94. ULONG m_cRef; // Ref count
  95. int m_numRanges; // number of ranges in the rangeTable
  96. int m_rangeTableSize; // range table has room for this many ranges
  97. RangeType *m_rangeTable; // the array of ranges
  98. };
  99. #endif // _RANGE_H