home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / h.z / STRSTREA.H < prev    next >
C/C++ Source or Header  |  1996-07-24  |  5KB  |  188 lines

  1. //
  2. //  strstrea.h    String streams
  3. //
  4. //  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  5. //
  6. #ifndef _STRSTREAM_H_INCLUDED
  7. #define _STRSTREAM_H_INCLUDED
  8.  
  9. #ifndef __cplusplus
  10. #error strstrea.h is for use with C++
  11. #endif
  12.  
  13. #ifndef _COMDEF_H_INCLUDED
  14.  #include <_comdef.h>
  15. #endif
  16. #ifndef _IOSTREAM_H_INCLUDED
  17.  #include <iostream.h>
  18. #endif
  19.  
  20. // **************************** STRSTREAMBUF *********************************
  21. #if defined(_M_IX86)
  22.   #pragma pack(__push,1);
  23. #else
  24.   #pragma pack(__push,8);
  25. #endif
  26. class _WPRTLINK strstreambuf : public streambuf {
  27. public:
  28.     strstreambuf();
  29.     strstreambuf( int __allocation_size );
  30.     strstreambuf( void *(*__alloc_fn)( long ), void (*__free_fn)( void * ) );
  31.     strstreambuf( char *__str, int __size, char *__pstart = NULL );
  32.     ~strstreambuf();
  33.  
  34.     int   alloc_size_increment( int __increment );
  35.     void  freeze( int __freeze = 1 );
  36.     char *str();
  37.  
  38.     virtual int        overflow( int = EOF );
  39.     virtual int        underflow();
  40.     virtual streambuf *setbuf( char *__ignored, int __allocation_size );
  41.     virtual streampos  seekoff( streamoff     __offset,
  42.                                 ios::seekdir  __direction,
  43.                                 ios::openmode __mode );
  44.     virtual int        sync();
  45.  
  46. protected:
  47.     virtual int doallocate();
  48.  
  49. private:
  50.     void  __strstreambuf( char *, int, char * );
  51.  
  52.     void *(*__alloc_fn)( long );
  53.     void  (*__free_fn)( void * );
  54.     int   __allocation_size;
  55.     int   __minbuf_size;
  56.     unsigned  __frozen    : 1;
  57.     unsigned  __dynamic   : 1;
  58.     unsigned  __unlimited : 1;
  59. };
  60. #pragma pack(__pop);
  61.  
  62. inline strstreambuf::strstreambuf() {
  63.     __strstreambuf( NULL, 0, NULL );
  64. }
  65.  
  66. inline strstreambuf::strstreambuf( char *__ptr, int __size, char *__pstart ) {
  67.     __strstreambuf( __ptr, __size, __pstart );
  68. }
  69.  
  70. inline int strstreambuf::alloc_size_increment( int __increment ) {
  71.     __lock_it( __b_lock );
  72.     int __old_allocation_size = __allocation_size;
  73.     __allocation_size        += __increment;
  74.     return( __old_allocation_size );
  75. }
  76.  
  77. inline void strstreambuf::freeze( int __freeze ) {
  78.     __frozen = (char)(__freeze ? 1 : 0);
  79. }
  80.  
  81. // **************************** STRSTREAMBASE ********************************
  82. #if defined(_M_IX86)
  83.   #pragma pack(__push,1);
  84. #else
  85.   #pragma pack(__push,8);
  86. #endif
  87. class _WPRTLINK strstreambase : public virtual ios {
  88. public:
  89.     strstreambuf *rdbuf() const;
  90.  
  91. protected:
  92.     strstreambase();
  93.     strstreambase( char *__str, int __size, char *__pstart = NULL );
  94.     ~strstreambase();
  95.  
  96. private:
  97.     strstreambuf __strstrmbuf;
  98. };
  99. #pragma pack(__pop);
  100.  
  101. inline strstreambuf *strstreambase::rdbuf() const {
  102.     return( (strstreambuf *) ios::rdbuf() );
  103. }
  104.  
  105. // ***************************** ISTRSTREAM **********************************
  106. #if defined(_M_IX86)
  107.   #pragma pack(__push,1);
  108. #else
  109.   #pragma pack(__push,8);
  110. #endif
  111. class _WPRTLINK istrstream : public strstreambase, public istream {
  112. public:
  113.     istrstream(          char *__str );
  114.     istrstream(   signed char *__str );
  115.     istrstream( unsigned char *__str );
  116.     istrstream(          char *__str, int __size );
  117.     istrstream(   signed char *__str, int __size );
  118.     istrstream( unsigned char *__str, int __size );
  119.     ~istrstream();
  120. };
  121. #pragma pack(__pop);
  122.  
  123. // ***************************** OSTRSTREAM **********************************
  124. #if defined(_M_IX86)
  125.   #pragma pack(__push,1);
  126. #else
  127.   #pragma pack(__push,8);
  128. #endif
  129. class _WPRTLINK ostrstream : public strstreambase, public ostream {
  130. public:
  131.     ostrstream();
  132.     ostrstream( char          *__str,
  133.                 int            __size,
  134.         ios::openmode  __mode = ios::out );
  135.     ostrstream( signed char   *__str,
  136.                 int            __size,
  137.         ios::openmode  __mode = ios::out );
  138.     ostrstream( unsigned char *__str,
  139.                 int            __size,
  140.         ios::openmode  __mode = ios::out );
  141.     ~ostrstream();
  142.  
  143.     int   pcount() const;
  144.     char *str();
  145. };
  146. #pragma pack(__pop);
  147.  
  148. inline char *ostrstream::str() {
  149.     __lock_it( __i_lock );
  150.     return( rdbuf()->str() );
  151. }
  152.  
  153. inline int ostrstream::pcount() const {
  154.     __lock_it( __i_lock );
  155.     return( rdbuf()->out_waiting() );
  156. }
  157.  
  158. // ***************************** STRSTREAM ***********************************
  159. #if defined(_M_IX86)
  160.   #pragma pack(__push,1);
  161. #else
  162.   #pragma pack(__push,8);
  163. #endif
  164. class _WPRTLINK strstream : public strstreambase, public iostream {
  165. public:
  166.     strstream();
  167.     strstream( char          *__str,
  168.                int            __size,
  169.            ios::openmode  __mode = ios::in|ios::out );
  170.     strstream( signed char   *__str,
  171.                int            __size,
  172.            ios::openmode  __mode = ios::in|ios::out );
  173.     strstream( unsigned char *__str,
  174.                int            __size,
  175.            ios::openmode  __mode = ios::in|ios::out );
  176.     ~strstream();
  177.  
  178.     char *str();
  179. };
  180. #pragma pack(__pop);
  181.  
  182. inline char *strstream::str() {
  183.     __lock_it( __i_lock );
  184.     return( rdbuf()->str() );
  185. }
  186.  
  187. #endif
  188.