home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / strstrea.h < prev    next >
C/C++ Source or Header  |  1998-06-16  |  3KB  |  126 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
  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
  27.  
  28.  
  29. #ifdef  _MSC_VER
  30.  
  31. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  32. // alignment.
  33. #pragma pack(push,8)
  34.  
  35. #endif  // _MSC_VER
  36.  
  37. /* Define _CRTIMP */
  38.  
  39. #ifndef _CRTIMP
  40. #ifdef  _DLL
  41. #define _CRTIMP __declspec(dllimport)
  42. #else   /* ndef _DLL */
  43. #define _CRTIMP
  44. #endif  /* _DLL */
  45. #endif  /* _CRTIMP */
  46.  
  47.  
  48. #include <useoldio.h>
  49. #include <iostream.h>
  50.  
  51. #ifdef  _MSC_VER
  52. #pragma warning(disable:4514)           // disable unwanted /W4 warning
  53. // #pragma warning(default:4514)        // use this to reenable, if necessary
  54. #endif  // _MSC_VER
  55.  
  56. class _CRTIMP strstreambuf : public streambuf  {
  57. public:
  58.                 strstreambuf();
  59.                 strstreambuf(int);
  60.                 strstreambuf(char *, int, char * = 0);
  61.                 strstreambuf(unsigned char *, int, unsigned char * = 0);
  62.                 strstreambuf(signed char *, int, signed char * = 0);
  63.                 strstreambuf(void * (*a)(long), void (*f) (void *));
  64.                 ~strstreambuf();
  65.  
  66.         void    freeze(int =1);
  67.         char * str();
  68.  
  69. virtual int     overflow(int);
  70. virtual int     underflow();
  71. virtual streambuf* setbuf(char *, int);
  72. virtual streampos seekoff(streamoff, ios::seek_dir, int);
  73. virtual int     sync();         // not in spec.
  74.  
  75. protected:
  76. virtual int     doallocate();
  77. private:
  78.         int     x_dynamic;
  79.         int     x_bufmin;
  80.         int     _fAlloc;
  81.         int     x_static;
  82.         void * (* x_alloc)(long);
  83.         void    (* x_free)(void *);
  84. };
  85.  
  86. class _CRTIMP istrstream : public istream {
  87. public:
  88.                 istrstream(char *);
  89.                 istrstream(char *, int);
  90.                 ~istrstream();
  91.  
  92. inline  strstreambuf* rdbuf() const { return (strstreambuf*) ios::rdbuf(); }
  93. inline  char * str() { return rdbuf()->str(); }
  94. };
  95.  
  96. class _CRTIMP ostrstream : public ostream {
  97. public:
  98.                 ostrstream();
  99.                 ostrstream(char *, int, int = ios::out);
  100.                 ~ostrstream();
  101.  
  102. inline  int     pcount() const { return rdbuf()->out_waiting(); }
  103. inline  strstreambuf* rdbuf() const { return (strstreambuf*) ios::rdbuf(); }
  104. inline  char *  str() { return rdbuf()->str(); }
  105. };
  106.  
  107. class _CRTIMP strstream : public iostream {    // strstreambase ???
  108. public:
  109.                 strstream();
  110.                 strstream(char *, int, int);
  111.                 ~strstream();
  112.  
  113. inline  int     pcount() const { return rdbuf()->out_waiting(); } // not in spec.
  114. inline  strstreambuf* rdbuf() const { return (strstreambuf*) ostream::rdbuf(); }
  115. inline  char * str() { return rdbuf()->str(); }
  116. };
  117.  
  118. #ifdef  _MSC_VER
  119. // Restore previous packing
  120. #pragma pack(pop)
  121. #endif  // _MSC_VER
  122.  
  123. #endif  // _INC_STRSTREAM
  124.  
  125. #endif /* __cplusplus */
  126.