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.

127 lines
3.6 KiB

  1. // strstream standard header
  2. #ifndef _STRSTREAM_
  3. #define _STRSTREAM_
  4. #include <istream>
  5. #ifdef _MSC_VER
  6. #pragma pack(push,8)
  7. #endif /* _MSC_VER */
  8. _STD_BEGIN
  9. // CLASS strstreambuf
  10. class strstreambuf : public streambuf {
  11. public:
  12. enum __Strstate {_Allocated = 1, _Constant = 2,
  13. _Dynamic = 4, _Frozen = 8};
  14. _BITMASK(__Strstate, _Strstate);
  15. explicit strstreambuf(streamsize _N = 0)
  16. {_Init(_N); }
  17. strstreambuf(void *(__cdecl *_A)(size_t),
  18. void (__cdecl *_F)(void *))
  19. {_Init(), _Palloc = _A, _Pfree = _F; }
  20. strstreambuf(char *_G, streamsize _N, char *_P = 0)
  21. {_Init(_N, _G, _P); }
  22. strstreambuf(unsigned char *_G, streamsize _N,
  23. unsigned char *_P = 0)
  24. {_Init(_N, (char *)_G, (char *)_P); }
  25. strstreambuf(const char *_G, streamsize _N)
  26. {_Init(_N, (char *)_G, 0, _Constant); }
  27. strstreambuf(const unsigned char *_G, streamsize _N)
  28. {_Init(_N, (char *)_G, 0, _Constant); }
  29. _CRTIMP2 virtual ~strstreambuf();
  30. _CRTIMP2 void freeze(bool = true);
  31. char *str()
  32. {freeze();
  33. return (gptr()); }
  34. streamsize pcount() const
  35. {return (pptr() == 0 ? 0 : (streamsize) (pptr() - pbase())); }
  36. strstreambuf(signed char *_G, streamsize _N,
  37. signed char *_P = 0)
  38. {_Init(_N, (char *)_G, (char *)_P); }
  39. strstreambuf(const signed char *_G, streamsize _N)
  40. {_Init(_N, (char *)_G, 0, _Constant); }
  41. protected:
  42. _CRTIMP2 virtual int overflow(int = EOF);
  43. _CRTIMP2 virtual int pbackfail(int = EOF);
  44. _CRTIMP2 virtual int underflow();
  45. _CRTIMP2 virtual streampos seekoff(streamoff, ios::seekdir,
  46. ios::openmode = ios::in | ios::out);
  47. _CRTIMP2 virtual streampos seekpos(streampos,
  48. ios::openmode = ios::in | ios::out);
  49. _CRTIMP2 void _Init(int = 0, char * = 0, char * = 0,
  50. _Strstate = (_Strstate)0);
  51. _CRTIMP2 void _Tidy();
  52. private:
  53. enum {_ALSIZE = 512, _MINSIZE = 32};
  54. char *_Pendsave, *_Seekhigh;
  55. int _Alsize;
  56. _Strstate _Strmode;
  57. void *(__cdecl *_Palloc)(size_t);
  58. void (__cdecl *_Pfree)(void *);
  59. };
  60. _BITMASK_OPS(strstreambuf::__Strstate)
  61. // CLASS istrstream
  62. class istrstream : public istream {
  63. public:
  64. explicit istrstream(const char *_S)
  65. : istream(&_Sb), _Sb(_S, 0) {}
  66. istrstream(const char *_S, streamsize _N)
  67. : istream(&_Sb), _Sb(_S, _N) {}
  68. explicit istrstream(char *_S)
  69. : istream(&_Sb), _Sb((const char *)_S, 0) {}
  70. istrstream(char *_S, int _N)
  71. : istream(&_Sb), _Sb((const char *)_S, _N) {}
  72. _CRTIMP2 virtual ~istrstream();
  73. strstreambuf *rdbuf() const
  74. {return ((strstreambuf *)&_Sb); }
  75. char *str()
  76. {return (_Sb.str()); }
  77. private:
  78. strstreambuf _Sb;
  79. };
  80. // CLASS ostrstream
  81. class ostrstream : public ostream {
  82. public:
  83. ostrstream()
  84. : ostream(&_Sb), _Sb() {}
  85. _CRTIMP2 ostrstream(char *, streamsize, openmode = out);
  86. _CRTIMP2 virtual ~ostrstream();
  87. strstreambuf *rdbuf() const
  88. {return ((strstreambuf *)&_Sb); }
  89. void freeze(bool _F = true)
  90. {_Sb.freeze(_F); }
  91. char *str()
  92. {return (_Sb.str()); }
  93. streamsize pcount() const
  94. {return (_Sb.pcount()); }
  95. private:
  96. strstreambuf _Sb;
  97. };
  98. // CLASS strstream
  99. class strstream : public iostream {
  100. public:
  101. strstream()
  102. : iostream(&_Sb), _Sb() {}
  103. _CRTIMP2 strstream(char *, streamsize, openmode = in | out);
  104. _CRTIMP2 virtual ~strstream();
  105. strstreambuf *rdbuf() const
  106. {return ((strstreambuf *)&_Sb); }
  107. void freeze(bool _F = true)
  108. {_Sb.freeze(_F); }
  109. char *str()
  110. {return (_Sb.str()); }
  111. streamsize pcount() const
  112. {return (_Sb.pcount()); }
  113. private:
  114. strstreambuf _Sb;
  115. };
  116. _STD_END
  117. #ifdef _MSC_VER
  118. #pragma pack(pop)
  119. #endif /* _MSC_VER */
  120. #endif /* _STRSTREAM_ */
  121. /*
  122. * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
  123. * Consult your license regarding permissions and restrictions.
  124. */