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.

253 lines
6.7 KiB

  1. // strstream standard header
  2. #pragma once
  3. #ifndef _STRSTREAM_
  4. #define _STRSTREAM_
  5. #include <istream>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. _STD_BEGIN
  9. // CLASS strstreambuf
  10. class strstreambuf
  11. : public streambuf
  12. { // stream buffer associated with static or allocated character array
  13. public:
  14. enum
  15. { // constants for bits in stream state
  16. _Allocated = 1, // set if character array storage has been allocated
  17. _Constant = 2, // set if character array nonmutable
  18. _Dynamic = 4, // set if character array length grows on demand
  19. _Frozen = 8}; // set if character array ownership given away
  20. typedef int _Strstate;
  21. explicit strstreambuf(streamsize _Count = 0)
  22. { // construct with empty character array, suggested initial size
  23. _Init(_Count);
  24. }
  25. strstreambuf(void *(__cdecl *_Allocfunc)(size_t),
  26. void (__cdecl *_Freefunc)(void *))
  27. { // construct with empty character array, allocation functions
  28. _Init();
  29. _Palloc = _Allocfunc;
  30. _Pfree = _Freefunc;
  31. }
  32. strstreambuf(char *_Getptr, streamsize _Count, char *_Putptr = 0)
  33. { // construct with [_Getptr, _Getptr + _Count), possibly mutable
  34. _Init(_Count, _Getptr, _Putptr);
  35. }
  36. strstreambuf(unsigned char *_Getptr, streamsize _Count,
  37. unsigned char *_Putptr = 0)
  38. { // construct with [_Getptr, _Getptr + _Count), possibly mutable
  39. _Init(_Count, (char *)_Getptr, (char *)_Putptr);
  40. }
  41. strstreambuf(const char *_Getptr, streamsize _Count)
  42. { // construct with [_Getptr, _Getptr + _Count), nonmutable
  43. _Init(_Count, (char *)_Getptr, 0, _Constant);
  44. }
  45. strstreambuf(const unsigned char *_Getptr, streamsize _Count)
  46. { // construct with [_Getptr, _Getptr + _Count), nonmutable
  47. _Init(_Count, (char *)_Getptr, 0, _Constant);
  48. }
  49. _CRTIMP2 virtual ~strstreambuf(); // destroy the object
  50. _CRTIMP2 void freeze(bool = true); // freeze or unfreeze writing
  51. char *str()
  52. { // freeze and return pointer to character array
  53. freeze();
  54. return (gptr());
  55. }
  56. streamsize pcount() const
  57. { // return size of writable character array
  58. return (pptr() == 0 ? 0 : (streamsize)(pptr() - pbase()));
  59. }
  60. strstreambuf(signed char *_Getptr, streamsize _Count,
  61. signed char *_Putptr = 0)
  62. { // construct with [_Getptr, _Getptr + _Count), possibly mutable
  63. _Init(_Count, (char *)_Getptr, (char *)_Putptr);
  64. }
  65. strstreambuf(const signed char *_Getptr, streamsize _Count)
  66. { // construct with [_Getptr, _Getptr + _Count), nonmutable
  67. _Init(_Count, (char *)_Getptr, 0, _Constant);
  68. }
  69. protected:
  70. _CRTIMP2 virtual int overflow(int = EOF); // try to extend write area
  71. _CRTIMP2 virtual int pbackfail(int = EOF); // try to putback a character
  72. _CRTIMP2 virtual int underflow(); // read if read position available
  73. _CRTIMP2 virtual streampos seekoff(streamoff,
  74. ios_base::seekdir,
  75. ios_base::openmode =
  76. ios_base::in | ios_base::out); // seek by specified offset
  77. _CRTIMP2 virtual streampos seekpos(streampos,
  78. ios_base::openmode =
  79. ios_base::in | ios_base::out); // seek to memorized position
  80. _CRTIMP2 void _Init(streamsize = 0, char * = 0, char * = 0,
  81. _Strstate = (_Strstate)0); // initialize with possibly static buffer
  82. _CRTIMP2 void _Tidy(); // free any allocated storage
  83. private:
  84. enum
  85. { // constant for default minimum buffer size
  86. _MINSIZE = 32};
  87. streamsize _Minsize; // the minimum buffer size
  88. char *_Pendsave; // the saved end pointer during freeze
  89. char *_Seekhigh; // the high-water pointer in character array
  90. _Strstate _Strmode; // the stream state
  91. void *(__cdecl *_Palloc)(size_t); // the pointer to allocator function
  92. void (__cdecl *_Pfree)(void *); // the pointer to free function
  93. };
  94. // CLASS istrstream
  95. class istrstream
  96. : public istream
  97. { // input stream associated with a character array
  98. public:
  99. explicit istrstream(const char *_Ptr)
  100. : istream(&_Mysb), _Mysb(_Ptr, 0)
  101. { // construct with NTBS
  102. }
  103. istrstream(const char *_Ptr, streamsize _Count)
  104. : istream(&_Mysb), _Mysb(_Ptr, _Count)
  105. { // construct with [_Ptr, _Ptr + _Count)
  106. }
  107. explicit istrstream(char *_Ptr)
  108. : istream(&_Mysb), _Mysb((const char *)_Ptr, 0)
  109. { // construct with NTBS
  110. }
  111. istrstream(char *_Ptr, int _Count)
  112. : istream(&_Mysb), _Mysb((const char *)_Ptr, _Count)
  113. { // construct with [_Ptr, _Ptr + _Count)
  114. }
  115. _CRTIMP2 virtual ~istrstream(); // destroy the object
  116. strstreambuf *rdbuf() const
  117. { // return pointer to character array buffer
  118. return ((strstreambuf *)&_Mysb);
  119. }
  120. char *str()
  121. { // freeze and return pointer to character array
  122. return (_Mysb.str());
  123. }
  124. private:
  125. strstreambuf _Mysb; // the string buffer
  126. };
  127. // CLASS ostrstream
  128. class ostrstream
  129. : public ostream
  130. { // output stream associated with a character array
  131. public:
  132. ostrstream()
  133. : ostream(&_Mysb), _Mysb()
  134. { // construct with empty character array
  135. }
  136. _CRTIMP2 ostrstream(char *, streamsize,
  137. ios_base::openmode =
  138. ios_base::out); // construct with static array
  139. _CRTIMP2 virtual ~ostrstream(); // destroy the object
  140. strstreambuf *rdbuf() const
  141. { // return pointer to character array buffer
  142. return ((strstreambuf *)&_Mysb);
  143. }
  144. void freeze(bool _Freezeit = true)
  145. { // freeze or unfreeze writing
  146. _Mysb.freeze(_Freezeit);
  147. }
  148. char *str()
  149. { // freeze and return pointer to character array
  150. return (_Mysb.str());
  151. }
  152. streamsize pcount() const
  153. { // return size of writable character array
  154. return (_Mysb.pcount());
  155. }
  156. private:
  157. strstreambuf _Mysb; // the character array buffer
  158. };
  159. // CLASS strstream
  160. class strstream
  161. : public iostream
  162. { // input/output stream associated with character array buffer
  163. public:
  164. typedef char char_type;
  165. typedef int int_type;
  166. typedef streampos pos_type;
  167. typedef streamoff off_type;
  168. strstream()
  169. : iostream(&_Mysb), _Mysb()
  170. { // construct with empty character array
  171. }
  172. _CRTIMP2 strstream(char *, streamsize,
  173. ios_base::openmode =
  174. ios_base::in | ios_base::out); // construct with static array
  175. _CRTIMP2 virtual ~strstream(); // destroy the object
  176. strstreambuf *rdbuf() const
  177. { // return pointer to character array buffer
  178. return ((strstreambuf *)&_Mysb);
  179. }
  180. void freeze(bool _Freezeit = true)
  181. { // freeze or unfreeze writing
  182. _Mysb.freeze(_Freezeit);
  183. }
  184. char *str()
  185. { // freeze and return pointer to character array
  186. return (_Mysb.str());
  187. }
  188. streamsize pcount() const
  189. { // return size of writable character array
  190. return (_Mysb.pcount());
  191. }
  192. private:
  193. strstreambuf _Mysb; // the character array buffer
  194. };
  195. _STD_END
  196. #pragma warning(pop)
  197. #pragma pack(pop)
  198. #endif /* _STRSTREAM_ */
  199. /*
  200. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  201. * Consult your license regarding permissions and restrictions.
  202. V3.10:0009 */