home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / modhead1.zip / STRSTREA.H < prev    next >
C/C++ Source or Header  |  1995-05-15  |  3KB  |  135 lines

  1. /*
  2.  *   strstream.h
  3.  *
  4.  *   C++ IOStreams specialized for use with strings.
  5.  *
  6.  *           Copyright (c) 1991-1992, MetaWare Incorporated
  7.  */
  8.  
  9. #ifndef __STRSTREAM_H
  10. #define __STRSTREAM_H
  11. #pragma push_align_members(64);
  12.  
  13. #if _MSDOS && !__EXCEPTIONS__
  14.     #pragma off(exception_aware_class);
  15. #elif _MSDOS || _MSNT || _OS2
  16.     #pragma on(exception_aware_class);
  17. #endif
  18.  
  19. #if _MSNT && _DLL && !_DLLBUILD
  20.     #pragma on(dllimport);
  21. #endif
  22.  
  23. #c_include <iostream.h>
  24.  
  25. #pragma on(nodebug);
  26.  
  27. class strstreambuf : public streambuf {
  28. private:
  29.     void        init(char* __base, int __len,char* __put_origin);
  30.     void*        (*alloc_fcn)(long);    // fcn used to allocate space
  31.     void        (*free_fcn)(void*);    // fcn used to free space
  32.     enum strflags    {
  33.               ignore_oflow =  0x01,    // Ignore overflow condition
  34.               auto_extend  =  0x02,    // Reallocate buffer when full
  35.               frozen       =  0x04    // Buffer frozen--inserts fail
  36.             };
  37.     long        _strflags;        // status flags
  38.     int        next_min_alloc;
  39.  
  40. public: 
  41.             strstreambuf();
  42.             strstreambuf(int __min_size);
  43.             strstreambuf(void* (*__alloc)(long),
  44.                     void (*__free)(void*));
  45.             strstreambuf(char* __base, int __len,
  46.                     char* __put_origin = 0 );
  47.             strstreambuf(unsigned char* __base, int __len,
  48.                     unsigned char* __put_origin = 0 );
  49.             ~strstreambuf();
  50.  
  51.     void        _UNSAFE(freeze)(int __frozen=1);
  52.     char*        str();
  53.     // nothing to do in sync(), since external representation of a string
  54.     // stream buffer is the stream buffer itself and the buffer pointers
  55.     // are already in sync.
  56.         int             _UNSAFE(sync)() {
  57.                                 return 0;
  58.                         }
  59.     virtual int    _UNSAFE(doallocate)();
  60.     virtual int    _UNSAFE(overflow)(int __c);
  61.     virtual int    _UNSAFE(underflow)();
  62.     virtual streambuf*
  63.             setbuf(char*, int __len);
  64.     virtual streampos
  65.             _UNSAFE(seekoff)(streamoff __offset,
  66.                 ios::seek_dir __dir, long __mode);
  67.  
  68. #if _MT
  69. public:
  70.     void        freeze(int __frozen=1);
  71.     int        sync(){
  72.                 return(sync_unsafe());
  73.             }
  74.     virtual int    doallocate();
  75.     virtual int    overflow(int __c);
  76.     virtual int    underflow();
  77.     virtual streampos
  78.             seekoff(streamoff __offset, ios::seek_dir __dir,
  79.                     long __mode);
  80. #endif
  81.     };
  82.  
  83. class strstreambase : public virtual ios {
  84. private:
  85.     strstreambuf    buf; 
  86. protected:    
  87.             strstreambase(char* __base, int __len,
  88.                     char* __put_origin);
  89.             strstreambase();
  90.             ~strstreambase();
  91. public:
  92.     strstreambuf*    rdbuf();
  93.     };
  94.  
  95. class istrstream : public strstreambase, public istream {
  96. public:
  97.             istrstream(char* __base);
  98.             istrstream(char* __base, int __len);
  99.             ~istrstream();
  100.     };
  101.  
  102. class ostrstream : public strstreambase, public ostream {
  103. public:
  104.             ostrstream(char* __base, int __len,
  105.                     int __mode=ios::out);
  106.             ostrstream();
  107.             ~ostrstream();
  108.     char*        str();
  109.     int        pcount();
  110.     };
  111.  
  112.  
  113. class strstream : public strstreambase, public iostream {
  114. public:
  115.             strstream();
  116.             strstream(char* __base, int __len, int __mode);
  117.             ~strstream();
  118.     char*        str();
  119.     };
  120.  
  121. #pragma pop(nodebug);
  122.  
  123. #if _MSNT && _DLL && !_DLLBUILD
  124.     #pragma pop(dllimport);
  125. #endif
  126.  
  127. #if _MSDOS || _MSNT || _OS2
  128.     #pragma pop(exception_aware_class);
  129. #endif
  130.  
  131. #pragma pop_align_members();
  132. #endif __STRSTREAM_H
  133.  
  134. /**          Copyright (c) 1991-1992, MetaWare Incorporated             **/
  135.