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.

212 lines
5.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: enforcer.hxx
  7. //
  8. // Contents: Constraint enforcer for IWordSink methods
  9. //
  10. // History: 24-Apr-95 SitaramR Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #pragma once
  14. enum StateOfEnforcer
  15. {
  16. stateStart, // start state
  17. stateError, // error state
  18. statePAW, // PutAltWord state
  19. stateSAP, // StartAltPhrase state
  20. stateEAP, // EndAltPhrase state
  21. };
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Class: CAltWordsEnforcer
  25. //
  26. // Purpose: Constraint enforcer for PutAltWord and PutWord methods
  27. //
  28. // History: 25-Apr-95 SitaramR Created.
  29. //
  30. //----------------------------------------------------------------------------
  31. class CAltWordsEnforcer
  32. {
  33. public:
  34. CAltWordsEnforcer() { _state = stateStart; }
  35. ~CAltWordsEnforcer() { }
  36. BOOL IsPutWordOk();
  37. BOOL IsPutAltWordOk();
  38. BOOL IsStartAltPhraseOk();
  39. BOOL IsEndAltPhraseOk();
  40. private:
  41. StateOfEnforcer _state;
  42. };
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Class: CAltPhrasesEnforcer
  46. //
  47. // Purpose: Constraint enforcer for StartAltPhrase and EndAltPhrase methods
  48. //
  49. // History: 25-Apr-95 SitaramR Created.
  50. //
  51. //----------------------------------------------------------------------------
  52. class CAltPhrasesEnforcer
  53. {
  54. public:
  55. CAltPhrasesEnforcer() { _state = stateStart; }
  56. ~CAltPhrasesEnforcer() { }
  57. BOOL IsStartAltPhraseOk();
  58. BOOL IsEndAltPhraseOk();
  59. private:
  60. StateOfEnforcer _state;
  61. };
  62. //+---------------------------------------------------------------------------
  63. //
  64. // Member: CAltWordsEnforcer::IsPutWordOk
  65. //
  66. // Synopsis: Is the PutWord method call allowed in the current state ?
  67. //
  68. // History: 24-Apr-1995 SitaramR Created
  69. //
  70. //----------------------------------------------------------------------------
  71. inline BOOL CAltWordsEnforcer::IsPutWordOk()
  72. {
  73. if ( _state == statePAW )
  74. _state = stateStart;
  75. return _state != stateError;
  76. }
  77. //+---------------------------------------------------------------------------
  78. //
  79. // Member: CAltWordsEnforcer::IsPutAltWordOk
  80. //
  81. // Synopsis: Is the PutAltWord method call allowed in the current state ? After a
  82. // sequence of PutAltWord calls at least one PutWord method must be
  83. // called before any StartAltPhrase or EndAltPhrase methods
  84. //
  85. // History: 24-Apr-1995 SitaramR Created
  86. //
  87. //----------------------------------------------------------------------------
  88. inline BOOL CAltWordsEnforcer::IsPutAltWordOk()
  89. {
  90. if ( _state == stateStart )
  91. _state = statePAW;
  92. return _state != stateError;
  93. }
  94. //+---------------------------------------------------------------------------
  95. //
  96. // Member: CAltWordsEnforcer::IsStartAltPhraseOk
  97. //
  98. // Synopsis: Is the StartAltPhrase method call allowed in the current state ? After a
  99. // sequence of PutAltWord calls at least one PutWord method must be
  100. // called before any StartAltPhrase or EndAltPhrase methods
  101. //
  102. // History: 24-Apr-1995 SitaramR Created
  103. //
  104. //----------------------------------------------------------------------------
  105. inline BOOL CAltWordsEnforcer::IsStartAltPhraseOk()
  106. {
  107. if ( _state == statePAW )
  108. _state = stateError;
  109. return _state != stateError;
  110. }
  111. //+---------------------------------------------------------------------------
  112. //
  113. // Member: CAltWordsEnforcer::IsEndAltPhraseOk
  114. //
  115. // Synopsis: Is the EndAltPhrase method call allowed in the current state ? After a
  116. // sequence of PutAltWord calls at least one PutWord method must be
  117. // called before any StartAltPhrase or EndAltPhrase methods
  118. //
  119. // History: 24-Apr-1995 SitaramR Created
  120. //
  121. //----------------------------------------------------------------------------
  122. inline BOOL CAltWordsEnforcer::IsEndAltPhraseOk()
  123. {
  124. if ( _state == statePAW )
  125. _state = stateError;
  126. return _state != stateError;
  127. }
  128. //+---------------------------------------------------------------------------
  129. //
  130. // Member: CAltPhrasesEnforcer::IsStartAltPhraseOk
  131. //
  132. // Synopsis: Is the StartAltPhrase method call allowed in the current state ?
  133. // There cannot be two EndAltPhrase calls without an intervening
  134. // StartAltPhrase
  135. //
  136. // History: 24-Apr-1995 SitaramR Created
  137. //
  138. //----------------------------------------------------------------------------
  139. inline BOOL CAltPhrasesEnforcer::IsStartAltPhraseOk()
  140. {
  141. if ( _state == stateStart || _state == stateEAP )
  142. _state = stateSAP;
  143. return _state != stateError;
  144. }
  145. //+---------------------------------------------------------------------------
  146. //
  147. // Member: CAltPhrasesEnforcer::IsEndAltPhraseOk
  148. //
  149. // Synopsis: Is the EndAltPhrase method call allowed in the current state ?
  150. //
  151. // History: 24-Apr-1995 SitaramR Created
  152. //
  153. //----------------------------------------------------------------------------
  154. inline BOOL CAltPhrasesEnforcer::IsEndAltPhraseOk()
  155. {
  156. if ( _state == stateSAP )
  157. _state = stateEAP;
  158. else
  159. _state = stateError;
  160. return _state != stateError;
  161. }