Disk ARchive  2.4.21
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 
29 
30 #ifndef WRAPPERLIB_HPP
31 #define WRAPPERLIB_HPP
32 
33 #include "../my_config.h"
34 
35 extern "C"
36 {
37 #if HAVE_ZLIB_H && LIBZ_AVAILABLE
38 #include <zlib.h>
39 #endif
40 
41 #if HAVE_BZLIB_H && LIBBZ2_AVAILABLE
42 #include <bzlib.h>
43 #endif
44 } // end extern "C"
45 
46 #include "integers.hpp"
47 
48 namespace libdar
49 {
50 
53 
54  const int WR_OK = 0;
55  const int WR_MEM_ERROR = 1;
56  const int WR_VERSION_ERROR = 2;
57  const int WR_STREAM_ERROR = 3;
58  const int WR_DATA_ERROR = 4;
59  const int WR_NO_FLUSH = 5;
60  const int WR_BUF_ERROR = 6;
61  const int WR_STREAM_END = 7;
62  const int WR_FINISH = 8;
63 
64  enum wrapperlib_mode { zlib_mode, bzlib_mode };
65 
67 
71 
72  class wrapperlib
73  {
74  public:
75  wrapperlib(wrapperlib_mode mode);
76  wrapperlib(const wrapperlib & ref);
77  const wrapperlib & operator = (const wrapperlib & ref);
78  ~wrapperlib();
79 
80  void set_next_in(const char *x) { return (this->*x_set_next_in)(x); };
81  void set_avail_in(U_I x) { return (this->*x_set_avail_in)(x); };
82  U_I get_avail_in() const { return (this->*x_get_avail_in)(); };
83  U_64 get_total_in() const { return (this->*x_get_total_in)(); };
84 
85  void set_next_out(char *x) { return (this->*x_set_next_out)(x); };
86  char *get_next_out() const { return (this->*x_get_next_out)(); };
87  void set_avail_out(U_I x) { return (this->*x_set_avail_out)(x); };
88  U_I get_avail_out() const { return (this->*x_get_avail_out)(); };
89  U_64 get_total_out() const { return (this->*x_get_total_out)(); };
90 
91  S_I compressInit(U_I compression_level) { level = compression_level; return (this->*x_compressInit)(compression_level); };
92  S_I decompressInit() { return (this->*x_decompressInit)(); };
93  S_I compressEnd() { return (this->*x_compressEnd)(); };
94  S_I decompressEnd() { return (this->*x_decompressEnd)(); };
95  S_I compress(S_I flag) { return (this->*x_compress)(flag); };
96  S_I decompress(S_I flag) { return (this->*x_decompress)(flag);};
97  S_I compressReset();
98  S_I decompressReset();
99 
100  private:
101 #if LIBZ_AVAILABLE
102  z_stream *z_ptr;
103 #endif
104 #if LIBBZ2_AVAILABLE
105  bz_stream *bz_ptr;
106 #endif
107  S_I level;
108 
109  void (wrapperlib::*x_set_next_in)(const char *x);
110  void (wrapperlib::*x_set_avail_in)(U_I x);
111  U_I (wrapperlib::*x_get_avail_in)() const;
112  U_64 (wrapperlib::*x_get_total_in)() const;
113 
114  void (wrapperlib::*x_set_next_out)(char *x);
115  char *(wrapperlib::*x_get_next_out)() const;
116  void (wrapperlib::*x_set_avail_out)(U_I x);
117  U_I (wrapperlib::*x_get_avail_out)() const;
118  U_64 (wrapperlib::*x_get_total_out)() const;
119 
120  S_I (wrapperlib::*x_compressInit)(U_I compression_level);
121  S_I (wrapperlib::*x_decompressInit)();
122  S_I (wrapperlib::*x_compressEnd)();
123  S_I (wrapperlib::*x_decompressEnd)();
124  S_I (wrapperlib::*x_compress)(S_I flag);
125  S_I (wrapperlib::*x_decompress)(S_I flag);
126 
127 
128  // set of routines for zlib
129 #if LIBZ_AVAILABLE
130  S_I z_compressInit(U_I compression_level);
131  S_I z_decompressInit();
132  S_I z_compressEnd();
133  S_I z_decompressEnd();
134  S_I z_compress(S_I flag);
135  S_I z_decompress(S_I flag);
136  void z_set_next_in(const char *x);
137  void z_set_avail_in(U_I x);
138  U_I z_get_avail_in() const;
139  U_64 z_get_total_in() const;
140  void z_set_next_out(char *x);
141  char *z_get_next_out() const;
142  void z_set_avail_out(U_I x);
143  U_I z_get_avail_out() const;
144  U_64 z_get_total_out() const;
145 #endif
146 
147  // set of routines for bzlib
148 #if LIBBZ2_AVAILABLE
149  S_I bz_compressInit(U_I compression_level);
150  S_I bz_decompressInit();
151  S_I bz_compressEnd();
152  S_I bz_decompressEnd();
153  S_I bz_compress(S_I flag);
154  S_I bz_decompress(S_I flag);
155  void bz_set_next_in(const char *x);
156  void bz_set_avail_in(U_I x);
157  U_I bz_get_avail_in() const;
158  U_64 bz_get_total_in() const;
159  void bz_set_next_out(char *x);
160  char *bz_get_next_out() const;
161  void bz_set_avail_out(U_I x);
162  U_I bz_get_avail_out() const;
163  U_64 bz_get_total_out() const;
164 #endif
165  };
166 
168 
169 } // end of namespace
170 
171 #endif
are defined here basic integer types that tend to be portable
this class encapsulates calls to libz or libbz2
Definition: wrapperlib.hpp:72
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43