13 #include "Pythia8/Streams.h"
25 gzstreambuf* gzstreambuf::open(
const char* name,
int open_mode) {
27 return (gzstreambuf*)0;
30 if ((mode & std::ios::ate) || (mode & std::ios::app)
31 || ((mode & std::ios::in) && (mode & std::ios::out)))
32 return (gzstreambuf*)0;
34 char* fmodeptr = fmode;
35 if ( mode & std::ios::in)
37 else if ( mode & std::ios::out)
41 file = gzopen( name, fmode);
43 return (gzstreambuf*)0;
50 gzstreambuf * gzstreambuf::close() {
54 if ( gzclose( file) == Z_OK)
57 return (gzstreambuf*)0;
62 int gzstreambuf::underflow() {
63 if ( gptr() && ( gptr() < egptr()))
64 return *
reinterpret_cast<unsigned char *
>( gptr());
66 if ( ! (mode & std::ios::in) || ! opened)
69 int n_putback = gptr() - eback();
72 memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback);
74 int num = gzread( file, buffer+4, bufferSize-4);
79 setg( buffer + (4 - n_putback),
84 return *
reinterpret_cast<unsigned char *
>( gptr());
89 int gzstreambuf::flush_buffer() {
92 int w = pptr() - pbase();
93 if ( gzwrite( file, pbase(), w) != w)
101 int gzstreambuf::overflow(
int c) {
102 if ( ! ( mode & std::ios::out) || ! opened)
108 if ( flush_buffer() == EOF)
115 int gzstreambuf::sync() {
119 if ( pptr() && pptr() > pbase()) {
120 if ( flush_buffer() == EOF)
132 gzstreambase::gzstreambase(
const char* name,
int mode) {
139 gzstreambase::~gzstreambase() {
145 void gzstreambase::open(
const char* name,
int mode) {
146 if ( ! buf.open( name, mode))
147 clear( rdstate() | std::ios::badbit);
152 void gzstreambase::close() {
155 clear( rdstate() | std::ios::badbit);
163 double DummyForStreams::xtox(
double x) {
return x;}