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.

190 lines
4.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: buffer.hxx
  7. //
  8. // Contents: An ASCII text-buffer for outputting to a debug stream
  9. //
  10. // Classes: CTextBufferA
  11. //
  12. // History: 11-Jul-95 t-stevan Created
  13. //
  14. //
  15. //----------------------------------------------------------------------------
  16. #ifndef __BUFFER_HXX__
  17. #define __BUFFER_HXX__
  18. #include "outfuncs.h"
  19. // The size of our text buffer
  20. const size_t cBufferSize = 1024;
  21. // A value that defines a "snapshot" of the buffer, in order to go back to
  22. // the way it was if we made a mistake.
  23. struct BufferContext
  24. {
  25. char * dwContext; // snapshot of the buffer's context
  26. WORD wRef; // the reference no of the context
  27. };
  28. //+-------------------------------------------------------------------------
  29. //
  30. // Class: CTextBufferA
  31. //
  32. // Purpose: ASCII text buffer for outputting to some stream
  33. //
  34. // Interface: CTextBufferA
  35. // ~CTextBufferA
  36. // operator<< (insertion operator)
  37. // Flush
  38. // Clear
  39. //
  40. // History: 11-Jul-95 t-stevan Created
  41. //
  42. //--------------------------------------------------------------------------
  43. class CTextBufferA
  44. {
  45. public:
  46. inline CTextBufferA();
  47. inline ~CTextBufferA();
  48. CTextBufferA &operator<<(const char *pStr);
  49. inline CTextBufferA &operator<<(char cChar);
  50. // insertion operator which only does 'n' bytes
  51. void Insert(const char *pStr, size_t nCount);
  52. inline void Flush();
  53. inline void Clear();
  54. inline void SnapShot(BufferContext &bc) const;
  55. // Note that if the buffer has flushed since the last snap shot
  56. // it is assumed that the old buffer context is invalid, and this does nothing
  57. BOOL Revert(const BufferContext &bc);
  58. private:
  59. char m_szBuffer[cBufferSize+1]; // plus one so we have space to tag on NULL byte
  60. char *m_pszPos;
  61. WORD m_wFlushes; // the number of times we've flushed
  62. };
  63. //+-------------------------------------------------------------------------
  64. //
  65. // Member: CTextBufferA::CTextBufferA
  66. //
  67. // Synopsis: Constructor
  68. //
  69. // Arguments:
  70. //
  71. // History: 11-Jul-95 t-stevan Created
  72. //
  73. //--------------------------------------------------------------------------
  74. inline CTextBufferA::CTextBufferA()
  75. {
  76. m_pszPos = m_szBuffer;
  77. m_wFlushes = 0;
  78. }
  79. //+-------------------------------------------------------------------------
  80. //
  81. // Member: CTextBufferA::~CTextBufferA
  82. //
  83. // Synopsis: Destructor
  84. //
  85. // Algorithm: calls Flush() before destroying object
  86. //
  87. // History: 11-Jul-95 t-stevan Created
  88. //
  89. //--------------------------------------------------------------------------
  90. inline CTextBufferA::~CTextBufferA()
  91. {
  92. Flush(); // flush our buffer out before we're done
  93. }
  94. //+-------------------------------------------------------------------------
  95. //
  96. // Member: CTextBufferA::operator<< (char)
  97. //
  98. // Synopsis: Character Insertion operator
  99. //
  100. // Arguments: [cChar] - char to insert into stream
  101. //
  102. // Returns: reference to this stream
  103. //
  104. // Algorithm: inserts pStr into buffer, if not enough room, flushes buffer
  105. //
  106. // History: 11-Jul-95 t-stevan Created
  107. //
  108. //--------------------------------------------------------------------------
  109. inline CTextBufferA &CTextBufferA::operator<<(char cChar)
  110. {
  111. *m_pszPos++ = cChar;
  112. if(m_pszPos == m_szBuffer+cBufferSize)
  113. {
  114. Flush(); // flush our output
  115. }
  116. return *this;
  117. }
  118. //+-------------------------------------------------------------------------
  119. //
  120. // Member: CTextBufferA::Clear
  121. //
  122. // Synopsis: Clear (reset) buffer
  123. //
  124. // History: 11-Jul-95 t-stevan Created
  125. //
  126. //--------------------------------------------------------------------------
  127. inline void CTextBufferA::Clear()
  128. {
  129. m_pszPos = m_szBuffer;
  130. }
  131. //+-------------------------------------------------------------------------
  132. //
  133. // Member: CTextBufferA::Flush
  134. //
  135. // Synopsis: Flushes buffer to output
  136. //
  137. // History: 11-Jul-95 t-stevan Created
  138. //
  139. //--------------------------------------------------------------------------
  140. inline void CTextBufferA::Flush()
  141. {
  142. // tag on NULL byte
  143. *(m_pszPos+1) = '\0';
  144. // Call output functions to dump the string
  145. CallOutputFunctions(m_szBuffer);
  146. m_wFlushes++;
  147. Clear();
  148. }
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Member: CTextBufferA::SnapShot
  152. //
  153. // Synopsis: Takes a snap shot of the current buffer, so that
  154. // it may be reverted to later
  155. //
  156. // Arguments: [bc] - a buffer context to store the snap shot into
  157. //
  158. // History: 11-Jul-95 t-stevan Created
  159. //
  160. //--------------------------------------------------------------------------
  161. inline void CTextBufferA::SnapShot(BufferContext &bc) const
  162. {
  163. bc.dwContext = m_pszPos;
  164. bc.wRef = m_wFlushes;
  165. }
  166. #endif