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.

96 lines
2.1 KiB

  1. /***************************************************************************\
  2. *
  3. * File: BitHelp.h
  4. *
  5. * Description:
  6. * BitHelp.h defines a collection of helpful bit-manipulation routines used
  7. * commonly throughout DirectUser.
  8. *
  9. *
  10. * History:
  11. * 11/26/1999: JStall: Created
  12. *
  13. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  14. *
  15. \***************************************************************************/
  16. #if !defined(BASE__BitHelp_h__INCLUDED)
  17. #define BASE__BitHelp_h__INCLUDED
  18. //------------------------------------------------------------------------------
  19. inline HWND
  20. ValidateHWnd(HWND hwnd)
  21. {
  22. if ((hwnd == NULL) || (!IsWindow(hwnd))) {
  23. return NULL;
  24. }
  25. return hwnd;
  26. }
  27. //------------------------------------------------------------------------------
  28. __forceinline bool
  29. TestFlag(UINT nValue, UINT nMask)
  30. {
  31. return (nValue & nMask) != 0;
  32. }
  33. //------------------------------------------------------------------------------
  34. __forceinline bool
  35. TestAllFlags(UINT nValue, UINT nMask)
  36. {
  37. return (nValue & nMask) == nMask;
  38. }
  39. //------------------------------------------------------------------------------
  40. __forceinline UINT
  41. SetFlag(UINT & nValue, UINT nMask)
  42. {
  43. nValue |= nMask;
  44. return nValue;
  45. }
  46. //------------------------------------------------------------------------------
  47. __forceinline UINT
  48. ClearFlag(UINT & nValue, UINT nMask)
  49. {
  50. nValue &= ~nMask;
  51. return nValue;
  52. }
  53. //------------------------------------------------------------------------------
  54. __forceinline UINT
  55. ChangeFlag(UINT & nValue, UINT nNewValue, UINT nMask)
  56. {
  57. nValue = (nNewValue & nMask) | (nValue & ~nMask);
  58. return nValue;
  59. }
  60. //------------------------------------------------------------------------------
  61. template <class T>
  62. void SafeAddRef(T * p)
  63. {
  64. if (p != NULL) {
  65. p->AddRef();
  66. }
  67. }
  68. //------------------------------------------------------------------------------
  69. template <class T>
  70. void SafeRelease(T * & p)
  71. {
  72. if (p != NULL) {
  73. p->Release();
  74. p = NULL;
  75. }
  76. }
  77. #endif // BASE__BitHelp_h__INCLUDED