File indexing completed on 2025-01-18 10:06:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef Pythia8_Streams_H
0014 #define Pythia8_Streams_H
0015
0016 #include <cstddef>
0017 #include <iostream>
0018 #include <iomanip>
0019 #include <sstream>
0020 #include <fstream>
0021 #include <string.h>
0022 #ifdef GZIP
0023 #include <zlib.h>
0024 #endif
0025
0026 namespace Pythia8 {
0027
0028 #ifdef GZIP
0029
0030
0031
0032
0033
0034
0035
0036 class gzstreambuf : public std::streambuf {
0037 private:
0038 static const int bufferSize = 47+256;
0039
0040
0041 gzFile file{};
0042 char buffer[bufferSize]{};
0043 char opened{};
0044 int mode{};
0045
0046 int flush_buffer();
0047 public:
0048 gzstreambuf() : opened(0) {
0049 setp( buffer, buffer + (bufferSize-1));
0050 setg( buffer + 4,
0051 buffer + 4,
0052 buffer + 4);
0053
0054 }
0055 int is_open() { return opened; }
0056 gzstreambuf* open( const char* name, int open_mode);
0057 gzstreambuf* close();
0058 ~gzstreambuf() { close(); }
0059
0060 virtual int overflow( int c = EOF);
0061 virtual int underflow();
0062 virtual int sync();
0063 };
0064
0065
0066
0067 class gzstreambase : virtual public std::ios {
0068 protected:
0069 gzstreambuf buf;
0070 public:
0071 gzstreambase() { init(&buf); }
0072 gzstreambase( const char* name, int open_mode);
0073 ~gzstreambase();
0074 void open( const char* name, int open_mode);
0075 void close();
0076 gzstreambuf* rdbuf() { return &buf; }
0077 };
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 class igzstream : public gzstreambase, public std::istream {
0088 public:
0089 igzstream() : std::istream( &buf) {}
0090 igzstream( const char* name, int mode = std::ios::in)
0091 : gzstreambase( name, mode), std::istream( &buf) {}
0092 gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
0093 void open( const char* name, int mode = std::ios::in) {
0094 gzstreambase::open( name, mode);
0095 }
0096 };
0097
0098
0099 class ogzstream : public gzstreambase, public std::ostream {
0100 public:
0101 ogzstream() : std::ostream( &buf) {}
0102 ogzstream( const char* name, int mode = std::ios::out)
0103 : gzstreambase( name, mode), std::ostream( &buf) {}
0104 gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
0105 void open( const char* name, int mode = std::ios::out) {
0106 gzstreambase::open( name, mode);
0107 }
0108 };
0109
0110
0111
0112 #else
0113 typedef std::ifstream igzstream;
0114 typedef std::ofstream ogzstream;
0115 #endif
0116
0117
0118 class DummyForStreams {
0119 public:
0120 DummyForStreams() {}
0121 double xtox(double x);
0122 };
0123
0124
0125
0126 }
0127
0128 #endif