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.

100 lines
3.5 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: bitmap.h
  5. //
  6. // Description: Contains bitmap manipulation utilities
  7. //
  8. // Author: mikeswa
  9. //
  10. // Copyright (C) 1997 Microsoft Corporation
  11. //
  12. //-----------------------------------------------------------------------------
  13. #ifndef __bitmap_h__
  14. #define __bitmap_h__
  15. #include "cmt.h"
  16. //---[ CMsgBitMap ]------------------------------------------------------------
  17. //
  18. //
  19. // Hungarian: mbmap, pmbmap
  20. //
  21. // Provides a wrapper around the bitmaps used to indicate per recipient responsibility
  22. // and statistics.
  23. //
  24. // Number of recipients is not stored with bitmaps, since there will be many bitmaps
  25. // per message. This can reduce memory usage nearly by half (in the case of < 32 recips).
  26. //-----------------------------------------------------------------------------
  27. class CMsgBitMap
  28. {
  29. private:
  30. DWORD m_rgdwBitMap[1]; //if there are MORE than 32 recipients
  31. //private helper functions
  32. DWORD dwIndexToBitMap(DWORD dwIndex);
  33. static inline DWORD cGetNumDWORDS(DWORD cBits)
  34. {return((cBits + 31)/32);};
  35. public:
  36. //overide new operator to allow for variable sized bitmaps
  37. void * operator new(size_t stIgnored, unsigned int cBits);
  38. void operator delete(void *pMem, size_t cBits) {::delete pMem;};
  39. CMsgBitMap(DWORD cBits); //only zeros memory... can be done externally when there
  40. //is a large array of bitmaps.
  41. //return the actual size of the bitmap with a given # of recips
  42. static inline size_t size(DWORD cBits)
  43. {return (cGetNumDWORDS(cBits)*sizeof(DWORD));};
  44. //Simple logic checking for bitmaps
  45. BOOL FAllClear(IN DWORD cBits);
  46. BOOL FAllSet(IN DWORD cBits);
  47. //Test against a single other bit
  48. BOOL FTest(IN DWORD cBits, IN CMsgBitMap *pmbmap);
  49. //Interlocked Test and set functionality
  50. BOOL FTestAndSet(IN DWORD cBits, IN CMsgBitMap *pmbmap);
  51. //Set/Clear the bit corresponding to a given index on the bitmap
  52. HRESULT HrMarkBits(IN DWORD cBits,
  53. IN DWORD cIndexes, //# of indexes in array
  54. IN DWORD *rgiBits, //array of indexes to mark
  55. IN BOOL fSet); //TRUE => set to 1, 0 otherwise
  56. //Generate a list of indexes represented by the bitmap
  57. HRESULT HrGetIndexes(IN DWORD cBits,
  58. OUT DWORD *pcIndexes, //# of indexes returned
  59. OUT DWORD **prgdwIndexes); //array of indexes
  60. //Set self to logical OR of group
  61. HRESULT HrGroupOr(IN DWORD cBits,
  62. IN DWORD cBitMaps, //# of bitmaps passed in
  63. IN CMsgBitMap **rgpBitMaps); //array of bitmap ptrs
  64. //If the description of the following is not immediately clear, I have
  65. //included a truth table with the implementation
  66. //Filter self against other bitmap-only keep bits set if NOT set in other
  67. HRESULT HrFilter(IN DWORD cBits,
  68. IN CMsgBitMap *pmbmap); //bitmap to filter against
  69. //Filters and sets filtered bits to 1 in other bitmap
  70. HRESULT HrFilterSet(IN DWORD cBits,
  71. IN CMsgBitMap *pmbmap); //bitmap to filter and set
  72. //Sets bits that are 1 in self to 0 in other. Checks to make sure that
  73. //self is a subset of setbits to other
  74. HRESULT HrFilterUnset(IN DWORD cBits,
  75. IN CMsgBitMap *pmbmap); //bitmap to unset
  76. };
  77. #endif //__bitmap_h__