Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/libdar/wrapperlib.hpp
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00032 
00033 #ifndef WRAPPERLIB_HPP
00034 #define WRAPPERLIB_HPP
00035 
00036 #include "../my_config.h"
00037 
00038 extern "C"
00039 {
00040 #if HAVE_ZLIB_H && LIBZ_AVAILABLE
00041 #include <zlib.h>
00042 #endif
00043 
00044 #if HAVE_BZLIB_H && LIBBZ2_AVAILABLE
00045 #include <bzlib.h>
00046 #endif
00047 } // end extern "C"
00048 
00049 #include "integers.hpp"
00050 
00051 namespace libdar
00052 {
00053 
00056 
00057     const int WR_OK            = 0;
00058     const int WR_MEM_ERROR     = 1;
00059     const int WR_VERSION_ERROR = 2;
00060     const int WR_STREAM_ERROR  = 3;
00061     const int WR_DATA_ERROR    = 4;
00062     const int WR_NO_FLUSH      = 5;
00063     const int WR_BUF_ERROR     = 6;
00064     const int WR_STREAM_END    = 7;
00065     const int WR_FINISH        = 8;
00066 
00067     enum wrapperlib_mode { zlib_mode, bzlib_mode };
00068 
00070 
00074 
00075     class wrapperlib
00076     {
00077     public:
00078         wrapperlib(wrapperlib_mode mode);
00079         wrapperlib(const wrapperlib & ref);
00080         const wrapperlib & operator = (const wrapperlib & ref);
00081         ~wrapperlib();
00082 
00083         void set_next_in(const char *x) { return (this->*x_set_next_in)(x); };
00084         void set_avail_in(U_I x) { return (this->*x_set_avail_in)(x); };
00085         U_I get_avail_in() const { return (this->*x_get_avail_in)(); };
00086         U_64 get_total_in() const { return (this->*x_get_total_in)(); };
00087 
00088         void set_next_out(char *x) { return (this->*x_set_next_out)(x); };
00089         char *get_next_out() const { return (this->*x_get_next_out)(); };
00090         void set_avail_out(U_I x) { return (this->*x_set_avail_out)(x); };
00091         U_I get_avail_out() const { return (this->*x_get_avail_out)(); };
00092         U_64 get_total_out() const { return (this->*x_get_total_out)(); };
00093 
00094         S_I compressInit(U_I compression_level) { level = compression_level; return (this->*x_compressInit)(compression_level); };
00095         S_I decompressInit() { return (this->*x_decompressInit)(); };
00096         S_I compressEnd() { return (this->*x_compressEnd)(); };
00097         S_I decompressEnd() { return (this->*x_decompressEnd)(); };
00098         S_I compress(S_I flag) { return (this->*x_compress)(flag); };
00099         S_I decompress(S_I flag) { return (this->*x_decompress)(flag);};
00100         S_I compressReset();
00101         S_I decompressReset();
00102 
00103     private:
00104 #if LIBZ_AVAILABLE
00105         z_stream *z_ptr;
00106 #endif
00107 #if LIBBZ2_AVAILABLE
00108         bz_stream *bz_ptr;
00109 #endif
00110         S_I level;
00111 
00112         void (wrapperlib::*x_set_next_in)(const char *x);
00113         void (wrapperlib::*x_set_avail_in)(U_I x);
00114         U_I (wrapperlib::*x_get_avail_in)() const;
00115         U_64 (wrapperlib::*x_get_total_in)() const;
00116 
00117         void (wrapperlib::*x_set_next_out)(char *x);
00118         char *(wrapperlib::*x_get_next_out)() const;
00119         void (wrapperlib::*x_set_avail_out)(U_I x);
00120         U_I (wrapperlib::*x_get_avail_out)() const;
00121         U_64 (wrapperlib::*x_get_total_out)() const;
00122 
00123         S_I (wrapperlib::*x_compressInit)(U_I compression_level);
00124         S_I (wrapperlib::*x_decompressInit)();
00125         S_I (wrapperlib::*x_compressEnd)();
00126         S_I (wrapperlib::*x_decompressEnd)();
00127         S_I (wrapperlib::*x_compress)(S_I flag);
00128         S_I (wrapperlib::*x_decompress)(S_I flag);
00129 
00130 
00131             // set of routines for zlib
00132 #if LIBZ_AVAILABLE
00133         S_I z_compressInit(U_I compression_level);
00134         S_I z_decompressInit();
00135         S_I z_compressEnd();
00136         S_I z_decompressEnd();
00137         S_I z_compress(S_I flag);
00138         S_I z_decompress(S_I flag);
00139         void z_set_next_in(const char *x);
00140         void z_set_avail_in(U_I x);
00141         U_I z_get_avail_in() const;
00142         U_64 z_get_total_in() const;
00143         void z_set_next_out(char *x);
00144         char *z_get_next_out() const;
00145         void z_set_avail_out(U_I x);
00146         U_I z_get_avail_out() const;
00147         U_64 z_get_total_out() const;
00148 #endif
00149 
00150             // set of routines for bzlib
00151 #if LIBBZ2_AVAILABLE
00152         S_I bz_compressInit(U_I compression_level);
00153         S_I bz_decompressInit();
00154         S_I bz_compressEnd();
00155         S_I bz_decompressEnd();
00156         S_I bz_compress(S_I flag);
00157         S_I bz_decompress(S_I flag);
00158         void bz_set_next_in(const char *x);
00159         void bz_set_avail_in(U_I x);
00160         U_I bz_get_avail_in() const;
00161         U_64 bz_get_total_in() const;
00162         void bz_set_next_out(char *x);
00163         char *bz_get_next_out() const;
00164         void bz_set_avail_out(U_I x);
00165         U_I bz_get_avail_out() const;
00166         U_64 bz_get_total_out() const;
00167 #endif
00168     };
00169 
00171 
00172 } // end of namespace
00173 
00174 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines