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.

226 lines
5.0 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module _RTFLOG.H -- RichEdit RTF Log Class Definition |
  5. *
  6. * This file contains the class declarations for an RTF log class
  7. * which can be used to track the hit counts of RTF tags encountered
  8. * by the RTF reader
  9. *
  10. * Authors:<nl>
  11. * Created for RichEdit 2.0: Brad Olenick
  12. *
  13. * Copyright (c) 1995-1996, Microsoft Corporation. All rights reserved.
  14. */
  15. #ifndef __RTFLOG_H
  16. #define __RTFLOG_H
  17. #include "tokens.h"
  18. extern INT cKeywords;
  19. class CRTFLog
  20. {
  21. public:
  22. typedef size_t INDEX;
  23. typedef INDEX *PINDEX;
  24. typedef DWORD ELEMENT;
  25. typedef ELEMENT *PELEMENT;
  26. CRTFLog(); //@cmember CRTFLog constructor
  27. inline ~CRTFLog(); //@cmember CRTFLog destructor
  28. BOOL FInit() const
  29. { return _rgdwHits ? TRUE : FALSE; } //@cmember Determines whether object is init'd
  30. INDEX ISize() const
  31. { return cKeywords; } //@cmember Number of elements in log
  32. inline BOOL AddAt(INDEX i); //@cmember Increment hit count for element at index i
  33. inline BOOL AddAt(LPCSTR lpcstrKeyword); //@cmember Increment hit count for RTF keyword
  34. inline BOOL AddAt(TOKEN token); //@cmember Increment hit count for RTF token
  35. inline ELEMENT GetAt(INDEX i) const
  36. { return (*this)[i]; } //@cmember Get hit count for element i
  37. inline BOOL GetAt(LPCSTR lpcstrKeyword, PELEMENT pelemCount) const; //@cmember Get hit count for RTF keyword
  38. inline BOOL GetAt(TOKEN token, PELEMENT pelemCount) const; //@cmember Get hit count for RTF token
  39. void Reset(); //@cmember Reset all hit count values to 0
  40. UINT UGetWindowMsg() const; //@cmember Get window msg ID used for log change notifications
  41. private:
  42. // we manage all updates through AddAt to
  43. // facilitate change notifications
  44. ELEMENT &operator[](INDEX); //@cmember Access element i for l-value
  45. const ELEMENT &operator[](INDEX) const; //@cmember Access element i for r-value
  46. LPCSTR LpcstrLogFilename() const; //@cmember Get name of log filename
  47. BOOL IIndexOfKeyword(LPCSTR lpcstrKeyword, PINDEX pi) const; //@cmember Get log index for keyword
  48. BOOL IIndexOfToken(TOKEN token, PINDEX pi) const; //@cmember Get log index for token
  49. void ChangeNotify(INDEX i) const
  50. {
  51. PostMessage(HWND_BROADCAST, UGetWindowMsg(), i, 0);
  52. } //@cmember Notify clients of change to element i
  53. void ChangeNotifyAll() const
  54. { ChangeNotify(ISize() + 1); } //@cmember Notify clients of log refresh
  55. HANDLE _hfm; //@cmember Handle to file mapping
  56. HANDLE _hfile; //@cmember Handle to file behind file mapping
  57. PELEMENT _rgdwHits; //@cmember Handle to view of file mapping
  58. UINT _uMsg; //@cmember Window msg ID for change notifications
  59. };
  60. /*
  61. * CRTFLog::~CRTFLog
  62. *
  63. * @mfunc
  64. * Destructor - cleans up memory-mapped file and underlying resources
  65. *
  66. */
  67. inline CRTFLog::~CRTFLog()
  68. {
  69. if(_rgdwHits)
  70. {
  71. UnmapViewOfFile(_rgdwHits);
  72. }
  73. if(_hfm)
  74. {
  75. CloseHandle(_hfm);
  76. }
  77. if(_hfile)
  78. {
  79. CloseHandle(_hfile);
  80. }
  81. }
  82. /*
  83. * CRTFLog::AddAt(INDEX i)
  84. *
  85. * @mfunc
  86. * Increments the hit count for log element, i, and
  87. * notifies clients of the change
  88. *
  89. * @rdesc
  90. * BOOL whether the increment was successful
  91. */
  92. inline BOOL CRTFLog::AddAt(INDEX i)
  93. {
  94. (*this)[i]++;
  95. // change notification
  96. ChangeNotify(i);
  97. return TRUE;
  98. }
  99. /*
  100. * CRTFLog::AddAt(LPCSTR lpcstrKeyword)
  101. *
  102. * @mfunc
  103. * Increments the hit count for log element corresponding
  104. * to the RTF keyword, lpcstrKeyword, and
  105. * notifies clients of the change
  106. *
  107. * @rdesc
  108. * BOOL whether the increment was successful
  109. */
  110. inline BOOL CRTFLog::AddAt(LPCSTR lpcstrKeyword)
  111. {
  112. INDEX i;
  113. if(!IIndexOfKeyword(lpcstrKeyword, &i))
  114. {
  115. return FALSE;
  116. }
  117. return AddAt(i);
  118. }
  119. /*
  120. * CRTFLog::AddAt(TOKEN token)
  121. *
  122. * @mfunc
  123. * Increments the hit count for log element corresponding
  124. * to the RTF token, token, and
  125. * notifies clients of the change
  126. *
  127. * @rdesc
  128. * BOOL whether the increment was successful
  129. */
  130. inline BOOL CRTFLog::AddAt(TOKEN token)
  131. {
  132. INDEX i;
  133. if(!IIndexOfToken(token, &i))
  134. {
  135. return FALSE;
  136. }
  137. return AddAt((INDEX)i);
  138. }
  139. /*
  140. * CRTFLog::GetAt(LPCSTR lpcstKeyword, PELEMENT pelemCount)
  141. *
  142. * @mfunc
  143. * Gets the hit count for log element corresponding to the
  144. * RTF keyword, lpcstrKeywor
  145. *
  146. * @rdesc
  147. * BOOL indicates whether a hit count was found for the element
  148. */
  149. inline BOOL CRTFLog::GetAt(LPCSTR lpcstrKeyword, PELEMENT pelemCount) const
  150. {
  151. INDEX i;
  152. if(!IIndexOfKeyword(lpcstrKeyword, &i))
  153. {
  154. return FALSE;
  155. }
  156. if(pelemCount)
  157. {
  158. *pelemCount = (*this)[i];
  159. }
  160. return TRUE;
  161. }
  162. /*
  163. * CRTFLog::GetAt(LPCSTR lpcstKeyword, PELEMENT pelemCount)
  164. *
  165. * @mfunc
  166. * Gets the hit count for log element corresponding to the
  167. * RTF token, token
  168. *
  169. * @rdesc
  170. * BOOL indicates whether a hit count was found for the element
  171. */
  172. inline BOOL CRTFLog::GetAt(TOKEN token, PELEMENT pelemCount) const
  173. {
  174. INDEX i;
  175. if(!IIndexOfToken(token, &i))
  176. {
  177. return FALSE;
  178. }
  179. if(pelemCount)
  180. {
  181. *pelemCount = (*this)[i];
  182. }
  183. return TRUE;
  184. }
  185. #endif