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.

114 lines
2.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: bitoff.hxx
  7. //
  8. // Contents: Index Bit Offset
  9. //
  10. // Classes: CBitOffset
  11. //
  12. // History: 10-Nov-91 BartoszM Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #define ULONG_BITS (sizeof(ULONG)*8)
  17. #define INVALID_PAGENUM 0xFFFFFFFF
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Class: BitOffset
  21. //
  22. // Purpose: BitOffset into index
  23. //
  24. // Interface:
  25. //
  26. // History: 13-Jun-91 BartoszM Created
  27. //
  28. //----------------------------------------------------------------------------
  29. struct BitOffset
  30. {
  31. BitOffset( BitOffset & bo ) : page( bo.page ), off( bo.off ) {}
  32. BitOffset() : page( 0 ), off( 0 ) {}
  33. ULONG Page() const {
  34. return(page);
  35. }
  36. ULONG Offset() const {
  37. return(off);
  38. }
  39. void SetPage(ULONG p) {
  40. page = p;
  41. }
  42. void SetOff(ULONG offset) {
  43. off = offset;
  44. }
  45. void SetInvalid() {
  46. page = INVALID_PAGENUM;
  47. }
  48. BOOL Valid() const {
  49. return( INVALID_PAGENUM != page );
  50. }
  51. void Init( ULONG pageNum, ULONG bitPos )
  52. {
  53. if (bitPos < SMARTBUF_PAGE_SIZE_IN_BITS )
  54. {
  55. SetPage(pageNum);
  56. SetOff(bitPos);
  57. }
  58. else
  59. {
  60. Win4Assert ( bitPos == SMARTBUF_PAGE_SIZE_IN_BITS );
  61. SetPage(pageNum + 1);
  62. SetOff(0);
  63. }
  64. }
  65. void operator +=( unsigned offDelta )
  66. {
  67. off += offDelta;
  68. while (off >= SMARTBUF_PAGE_SIZE_IN_BITS)
  69. {
  70. off -= SMARTBUF_PAGE_SIZE_IN_BITS;
  71. page++;
  72. }
  73. }
  74. ULONG Delta ( const BitOffset& bitoff ) const
  75. {
  76. return( (page - bitoff.page) * SMARTBUF_PAGE_SIZE_IN_BITS
  77. + off - bitoff.off);
  78. }
  79. BOOL operator > ( const BitOffset & bitoff ) const
  80. {
  81. if ( page > bitoff.page )
  82. {
  83. return TRUE;
  84. }
  85. else if ( ( page == bitoff.page ) &&
  86. ( off > bitoff.off )
  87. )
  88. {
  89. return TRUE;
  90. }
  91. return FALSE;
  92. }
  93. #ifdef CIEXTMODE
  94. void CiExtDump(void *ciExtSelf);
  95. #endif
  96. private:
  97. ULONG page; // page number
  98. ULONG off; // bit offset within page
  99. };