limit fstBC to 30bp in Python3 ver.
[GalaxyCodeBases.git] / BGI / SOAPsnp / gzstream.h
blobc4cee4fcdcaa32d08f1ed46944aeca9ff145d54d
1 // ============================================================================
2 // gzstream, C++ iostream classes wrapping the zlib compression library.
3 // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // ============================================================================
20 // File : gzstream.h
21 // Revision : $Revision: 1.5 $
22 // Revision_date : $Date: 2002/04/26 23:30:15 $
23 // Author(s) : Deepak Bandyopadhyay, Lutz Kettner
24 //
25 // Standard streambuf implementation following Nicolai Josuttis, "The
26 // Standard C++ Library".
27 // ============================================================================
29 #ifndef GZSTREAM_H
30 #define GZSTREAM_H 1
32 // standard C++ with new header file names and std:: namespace
33 #include <iostream>
34 #include <fstream>
35 //#include <ostream>
36 #include <zlib.h>
37 #include <boost/iostreams/filtering_stream.hpp>
38 #include <boost/iostreams/filter/gzip.hpp>
39 #include <boost/iostreams/device/file.hpp>
41 #ifdef GZSTREAM_NAMESPACE
42 namespace GZSTREAM_NAMESPACE {
43 #endif
45 // ----------------------------------------------------------------------------
46 // Internal classes to implement gzstream. See below for user classes.
47 // ----------------------------------------------------------------------------
49 class gzstreambuf : public std::streambuf {
50 private:
51 static const int bufferSize = 47+256; // size of data buff
52 // totals 512 bytes under g++ for igzstream at the end.
54 gzFile file; // file handle for compressed file
55 char buffer[bufferSize]; // data buffer
56 int opened; // open/close state of stream
57 int mode; // I/O mode
59 int flush_buffer();
60 public:
61 gzstreambuf() : opened(0)
63 setp( buffer, buffer + (bufferSize-1));
64 setg( buffer + 4, // beginning of putback area
65 buffer + 4, // read position
66 buffer + 4); // end position
67 // ASSERT: both input & output capabilities will not be used together
69 int is_open()
71 return opened;
73 gzstreambuf* open( const char* name, int open_mode);
74 gzstreambuf* close();
75 ~gzstreambuf() { close(); }
77 virtual int overflow( int c = EOF);
78 virtual int underflow();
79 virtual int sync();
80 gzstreambuf& operator=(const gzstreambuf& gzs);
83 class gzstreambase : virtual public std::ios
85 protected:
86 gzstreambuf buf;
87 public:
88 gzstreambase()
90 init(&buf);
92 gzstreambase( const char* name, int open_mode);
93 ~gzstreambase();
94 int is_open()
96 return buf.is_open();
98 void open( const char* name, int open_mode);
99 void close();
100 gzstreambuf* rdbuf()
102 return &buf;
104 gzstreambase& operator=(const gzstreambase& gzst);
107 // ----------------------------------------------------------------------------
108 // User classes. Use igzstream and ogzstream analogously to ifstream and
109 // ofstream respectively. They read and write files based on the gz*
110 // function interface of the zlib. Files are compatible with gzip compression.
111 // ----------------------------------------------------------------------------
113 class igzstream : public gzstreambase, public std::istream
115 public:
116 igzstream() : std::istream( &buf)
118 /*gzstreambase::init(&buf);*/
120 igzstream( const char* name, int open_mode = std::ios::in)
121 : gzstreambase( name, open_mode), std::istream( &buf)
123 /*gzstreambase::init(&buf);*/
125 gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
126 void open( const char* name, int open_mode = std::ios::in)
128 gzstreambase::open( name, open_mode);
132 class ogzstream : public gzstreambase, public std::ostream
134 public:
135 ogzstream() : std::ostream( &buf)
137 /*gzstreambase::init(&buf);*/
139 ogzstream( const char* name, int mode = std::ios::out)
140 : gzstreambase( name, mode), std::ostream( &buf)
142 /*gzstreambase::init(&buf);*/
144 gzstreambuf* rdbuf()
146 return gzstreambase::rdbuf();
148 void open( const char* name, int open_mode = std::ios::out)
150 gzstreambase::open( name, open_mode);
152 ogzstream& operator=(const ogzstream& ogzst);
156 class myfstream
158 public:
159 virtual void open(const char* name, int open_mode = std::ios::out) = 0;
160 virtual void close() = 0;
161 virtual void clear() = 0;
162 virtual bool good() =0;
163 virtual std::ostream& flush() =0;
164 virtual std::ostream& endl() =0;
165 virtual void write(const char* name, int streamsizecount) =0;
166 virtual int is_open() = 0;
167 virtual myfstream & operator<<(const double value) = 0;
168 virtual myfstream & operator<<(const char* value) = 0;
169 virtual myfstream & operator<<(const char value) = 0;
170 virtual myfstream & operator<<(const unsigned char value) = 0;
171 virtual myfstream & operator<<(const std::string & value) = 0;
172 virtual myfstream & operator<<(const int value) = 0;
173 virtual myfstream & operator<<(const int* value) = 0;
174 virtual myfstream & operator<<(const unsigned int value) = 0;
175 virtual myfstream & operator<<(const float value) = 0;
176 virtual int set_f(std::ios_base::fmtflags value) = 0;
177 //virtual ostream & operator<<(std::ostream& value) = 0;
178 //virtual myfstream & operator<< (std::ostream& (__cdecl *fun) (ostream& value)) =0;
183 * a class to use ofstream.
186 class myofstream : public myfstream
188 private:
189 std::ofstream ogz;
190 public:
191 myofstream() : ogz(){}
192 myofstream(const char * name, int mode = std::ios::out)
193 :ogz(name){}
194 virtual inline void open( const char* name, int open_mode = std::ios::out)
196 ogz.open(name);
198 virtual inline void close()
200 ogz.close();
202 virtual inline void write(const char* name, int streamsizecount )
204 ogz.write(name, streamsizecount);
206 virtual inline std::ostream& flush()
208 return ogz.flush();
210 virtual inline std::ostream& endl()
212 ogz << "\n";
213 return ogz.flush();
215 virtual inline void clear()
217 ogz.clear();
219 virtual inline bool good()
221 return ogz.good();
223 virtual inline int is_open()
225 return ogz.is_open();
228 virtual inline myofstream & operator<<(const double value)
230 ogz << value;
231 return *this;
233 virtual inline myofstream & operator<<(const char * value)
235 ogz << value;
236 return *this;
238 virtual inline myofstream & operator<<(const int value)
240 ogz << value;
241 return *this;
243 virtual inline myofstream & operator<<(const int* value)
245 ogz << value;
246 return *this;
248 virtual inline myofstream & operator<<(const unsigned int value)
250 ogz << value;
251 return *this;
253 virtual inline myofstream & operator<<(const char value)
255 ogz << value;
256 return *this;
258 virtual inline myofstream & operator<<(const unsigned char value)
260 ogz << value;
261 return *this;
263 virtual inline myofstream & operator<<(const std::string & value)
265 ogz << value;
266 return *this;
268 virtual inline myofstream & operator<<(const float value)
270 ogz << value;
271 return *this;
273 virtual inline int set_f(std::ios_base::fmtflags value)
275 return ogz.setf(value);
277 /*virtual inline myofstream & operator<<(const std::ios& value)
279 ogz << value;
280 return *this;
282 /*virtual myofstream& operator<< (std::ostream& (__cdecl *fun)(ostream& value))
284 (*fun)(*this);
285 return *this;
291 * a class to use ogzstream.
294 class myogzstream : public myfstream
296 private:
297 ogzstream ogz;
298 public:
299 myogzstream() : ogz(){}
300 myogzstream(const char * name, int mode = std::ios::out)
301 :ogz(name, mode){}
302 virtual inline void open( const char* name, int open_mode = std::ios::out)
304 ogz.open(name, open_mode);
306 virtual inline void close()
308 ogz.close();
310 virtual inline bool good()
312 return ogz.good();
314 virtual inline void write(const char* name, int streamsizecount)
316 ogz.write(name,streamsizecount);
318 virtual inline void clear()
320 ogz.clear();
322 virtual std::ostream& flush()
324 return ogz.flush();
326 virtual std::ostream& endl()
328 ogz<<"\n";
329 return ogz.flush();
331 virtual inline int is_open()
333 return ogz.is_open();
336 virtual inline myogzstream & operator<<(const double value)
338 ogz << value;
339 return *this;
341 virtual inline myogzstream & operator<<(const char * value)
343 ogz << value;
344 return *this;
346 virtual inline myogzstream & operator<<(const int value)
348 ogz << value;
349 return *this;
351 virtual inline myogzstream & operator<<(const int* value)
353 ogz << value;
354 return *this;
356 virtual inline myogzstream & operator<<(const unsigned int value)
358 ogz << value;
359 return *this;
361 virtual inline myogzstream & operator<<(const char value)
363 ogz << value;
364 return *this;
366 virtual inline myogzstream & operator<<(const unsigned char value)
368 ogz << value;
369 return *this;
371 virtual inline myogzstream & operator<<(const std::string & value)
373 ogz << value;
374 return *this;
376 virtual inline myogzstream & operator<<(const float value)
378 ogz << value;
379 return *this;
381 virtual inline int set_f(std::ios_base::fmtflags value)
383 return ogz.setf(value);
385 /*virtual inline myogzstream & operator<<(const std::ios& value)
387 ogz << value;
388 return *this;
390 /*virtual myogzstream& operator<< (std::ostream& (__cdecl *fun)(ostream& value))
392 (*fun)(*this);
393 return *this;
397 #ifdef GZSTREAM_NAMESPACE
398 } // namespace GZSTREAM_NAMESPACE
399 #endif
401 #endif // GZSTREAM_H
402 // ============================================================================
403 // EOF //