Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
gzstreambuf Class Reference

#include <gzstream.h>

Inheritance diagram for gzstreambuf:

Public Member Functions

 gzstreambuf ()
 
int is_open () const
 
 ~gzstreambuf ()
 
gzstreambufopen (const char *name, int open_mode)
 
gzstreambufclose ()
 
virtual int underflow ()
 
virtual int overflow (int c=EOF)
 
virtual int sync ()
 

Private Member Functions

int flush_buffer ()
 

Private Attributes

gzFile file
 
char buffer [bufferSize]
 
char opened
 
int mode
 

Static Private Attributes

static const int bufferSize = 47+256
 

Detailed Description

Author
mdejong

Definition at line 51 of file gzstream.h.

Constructor & Destructor Documentation

◆ gzstreambuf()

gzstreambuf::gzstreambuf ( )
inline

Definition at line 72 of file gzstream.h.

72 : opened(0) {
73 setp( buffer, buffer + (bufferSize-1));
74 setg( buffer + 4, // beginning of putback area
75 buffer + 4, // read position
76 buffer + 4); // end position
77 // ASSERT: both input & output capabilities will not be used together
78 }
char opened
Definition gzstream.h:58
static const int bufferSize
Definition gzstream.h:53
char buffer[bufferSize]
Definition gzstream.h:57

◆ ~gzstreambuf()

gzstreambuf::~gzstreambuf ( )
inline

Definition at line 81 of file gzstream.h.

81{ close(); }
gzstreambuf * close()
Definition gzstream.h:108

Member Function Documentation

◆ flush_buffer()

int gzstreambuf::flush_buffer ( )
inlineprivate

Definition at line 62 of file gzstream.h.

62 {
63 // Separate the writing of the buffer from overflow() and
64 // sync() operation.
65 int w = pptr() - pbase();
66 if ( gzwrite( file, pbase(), w) != w)
67 return EOF;
68 pbump( -w);
69 return w;
70 }
gzFile file
Definition gzstream.h:56

◆ is_open()

int gzstreambuf::is_open ( ) const
inline

Definition at line 79 of file gzstream.h.

79{ return opened; }

◆ open()

gzstreambuf * gzstreambuf::open ( const char * name,
int open_mode )
inline

Definition at line 82 of file gzstream.h.

82 {
83 if ( is_open())
84 return (gzstreambuf*)0;
85 mode = open_mode;
86 // no append nor read/write mode
87 if ((mode & std::ios::ate) || (mode & std::ios::app)
88 || ((mode & std::ios::in) && (mode & std::ios::out)))
89 return (gzstreambuf*)0;
90 char fmode[10];
91 char* fmodeptr = fmode;
92 if ( mode & std::ios::in)
93 *fmodeptr++ = 'r';
94 else if ( mode & std::ios::out)
95 *fmodeptr++ = 'w';
96 *fmodeptr++ = 'b';
97 *fmodeptr = '\0';
98 file = gzopen( name, fmode);
99 if (file == 0)
100 return (gzstreambuf*)0;
101 opened = 1;
102 setg( buffer + 4, // beginning of putback area
103 buffer + 4, // read position
104 buffer + 4); // end position
105 return this;
106 }
int is_open() const
Definition gzstream.h:79

◆ close()

gzstreambuf * gzstreambuf::close ( )
inline

Definition at line 108 of file gzstream.h.

108 {
109 if ( is_open()) {
110 sync();
111 opened = 0;
112 if ( gzclose( file) == Z_OK)
113 return this;
114 }
115 return (gzstreambuf*)0;
116 }
virtual int sync()
Definition gzstream.h:155

◆ underflow()

virtual int gzstreambuf::underflow ( )
inlinevirtual

Definition at line 118 of file gzstream.h.

118 { // used for input buffer only
119 if ( gptr() && ( gptr() < egptr()))
120 return * reinterpret_cast<unsigned char *>( gptr());
121
122 if ( ! (mode & std::ios::in) || ! opened)
123 return EOF;
124 // Josuttis' implementation of inbuf
125 int n_putback = gptr() - eback();
126 if ( n_putback > 4)
127 n_putback = 4;
128 memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback);
129
130 int num = gzread( file, buffer+4, bufferSize-4);
131 if (num <= 0) // ERROR or EOF
132 return EOF;
133
134 // reset buffer pointers
135 setg( buffer + (4 - n_putback), // beginning of putback area
136 buffer + 4, // read position
137 buffer + 4 + num); // end of buffer
138
139 // return next character
140 return * reinterpret_cast<unsigned char *>( gptr());
141 }

◆ overflow()

virtual int gzstreambuf::overflow ( int c = EOF)
inlinevirtual

Definition at line 143 of file gzstream.h.

143 { // used for output buffer only
144 if ( ! ( mode & std::ios::out) || ! opened)
145 return EOF;
146 if (c != EOF) {
147 *pptr() = c;
148 pbump(1);
149 }
150 if ( flush_buffer() == EOF)
151 return EOF;
152 return c;
153 }
int flush_buffer()
Definition gzstream.h:62

◆ sync()

virtual int gzstreambuf::sync ( )
inlinevirtual

Definition at line 155 of file gzstream.h.

155 {
156 // Changed to use flush_buffer() instead of overflow( EOF)
157 // which caused improper behavior with std::endl and flush(),
158 // bug reported by Vincent Ricard.
159 if ( pptr() && pptr() > pbase()) {
160 if ( flush_buffer() == EOF)
161 return -1;
162 }
163 return 0;
164 }

Member Data Documentation

◆ bufferSize

const int gzstreambuf::bufferSize = 47+256
staticprivate

Definition at line 53 of file gzstream.h.

◆ file

gzFile gzstreambuf::file
private

Definition at line 56 of file gzstream.h.

◆ buffer

char gzstreambuf::buffer[bufferSize]
private

Definition at line 57 of file gzstream.h.

◆ opened

char gzstreambuf::opened
private

Definition at line 58 of file gzstream.h.

◆ mode

int gzstreambuf::mode
private

Definition at line 59 of file gzstream.h.


The documentation for this class was generated from the following file: