gzfilterstream.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa Akiyama
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_GZ_GZFILTERSTREAM_H
00033 #define RCSC_GZ_GZFILTERSTREAM_H
00034 
00035 #include <boost/scoped_ptr.hpp>
00036 #include <iostream>
00037 
00038 namespace rcsc {
00039 
00040 struct gzfilterstreambuf_impl;
00041 
00043 
00048 class gzfilterstreambuf
00049     : public std::streambuf {
00050 public:
00060     enum CompressionLevel {
00061         DEFAULT_COMPRESSION = 6,
00062         NO_COMPRESSION = 0,
00063         BEST_SPEED = 1,
00064         BEST_COMPRESSION = 9,
00065     };
00066 
00070     enum FlushType {
00071         NO_FLUSH = 0,
00072         PARTIAL_FLUSH  = 1, // will be removed, use SYNC_FLUSH instead
00073         SYNC_FLUSH = 2,
00074         FULL_FLUSH = 3,
00075         FINISH = 4
00076     };
00077 
00078 private:
00080     std::streambuf & M_strmbuf;
00082     std::ostream * M_output_stream;
00084     std::istream * M_input_stream;
00086     std::streamsize M_buf_size;
00088     char_type * M_read_buf;
00090     char_type * M_input_buf;
00092     char_type * M_output_buf;
00094     char_type * M_write_buf;
00095 
00097     boost::scoped_ptr< gzfilterstreambuf_impl > M_impl;
00102     int M_level;
00103 
00105     gzfilterstreambuf( const gzfilterstreambuf & );
00107     gzfilterstreambuf & operator=( const gzfilterstreambuf & );
00108 
00109 public:
00110 
00120     explicit
00121     gzfilterstreambuf( std::streambuf & strm,
00122                        int level = DEFAULT_COMPRESSION,
00123                        std::size_t buf_size = 8192 );
00124 
00130     ~gzfilterstreambuf();
00131 
00139     bool setLevel( const int level );
00140 
00141 protected:
00142 
00148     bool writeData( int flush_type = NO_FLUSH );
00149 
00156     int readData( char * dest,
00157                   int & dest_size );
00158 
00165     virtual
00166     int_type overflow( int_type c );
00167 
00173     virtual
00174     int sync();
00175 
00182     virtual
00183     int_type underflow();
00184 };
00185 
00187 
00192 class gzfilterstream
00193     : public std::iostream {
00194 private:
00196     gzfilterstreambuf M_filter_buf;
00197 
00199     gzfilterstream( const gzfilterstream & );
00201     gzfilterstream & operator=( const gzfilterstream & );
00202 
00203 public:
00210     explicit
00211     gzfilterstream( std::streambuf & strmbuf,
00212                     int level = gzfilterstreambuf::DEFAULT_COMPRESSION,
00213                     std::size_t buf_size = 8192 );
00214 
00221     explicit
00222     gzfilterstream( std::iostream & strm,
00223                     int level = gzfilterstreambuf::DEFAULT_COMPRESSION,
00224                     std::size_t buf_size = 8192 );
00225 
00233     bool setLevel( const int level )
00234       {
00235           return M_filter_buf.setLevel( level );
00236       }
00237 
00238 };
00239 
00241 
00246 class gzifilterstream
00247     : public std::istream {
00248 private:
00250     gzfilterstreambuf M_filter_buf;
00251 
00253     gzifilterstream( const gzifilterstream & );
00255     gzifilterstream & operator=( const gzifilterstream & );
00256 
00257 public:
00264     explicit
00265     gzifilterstream( std::streambuf & src,
00266                      int level = gzfilterstreambuf::DEFAULT_COMPRESSION,
00267                      std::size_t buf_size = 8192 );
00268 
00275     explicit
00276     gzifilterstream( std::istream & src,
00277                      int level = gzfilterstreambuf::DEFAULT_COMPRESSION,
00278                      std::size_t buf_size = 8192 );
00279 
00287     bool setLevel( const int level )
00288       {
00289           return M_filter_buf.setLevel( level );
00290       }
00291 
00292 };
00293 
00295 
00300 class gzofilterstream
00301     : public std::ostream {
00302 private:
00304     gzfilterstreambuf M_filter_buf;
00305 
00307     gzofilterstream( const gzofilterstream & );
00309     gzofilterstream & operator=( const gzofilterstream & );
00310 public:
00311 
00318     explicit
00319     gzofilterstream( std::streambuf & dest,
00320                      int level = gzfilterstreambuf::DEFAULT_COMPRESSION,
00321                      std::size_t buf_size = 8192 );
00322 
00329     explicit
00330     gzofilterstream( std::ostream & dest,
00331                      int level = gzfilterstreambuf::DEFAULT_COMPRESSION,
00332                      std::size_t buf_size = 8192 );
00333 
00341     bool setLevel( const int level )
00342       {
00343           return M_filter_buf.setLevel( level );
00344       }
00345 
00346 };
00347 
00348 } // end namespace
00349 
00350 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0