home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / iostream.zoo / include / strstrea.h < prev   
Encoding:
C/C++ Source or Header  |  1991-09-22  |  2.2 KB  |  65 lines

  1. //    This is part of the iostream library, providing input/output for C++.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef __STRSTREAM_H
  19. #define __STRSTREAM_H
  20. #pragma interface
  21. #include <iostream.h>
  22.  
  23. class strstreambuf : public streambuf {
  24.     size_t *lenp; /* current (logical) length (i.e. valid data bytes) */
  25.     size_t *sizep; /* allocated (physical) buffer size */
  26.     char **bufp;
  27.     size_t _len;
  28.     size_t _size;
  29.     char *buf;
  30.     int _frozen;
  31.   protected:
  32.     virtual int overflow(int = EOF);
  33.   public:
  34.     strstreambuf();
  35.     strstreambuf(int initial);
  36.     strstreambuf(char *ptr, size_t size, char *pstart = NULL);
  37.     ~strstreambuf();
  38.     int frozen() { return _frozen; }
  39.     void freeze(int n=1) { _frozen = n != 0; }
  40.     size_t pcount();
  41.     char *str();
  42. };
  43.  
  44. class istrstream : public istream {
  45.   public:
  46.     istrstream(char*);
  47.     istrstream(char*, size_t);
  48.     ~istrstream();
  49.     strstreambuf* rdbuf() { return (strstreambuf*)_strbuf; }
  50. };
  51.  
  52. class ostrstream : public ostream {
  53.   public:
  54.     ostrstream();
  55.     ostrstream(char *cp, size_t n, int mode=ios::out);
  56.     ~ostrstream();
  57.     size_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); }
  58.     char *str() { return ((strstreambuf*)_strbuf)->str(); }
  59.     void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); }
  60.     int frozen() { return ((strstreambuf*)_strbuf)->frozen(); }
  61.     strstreambuf* rdbuf() { return (strstreambuf*)_strbuf; }
  62. };
  63.  
  64. #endif /*!__STRSTREAM_H*/
  65.