Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
wrapperlib.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 // $Id: wrapperlib.hpp,v 1.14 2011/01/09 17:25:58 edrusb Rel $
22 //
23 /*********************************************************************/
24 
32 
33 #ifndef WRAPPERLIB_HPP
34 #define WRAPPERLIB_HPP
35 
36 #include "../my_config.h"
37 
38 extern "C"
39 {
40 #if HAVE_ZLIB_H && LIBZ_AVAILABLE
41 #include <zlib.h>
42 #endif
43 
44 #if HAVE_BZLIB_H && LIBBZ2_AVAILABLE
45 #include <bzlib.h>
46 #endif
47 } // end extern "C"
48 
49 #include "integers.hpp"
50 
51 namespace libdar
52 {
53 
56 
57  const int WR_OK = 0;
58  const int WR_MEM_ERROR = 1;
59  const int WR_VERSION_ERROR = 2;
60  const int WR_STREAM_ERROR = 3;
61  const int WR_DATA_ERROR = 4;
62  const int WR_NO_FLUSH = 5;
63  const int WR_BUF_ERROR = 6;
64  const int WR_STREAM_END = 7;
65  const int WR_FINISH = 8;
66 
67  enum wrapperlib_mode { zlib_mode, bzlib_mode };
68 
70 
74 
75  class wrapperlib
76  {
77  public:
78  wrapperlib(wrapperlib_mode mode);
79  wrapperlib(const wrapperlib & ref);
80  const wrapperlib & operator = (const wrapperlib & ref);
81  ~wrapperlib();
82 
83  void set_next_in(const char *x) { return (this->*x_set_next_in)(x); };
84  void set_avail_in(U_I x) { return (this->*x_set_avail_in)(x); };
85  U_I get_avail_in() const { return (this->*x_get_avail_in)(); };
86  U_64 get_total_in() const { return (this->*x_get_total_in)(); };
87 
88  void set_next_out(char *x) { return (this->*x_set_next_out)(x); };
89  char *get_next_out() const { return (this->*x_get_next_out)(); };
90  void set_avail_out(U_I x) { return (this->*x_set_avail_out)(x); };
91  U_I get_avail_out() const { return (this->*x_get_avail_out)(); };
92  U_64 get_total_out() const { return (this->*x_get_total_out)(); };
93 
94  S_I compressInit(U_I compression_level) { level = compression_level; return (this->*x_compressInit)(compression_level); };
95  S_I decompressInit() { return (this->*x_decompressInit)(); };
96  S_I compressEnd() { return (this->*x_compressEnd)(); };
97  S_I decompressEnd() { return (this->*x_decompressEnd)(); };
98  S_I compress(S_I flag) { return (this->*x_compress)(flag); };
99  S_I decompress(S_I flag) { return (this->*x_decompress)(flag);};
100  S_I compressReset();
101  S_I decompressReset();
102 
103  private:
104 #if LIBZ_AVAILABLE
105  z_stream *z_ptr;
106 #endif
107 #if LIBBZ2_AVAILABLE
108  bz_stream *bz_ptr;
109 #endif
110  S_I level;
111 
112  void (wrapperlib::*x_set_next_in)(const char *x);
113  void (wrapperlib::*x_set_avail_in)(U_I x);
114  U_I (wrapperlib::*x_get_avail_in)() const;
115  U_64 (wrapperlib::*x_get_total_in)() const;
116 
117  void (wrapperlib::*x_set_next_out)(char *x);
118  char *(wrapperlib::*x_get_next_out)() const;
119  void (wrapperlib::*x_set_avail_out)(U_I x);
120  U_I (wrapperlib::*x_get_avail_out)() const;
121  U_64 (wrapperlib::*x_get_total_out)() const;
122 
123  S_I (wrapperlib::*x_compressInit)(U_I compression_level);
124  S_I (wrapperlib::*x_decompressInit)();
125  S_I (wrapperlib::*x_compressEnd)();
126  S_I (wrapperlib::*x_decompressEnd)();
127  S_I (wrapperlib::*x_compress)(S_I flag);
128  S_I (wrapperlib::*x_decompress)(S_I flag);
129 
130 
131  // set of routines for zlib
132 #if LIBZ_AVAILABLE
133  S_I z_compressInit(U_I compression_level);
134  S_I z_decompressInit();
135  S_I z_compressEnd();
136  S_I z_decompressEnd();
137  S_I z_compress(S_I flag);
138  S_I z_decompress(S_I flag);
139  void z_set_next_in(const char *x);
140  void z_set_avail_in(U_I x);
141  U_I z_get_avail_in() const;
142  U_64 z_get_total_in() const;
143  void z_set_next_out(char *x);
144  char *z_get_next_out() const;
145  void z_set_avail_out(U_I x);
146  U_I z_get_avail_out() const;
147  U_64 z_get_total_out() const;
148 #endif
149 
150  // set of routines for bzlib
151 #if LIBBZ2_AVAILABLE
152  S_I bz_compressInit(U_I compression_level);
153  S_I bz_decompressInit();
154  S_I bz_compressEnd();
155  S_I bz_decompressEnd();
156  S_I bz_compress(S_I flag);
157  S_I bz_decompress(S_I flag);
158  void bz_set_next_in(const char *x);
159  void bz_set_avail_in(U_I x);
160  U_I bz_get_avail_in() const;
161  U_64 bz_get_total_in() const;
162  void bz_set_next_out(char *x);
163  char *bz_get_next_out() const;
164  void bz_set_avail_out(U_I x);
165  U_I bz_get_avail_out() const;
166  U_64 bz_get_total_out() const;
167 #endif
168  };
169 
171 
172 } // end of namespace
173 
174 #endif