Source code of Windows XP (NT5)
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.

188 lines
3.6 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: bitflag.hxx
  7. //
  8. // Contents: Lightweight class for test/set/clear bit flags.
  9. //
  10. // Classes: CBitFlag
  11. //
  12. // History: 2-17-1997 DavidMun Created
  13. //
  14. //---------------------------------------------------------------------------
  15. #ifndef __BITFLAG_HXX_
  16. #define __BITFLAG_HXX_
  17. #define CBITFLAG_FLAGWORD DWORD
  18. //+--------------------------------------------------------------------------
  19. //
  20. // Class: CBitFlag
  21. //
  22. // Purpose: Lightweight class for test/set/clear bit flags.
  23. //
  24. // History: 2-17-1997 DavidMun Created
  25. //
  26. // Notes: Designed for use as a base class.
  27. //
  28. //---------------------------------------------------------------------------
  29. class CBitFlag
  30. {
  31. public:
  32. CBitFlag();
  33. protected:
  34. BOOL
  35. _IsFlagSet(
  36. CBITFLAG_FLAGWORD fl) const;
  37. VOID
  38. _SetFlag(
  39. CBITFLAG_FLAGWORD fl);
  40. VOID
  41. _ClearFlag(
  42. CBITFLAG_FLAGWORD fl);
  43. VOID
  44. _SetMask(
  45. CBITFLAG_FLAGWORD flSet,
  46. CBITFLAG_FLAGWORD flMask);
  47. CBITFLAG_FLAGWORD
  48. _QueryMask(
  49. CBITFLAG_FLAGWORD flMask);
  50. CBITFLAG_FLAGWORD _flFlags;
  51. };
  52. //+--------------------------------------------------------------------------
  53. //
  54. // Member: CBitFlag::CBitFlag
  55. //
  56. // Synopsis: ctor
  57. //
  58. // History: 2-17-1997 DavidMun Created
  59. //
  60. //---------------------------------------------------------------------------
  61. inline
  62. CBitFlag::CBitFlag():
  63. _flFlags(0)
  64. {
  65. }
  66. //+--------------------------------------------------------------------------
  67. //
  68. // Member: CBitFlag::_IsFlagSet
  69. //
  70. // Synopsis: Return TRUE if one or more bits in [fl] are set.
  71. //
  72. // History: 2-17-1997 DavidMun Created
  73. //
  74. //---------------------------------------------------------------------------
  75. inline BOOL
  76. CBitFlag::_IsFlagSet(
  77. CBITFLAG_FLAGWORD fl) const
  78. {
  79. return (_flFlags & fl) ? TRUE : FALSE;
  80. }
  81. //+--------------------------------------------------------------------------
  82. //
  83. // Member: CBitFlag::_SetFlag
  84. //
  85. // Synopsis: Turn on flag bit(s) [fl].
  86. //
  87. // History: 2-17-1997 DavidMun Created
  88. //
  89. //---------------------------------------------------------------------------
  90. inline VOID
  91. CBitFlag::_SetFlag(
  92. CBITFLAG_FLAGWORD fl)
  93. {
  94. _flFlags |= fl;
  95. }
  96. //+--------------------------------------------------------------------------
  97. //
  98. // Member: CBitFlag::_ClearFlag
  99. //
  100. // Synopsis: Clear flag bit(s) [fl].
  101. //
  102. // History: 2-17-1997 DavidMun Created
  103. //
  104. //---------------------------------------------------------------------------
  105. inline VOID
  106. CBitFlag::_ClearFlag(
  107. CBITFLAG_FLAGWORD fl)
  108. {
  109. _flFlags &= ~fl;
  110. }
  111. //+--------------------------------------------------------------------------
  112. //
  113. // Member: CBitFlag::_SetMask
  114. //
  115. // Synopsis: Set
  116. //
  117. // History: 12-04-1997 JonN Created
  118. //
  119. //---------------------------------------------------------------------------
  120. inline VOID
  121. CBitFlag::_SetMask(
  122. CBITFLAG_FLAGWORD flSet,
  123. CBITFLAG_FLAGWORD flMask)
  124. {
  125. _flFlags = (_flFlags & ~flMask) | flSet;
  126. }
  127. //+--------------------------------------------------------------------------
  128. //
  129. // Member: CBitFlag::_QueryMask
  130. //
  131. // Synopsis: Set
  132. //
  133. // History: 12-04-1997 JonN Created
  134. //
  135. //---------------------------------------------------------------------------
  136. inline CBITFLAG_FLAGWORD
  137. CBitFlag::_QueryMask(
  138. CBITFLAG_FLAGWORD flMask)
  139. {
  140. return (_flFlags & flMask);
  141. }
  142. #endif // __BITFLAG_HXX_