|
||||
File indexing completed on 2024-09-28 07:02:49
0001 // ============================================================================ 0002 // gzstream, C++ iostream classes wrapping the zlib compression library. 0003 // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner 0004 // 0005 // This library is free software; you can redistribute it and/or 0006 // modify it under the terms of the GNU Lesser General Public 0007 // License as published by the Free Software Foundation; either 0008 // version 2.1 of the License, or (at your option) any later version. 0009 // 0010 // This library is distributed in the hope that it will be useful, 0011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 // Lesser General Public License for more details. 0014 // 0015 // You should have received a copy of the GNU Lesser General Public 0016 // License along with this library; if not, write to the Free Software 0017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0018 // ============================================================================ 0019 // 0020 // File : gzstream.h 0021 // Revision : $Revision: 1.5 $ 0022 // Revision_date : $Date: 2002/04/26 23:30:15 $ 0023 // Author(s) : Deepak Bandyopadhyay, Lutz Kettner 0024 // 0025 // Standard streambuf implementation following Nicolai Josuttis, "The 0026 // Standard C++ Library". 0027 // ============================================================================ 0028 0029 #ifndef GZSTREAM_H 0030 #define GZSTREAM_H 1 0031 0032 // standard C++ with new header file names and std:: namespace 0033 #include <iostream> 0034 #include <fstream> 0035 #include <zlib.h> 0036 0037 #ifdef GZSTREAM_NAMESPACE 0038 namespace GZSTREAM_NAMESPACE { 0039 #endif 0040 0041 // ---------------------------------------------------------------------------- 0042 // Internal classes to implement gzstream. See below for user classes. 0043 // ---------------------------------------------------------------------------- 0044 0045 class gzstreambuf : public std::streambuf { 0046 private: 0047 static const int bufferSize = 47+256; // size of data buff 0048 // totals 512 bytes under g++ for igzstream at the end. 0049 0050 gzFile file; // file handle for compressed file 0051 char buffer[bufferSize]; // data buffer 0052 char opened; // open/close state of stream 0053 int mode; // I/O mode 0054 0055 int flush_buffer(); 0056 public: 0057 gzstreambuf() : opened(0) { 0058 setp( buffer, buffer + (bufferSize-1)); 0059 setg( buffer + 4, // beginning of putback area 0060 buffer + 4, // read position 0061 buffer + 4); // end position 0062 // ASSERT: both input & output capabilities will not be used together 0063 } 0064 int is_open() { return opened; } 0065 gzstreambuf* open( const char* name, int open_mode); 0066 gzstreambuf* close(); 0067 ~gzstreambuf() { close(); } 0068 0069 virtual int overflow( int c = EOF); 0070 virtual int underflow(); 0071 virtual int sync(); 0072 }; 0073 0074 class gzstreambase : virtual public std::ios { 0075 protected: 0076 gzstreambuf buf; 0077 public: 0078 gzstreambase() { init(&buf); } 0079 gzstreambase( const char* name, int open_mode); 0080 ~gzstreambase(); 0081 void open( const char* name, int open_mode); 0082 void close(); 0083 gzstreambuf* rdbuf() { return &buf; } 0084 }; 0085 0086 // ---------------------------------------------------------------------------- 0087 // User classes. Use igzstream and ogzstream analogously to ifstream and 0088 // ofstream respectively. They read and write files based on the gz* 0089 // function interface of the zlib. Files are compatible with gzip compression. 0090 // ---------------------------------------------------------------------------- 0091 0092 class igzstream : public gzstreambase, public std::istream { 0093 public: 0094 igzstream() : std::istream( &buf) {} 0095 igzstream( const char* name, int open_mode = std::ios::in) 0096 : gzstreambase( name, open_mode), std::istream( &buf) {} 0097 gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); } 0098 void open( const char* name, int open_mode = std::ios::in) { 0099 gzstreambase::open( name, open_mode); 0100 } 0101 }; 0102 0103 class ogzstream : public gzstreambase, public std::ostream { 0104 public: 0105 ogzstream() : std::ostream( &buf) {} 0106 ogzstream( const char* name, int mode = std::ios::out) 0107 : gzstreambase( name, mode), std::ostream( &buf) {} 0108 gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); } 0109 void open( const char* name, int open_mode = std::ios::out) { 0110 gzstreambase::open( name, open_mode); 0111 } 0112 }; 0113 0114 #ifdef GZSTREAM_NAMESPACE 0115 } // namespace GZSTREAM_NAMESPACE 0116 #endif 0117 0118 #endif // GZSTREAM_H 0119 // ============================================================================ 0120 // EOF // 0121
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |