#ifndef __STRSTREAM_H
#define __STRSTREAM_H
#ifdef __GNUG__
#pragma interface
#endif
#include <iostream.h>
#include <strfile.h>
extern "C++" {
class strstreambuf : public streambuf
{
struct _IO_str_fields _s;
friend class istrstream;
void init_dynamic(_IO_alloc_type alloc, _IO_free_type free,
int initial_size = 0);
void init_static(char *ptr, int size, char *pstart);
void init_readonly(const char *ptr, int size);
protected:
virtual int overflow(int = EOF);
virtual int underflow();
virtual int pbackfail(int c);
public:
virtual ~strstreambuf();
strstreambuf() { init_dynamic(0, 0); }
strstreambuf(int initial_size) { init_dynamic(0, 0, initial_size); }
strstreambuf(void *(*alloc)(_IO_size_t), void (*free)(void*))
{ init_dynamic(alloc, free); }
strstreambuf(char *ptr, int size, char *pstart = NULL)
{ init_static(ptr, size, pstart); }
strstreambuf(unsigned char *ptr, int size, unsigned char *pstart = NULL)
{ init_static((char*)ptr, size, (char*)pstart); }
strstreambuf(const char *ptr, int size)
{ init_readonly(ptr, size); }
strstreambuf(const unsigned char *ptr, int size)
{ init_readonly((const char*)ptr, size); }
strstreambuf(signed char *ptr, int size, signed char *pstart = NULL)
{ init_static((char*)ptr, size, (char*)pstart); }
strstreambuf(const signed char *ptr, int size)
{ init_readonly((const char*)ptr, size); }
int frozen() { return _flags & _IO_USER_BUF ? 1 : 0; }
void freeze(int n=1)
{ if (_IO_STR_DYNAMIC(this))
{ if (n) _flags |= _IO_USER_BUF; else _flags &= ~_IO_USER_BUF; } }
_IO_ssize_t pcount();
char *str();
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
};
class strstreambase : virtual public ios {
protected:
strstreambuf __my_sb;
public:
strstreambuf* rdbuf() { return &__my_sb; }
protected:
strstreambase() { init (&__my_sb); }
strstreambase(char *cp, int n, int mode=ios::out);
};
class istrstream : public strstreambase, public istream {
public:
istrstream(const char*, int=0);
};
class ostrstream : public strstreambase, public ostream {
public:
ostrstream() { }
ostrstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){}
_IO_ssize_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); }
char *str() { return ((strstreambuf*)_strbuf)->str(); }
void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); }
int frozen() { return ((strstreambuf*)_strbuf)->frozen(); }
};
class strstream : public strstreambase, public iostream {
public:
strstream() { }
strstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){}
_IO_ssize_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); }
char *str() { return ((strstreambuf*)_strbuf)->str(); }
void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); }
int frozen() { return ((strstreambuf*)_strbuf)->frozen(); }
};
}
#endif