home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / strstrea.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  4KB  |  148 lines

  1. /***
  2. *strstrea.h - definitions/declarations for strstreambuf, strstream
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       This file defines the classes, values, macros, and functions
  8. *       used by the strstream and strstreambuf classes.
  9. *       [AT&T C++]
  10. *
  11. *       [Public]
  12. *
  13. ****/
  14.  
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif  /* _MSC_VER > 1000 */
  18.  
  19. #ifdef __cplusplus
  20.  
  21. #ifndef _INC_STRSTREAM
  22. #define _INC_STRSTREAM
  23.  
  24. #if !defined (_WIN32) && !defined (_MAC)
  25. #error ERROR: Only Mac or Win32 targets supported!
  26. #endif  /* !defined (_WIN32) && !defined (_MAC) */
  27.  
  28. #ifndef _CRTBLD
  29. /* This version of the header files is NOT for user programs.
  30.  * It is intended for use when building the C runtimes ONLY.
  31.  * The version intended for public use will not have this message.
  32.  */
  33. #error ERROR: Use of C runtime library internal header file.
  34. #endif  /* _CRTBLD */
  35.  
  36. #ifdef _MSC_VER
  37.  
  38. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  39. // alignment.
  40. #pragma pack(push,8)
  41.  
  42. #endif  /* _MSC_VER */
  43.  
  44. /* Define _CRTIMP */
  45.  
  46. #ifndef _CRTIMP
  47. #ifdef CRTDLL
  48. #define _CRTIMP __declspec(dllexport)
  49. #else  /* CRTDLL */
  50. #ifdef _DLL
  51. #define _CRTIMP __declspec(dllimport)
  52. #else  /* _DLL */
  53. #define _CRTIMP
  54. #endif  /* _DLL */
  55. #endif  /* CRTDLL */
  56. #endif  /* _CRTIMP */
  57.  
  58. #ifndef _INTERNAL_IFSTRIP_
  59. /* Define _CRTIMP1 */
  60.  
  61. #ifndef _CRTIMP1
  62. #ifdef CRTDLL1
  63. #define _CRTIMP1 __declspec(dllexport)
  64. #else  /* CRTDLL1 */
  65. #define _CRTIMP1 _CRTIMP
  66. #endif  /* CRTDLL1 */
  67. #endif  /* _CRTIMP1 */
  68. #endif  /* _INTERNAL_IFSTRIP_ */
  69.  
  70. #include <useoldio.h>
  71. #include <iostream.h>
  72.  
  73. #ifdef _MSC_VER
  74. #pragma warning(disable:4514)           // disable unwanted /W4 warning
  75. // #pragma warning(default:4514)        // use this to reenable, if necessary
  76. #endif  /* _MSC_VER */
  77.  
  78. class _CRTIMP1 strstreambuf : public streambuf  {
  79. public:
  80.                 strstreambuf();
  81.                 strstreambuf(int);
  82.                 strstreambuf(char *, int, char * = 0);
  83.                 strstreambuf(unsigned char *, int, unsigned char * = 0);
  84.                 strstreambuf(signed char *, int, signed char * = 0);
  85.                 strstreambuf(void * (*a)(long), void (*f) (void *));
  86.                 ~strstreambuf();
  87.  
  88.         void    freeze(int =1);
  89.         char * str();
  90.  
  91. virtual int     overflow(int);
  92. virtual int     underflow();
  93. virtual streambuf* setbuf(char *, int);
  94. virtual streampos seekoff(streamoff, ios::seek_dir, int);
  95. virtual int     sync();         // not in spec.
  96.  
  97. protected:
  98. virtual int     doallocate();
  99. private:
  100.         int     x_dynamic;
  101.         int     x_bufmin;
  102.         int     _fAlloc;
  103.         int     x_static;
  104.         void * (* x_alloc)(long);
  105.         void    (* x_free)(void *);
  106. };
  107.  
  108. class _CRTIMP1 istrstream : public istream {
  109. public:
  110.                 istrstream(char *);
  111.                 istrstream(char *, int);
  112.                 ~istrstream();
  113.  
  114. inline  strstreambuf* rdbuf() const { return (strstreambuf*) ios::rdbuf(); }
  115. inline  char * str() { return rdbuf()->str(); }
  116. };
  117.  
  118. class _CRTIMP1 ostrstream : public ostream {
  119. public:
  120.                 ostrstream();
  121.                 ostrstream(char *, int, int = ios::out);
  122.                 ~ostrstream();
  123.  
  124. inline  int     pcount() const { return rdbuf()->out_waiting(); }
  125. inline  strstreambuf* rdbuf() const { return (strstreambuf*) ios::rdbuf(); }
  126. inline  char *  str() { return rdbuf()->str(); }
  127. };
  128.  
  129. class _CRTIMP1 strstream : public iostream {    // strstreambase ???
  130. public:
  131.                 strstream();
  132.                 strstream(char *, int, int);
  133.                 ~strstream();
  134.  
  135. inline  int     pcount() const { return rdbuf()->out_waiting(); } // not in spec.
  136. inline  strstreambuf* rdbuf() const { return (strstreambuf*) ostream::rdbuf(); }
  137. inline  char * str() { return rdbuf()->str(); }
  138. };
  139.  
  140. #ifdef _MSC_VER
  141. // Restore previous packing
  142. #pragma pack(pop)
  143. #endif  /* _MSC_VER */
  144.  
  145. #endif  /* _INC_STRSTREAM */
  146.  
  147. #endif  /* __cplusplus */
  148.