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.

162 lines
4.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: dstream.h
  7. //
  8. // Contents: internal debugging support (debug stream which builds a string)
  9. //
  10. // Classes: dbgstream
  11. //
  12. // Functions:
  13. //
  14. // History: dd-mmm-yy Author Comment
  15. // 09-Feb-95 t-ScottH author
  16. //
  17. //--------------------------------------------------------------------------
  18. #ifndef _STREAM_H_
  19. #define _STREAM_H_
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Class: dbgstream (_DEBUG only)
  23. //
  24. // Purpose: a stream which builds a string for debugging purposes
  25. // (used to build a string in Dump methods of LE objects such
  26. // that the character array can be passed off in debugger extensions
  27. // or used by call tracing)
  28. //
  29. // Interface: private:
  30. // allocate(DWORD)
  31. // free()
  32. // reallocate()
  33. // reallocate(DWORD)
  34. // init()
  35. // public:
  36. // dbgstream(DWORD)
  37. // dbgstream()
  38. // ~dbgstream()
  39. // hex()
  40. // oct()
  41. // dec()
  42. // precision()
  43. // freeze()
  44. // unfreeze()
  45. // str()
  46. // operator<<(const void *)
  47. // operator<<(const char *)
  48. // operator<<(const unsigned char *)
  49. // operator<<(const signed char *)
  50. // operator<<(int)
  51. // operator<<(unsigned int)
  52. // operator<<(long)
  53. // operator<<(unsigned long)
  54. // operator<<(float)
  55. //
  56. // History: dd-mmm-yy Author Comment
  57. // 11-Feb-95 t-ScottH author
  58. //
  59. // Notes:
  60. // This is simple, efficient implementation of the CRT ostrstream. The
  61. // ostrstream was found to have too much overhead and thus performance
  62. // was terrible (in the debugger extensions almost a 5-10x slower) than
  63. // this implementation
  64. //
  65. // this implementation differs from the ostrstream class
  66. // - no need to append a null character to the string (the string ALWAYS
  67. // maintains a null character at the end of the string)
  68. // - implementation uses CoTaskMem[Alloc, Free, Realloc] for memory
  69. // management. Therefore, all strings passes out externally must also
  70. // use CoTaskMem[Alloc, Free, Realloc] for memory management
  71. //
  72. //--------------------------------------------------------------------------
  73. #ifdef _DEBUG
  74. #define DEFAULT_INITIAL_ALLOC 300
  75. #define DEFAULT_GROWBY 100
  76. #define DEFAULT_RADIX 10
  77. #define DEFAULT_PRECISION 6
  78. #define endl "\n"
  79. #define ends "\0"
  80. class dbgstream
  81. {
  82. private:
  83. // *** data members ***
  84. // pointer to last character in buffer
  85. SIZE_T m_stIndex;
  86. // maximum size of current buffer
  87. SIZE_T m_stBufSize;
  88. // if TRUE -> cannot change buffer
  89. BOOL m_fFrozen;
  90. // buffer
  91. char *m_pszBuf;
  92. // hex, dec, or oct for storing ints or longs
  93. int m_radix;
  94. // precision for doubles and floats
  95. int m_precision;
  96. // *** private methods ***
  97. void allocate(SIZE_T stSize);
  98. void reallocate(SIZE_T stSize);
  99. void reallocate();
  100. void free();
  101. void init();
  102. public:
  103. // *** constructors and destructor ***
  104. dbgstream(SIZE_T stSize);
  105. dbgstream();
  106. ~dbgstream();
  107. // *** public interface ***
  108. char *str();
  109. BOOL freeze();
  110. BOOL unfreeze();
  111. void hex() {m_radix = 16;}
  112. void dec() {m_radix = 10;}
  113. void oct() {m_radix = 8; }
  114. void precision(int p) {m_precision = p;}
  115. dbgstream& dbgstream::operator<<(int i);
  116. dbgstream& dbgstream::operator<<(unsigned int ui)
  117. {
  118. return (operator<<((unsigned long)ui));
  119. }
  120. dbgstream& dbgstream::operator<<(long l);
  121. dbgstream& dbgstream::operator<<(unsigned long ul);
  122. dbgstream& dbgstream::operator<<(const void *p);
  123. dbgstream& dbgstream::operator<<(const char *psz);
  124. dbgstream& dbgstream::operator<<(const unsigned char *psz)
  125. {
  126. return (operator<<((const char *)psz));
  127. }
  128. dbgstream& dbgstream::operator<<(const signed char *psz)
  129. {
  130. return (operator<<((const char *)psz));
  131. }
  132. };
  133. #endif // _DEBUG
  134. #endif // _STREAM_H_