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.

139 lines
4.1 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. RELATION.H
  5. Abstract:
  6. History:
  7. --*/
  8. #include <windows.h>
  9. typedef enum
  10. {
  11. VALUE_BOTH_FALSE = 0x1,
  12. VALUE_ONLY_FIRST = 0x2,
  13. VALUE_ONLY_SECOND = 0x4,
  14. VALUE_BOTH_TRUE = 0x8,
  15. } HMM_TWO_VALUES;
  16. class CTwoValues
  17. {
  18. public:
  19. inline static HMM_TWO_VALUES Combine(BOOL bFirst, BOOL bSecond)
  20. {
  21. return (HMM_TWO_VALUES)(1 <<
  22. ( (bFirst == TRUE) + (bSecond == TRUE) << 1 )
  23. );
  24. }
  25. };
  26. typedef enum
  27. {
  28. RELATION_NONE = VALUE_BOTH_FALSE+VALUE_ONLY_FIRST+VALUE_ONLY_SECOND+VALUE_BOTH_TRUE,
  29. RELATION_EQUIVALENT = VALUE_BOTH_TRUE + VALUE_BOTH_FALSE,
  30. RELATION_CONTRARY = VALUE_ONLY_FIRST + VALUE_ONLY_SECOND,
  31. RELATION_FIRST_IMPLIES = RELATION_NONE - VALUE_ONLY_FIRST,
  32. RELATION_SECOND_IMPLIES = RELATION_NONE - VALUE_ONLY_SECOND,
  33. RELATION_NOT_BOTH = RELATION_NONE - VALUE_BOTH_TRUE,
  34. RELATION_AT_LEAST_ONE = RELATION_NONE - VALUE_BOTH_FALSE,
  35. } HMM_RELATIONSHIP;
  36. typedef enum
  37. {
  38. VALUE_FALSE = FALSE,
  39. VALUE_TRUE = TRUE,
  40. VALUE_INDETERMINATE,
  41. } THREE_VALUED_BOOL;
  42. class CRelationship
  43. {
  44. public:
  45. inline static BOOL AdmitsValue(HMM_RELATIONSHIP Rel, HMM_TWO_VALUES Vals)
  46. {
  47. return (Rel & Vals);
  48. }
  49. inline static HMM_RELATIONSHIP ReverseRoles(HMM_RELATIONSHIP Rel)
  50. {
  51. if(AdmitsValue(Rel, VALUE_ONLY_FIRST))
  52. {
  53. if(!AdmitsValue(Rel, VALUE_ONLY_SECOND))
  54. return (HMM_RELATIONSHIP)
  55. (Rel - VALUE_ONLY_FIRST + VALUE_ONLY_SECOND);
  56. }
  57. else if(AdmitsValue(Rel, VALUE_ONLY_SECOND))
  58. {
  59. return (HMM_RELATIONSHIP)
  60. (Rel - VALUE_ONLY_SECOND + VALUE_ONLY_FIRST);
  61. }
  62. return Rel;
  63. }
  64. inline static THREE_VALUED_BOOL ComputeOr(HMM_RELATIONSHIP Rel)
  65. {
  66. if(Rel == VALUE_BOTH_FALSE)
  67. return VALUE_FALSE;
  68. else if(AdmitsValue(Rel, VALUE_BOTH_FALSE))
  69. return VALUE_INDETERMINATE;
  70. else
  71. return VALUE_TRUE;
  72. }
  73. inline static THREE_VALUED_BOOL ComputeAnd(HMM_RELATIONSHIP Rel)
  74. {
  75. if(Rel == VALUE_BOTH_TRUE)
  76. return VALUE_TRUE;
  77. else if(AdmitsValue(Rel, VALUE_BOTH_TRUE))
  78. return VALUE_INDETERMINATE;
  79. else
  80. return VALUE_FALSE;
  81. }
  82. static inline HMM_RELATIONSHIP GetRelationshipOfFirstWithANDofSeconds(
  83. int nNumSeconds, HMM_RELATIONSHIP* aSeconds)
  84. {
  85. BOOL bBothTrue = TRUE;
  86. BOOL bOnlyFirst = FALSE;
  87. BOOL bOnlySecond = TRUE;
  88. BOOL bBothFalse = FALSE;
  89. for(int i = 0; i < nNumSeconds; i++)
  90. {
  91. bBothTrue &= AdmitsValue(aSeconds[i], VALUE_BOTH_TRUE);
  92. bOnlyFirst |= AdmitsValue(aSeconds[i], VALUE_ONLY_FIRST);
  93. bOnlySecond &= AdmitsValue(aSeconds[i], VALUE_ONLY_SECOND);
  94. bBothFalse |= AdmitsValue(aSeconds[i], VALUE_BOTH_FALSE);
  95. }
  96. int nResult = 0;
  97. if(bBothTrue) nResult += VALUE_BOTH_TRUE;
  98. if(bOnlyFirst) nResult += VALUE_ONLY_FIRST;
  99. if(bOnlySecond) nResult += VALUE_ONLY_SECOND;
  100. if(bBothFalse) nResult += VALUE_BOTH_FALSE;
  101. return (HMM_RELATIONSHIP)nResult;
  102. }
  103. static inline HMM_RELATIONSHIP GetRelationshipOfFirstWithORofSeconds(
  104. int nNumSeconds, HMM_RELATIONSHIP* aSeconds)
  105. {
  106. BOOL bBothTrue = FALSE;
  107. BOOL bOnlyFirst = TRUE;
  108. BOOL bOnlySecond = FALSE;
  109. BOOL bBothFalse = TRUE;
  110. for(int i = 0; i < nNumSeconds; i++)
  111. {
  112. bBothTrue |= AdmitsValue(aSeconds[i], VALUE_BOTH_TRUE);
  113. bOnlyFirst &= AdmitsValue(aSeconds[i], VALUE_ONLY_FIRST);
  114. bOnlySecond |= AdmitsValue(aSeconds[i], VALUE_ONLY_SECOND);
  115. bBothFalse &= AdmitsValue(aSeconds[i], VALUE_BOTH_FALSE);
  116. }
  117. int nResult = 0;
  118. if(bBothTrue) nResult += VALUE_BOTH_TRUE;
  119. if(bOnlyFirst) nResult += VALUE_ONLY_FIRST;
  120. if(bOnlySecond) nResult += VALUE_ONLY_SECOND;
  121. if(bBothFalse) nResult += VALUE_BOTH_FALSE;
  122. return (HMM_RELATIONSHIP)nResult;
  123. }
  124. };