home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-18 | 3.0 KB | 114 lines | [TEXT/MMCC] |
- // strstream standard header
- #ifndef _STRSTREAM_
- #define _STRSTREAM_
- #include <istream>
- #include <ostream>
-
- #if __MWERKS__
- #pragma options align=mac68k
- #endif
-
- // constants
- const int _ALSIZE = 512; // default allocation size
- const int _MINSIZE = 32; // minimum allocation size
- // class strstreambuf
- class strstreambuf : public streambuf {
- public:
- enum __Strstate {_Allocated = 1, _Constant = 2,
- _Dynamic = 4, _Frozen = 8, _Noread = 16,
- _Strzero = 0};
- _BITMASK(__Strstate, _Strstate);
- strstreambuf(int _N = 0)
- {_Init(_N); }
- strstreambuf(void *(*_A)(size_t), void (*_F)(void *))
- {_Init(), _Palloc = _A, _Pfree = _F; }
- strstreambuf(char *_G, int _N, char *_P = 0,
- _Strstate _S = _Strzero)
- {_Init(_N, _G, _P, _S); }
- strstreambuf(unsigned char *_G, int _N,
- unsigned char *_P = 0)
- {_Init(_N, (char *)_G, (char *)_P); }
- strstreambuf(const char *_G, int _N)
- {_Init(_N, (char *)_G, 0, _Constant); }
- strstreambuf(const unsigned char *_G, int _N)
- {_Init(_N, (char *)_G, 0, _Constant); }
- virtual ~strstreambuf();
- void freeze(int = 1);
- char *str()
- {freeze(); return (gptr()); }
- int pcount() const
- {return (pptr() == 0 ? 0 : pptr() - pbase()); }
- #if _SIGNED_CHAR_IS_DISTINCT
- strstreambuf(signed char *_G, int _N, signed char *_P = 0)
- {_Init(_N, (char *)_G, (char *)_P); }
- strstreambuf(const signed char *_G, int _N)
- {_Init(_N, (char *)_G, 0, _Constant); }
- #endif /* _SIGNED_CHAR_IS_DISTINCT */
- protected:
- virtual int overflow(int = EOF);
- virtual int pbackfail(int = EOF);
- virtual int underflow();
- virtual streampos seekoff(streamoff, ios::seekdir,
- ios::openmode = ios::in | ios::out);
- virtual streampos seekpos(streampos,
- ios::openmode = ios::in | ios::out);
- void _Init(int = 0, char * = 0, char * = 0,
- _Strstate = _Strzero);
- void _Tidy();
- _Strstate _Strmode;
- private:
- char *_Pendsave, *_Seekhigh;
- int _Alsize;
- void *(*_Palloc)(size_t);
- void (*_Pfree)(void *);
- };
- // class istrstream
- class istrstream : public istream {
- public:
- istrstream(const char *_S)
- : ios(&_Sb), istream(&_Sb), _Sb(_S, 0) {}
- istrstream(const char *_S, int _N)
- : ios(&_Sb), istream(&_Sb), _Sb(_S, _N) {}
- istrstream(char *_S)
- : ios(&_Sb), istream(&_Sb), _Sb((const char *)_S, 0) {}
- istrstream(char *_S, int _N)
- : ios(&_Sb), istream(&_Sb), _Sb((const char *)_S, _N) {}
- virtual ~istrstream();
- strstreambuf *rdbuf() const
- {return ((strstreambuf *)&_Sb); }
- char *str()
- {return (_Sb.str()); }
- private:
- strstreambuf _Sb;
- };
- // class ostrstream
- class ostrstream : public ostream {
- public:
- ostrstream()
- : ios(&_Sb), ostream(&_Sb), _Sb() {}
- ostrstream(char *, int, openmode = out);
- virtual ~ostrstream();
- strstreambuf *rdbuf() const
- {return ((strstreambuf *)&_Sb); }
- void freeze(int _F = 1)
- {_Sb.freeze(_F); }
- char *str()
- {return (_Sb.str()); }
- int pcount() const
- {return (_Sb.pcount()); }
- private:
- strstreambuf _Sb;
- };
-
- #if __MWERKS__
- #pragma options align=reset
- #endif
-
- #endif
-
- /*
- * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
- * Consult your license regarding permissions and restrictions.
- */
-
-