Disk ARchive 2.7.16
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
wrapperlib.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
29
30#ifndef WRAPPERLIB_HPP
31#define WRAPPERLIB_HPP
32
33#include "../my_config.h"
34
35extern "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
45#if HAVE_LZMA_H && LIBLZMA_AVAILABLE
46#include <lzma.h>
47#endif
48} // end extern "C"
49
50#include "integers.hpp"
51
52namespace libdar
53{
54
57
58 const int WR_OK = 0; // operation successful
59 const int WR_MEM_ERROR = 1; // lack of memory
60 const int WR_VERSION_ERROR = 2; // incompatible version of the compression library with the one expected by libdar
61 const int WR_STREAM_ERROR = 3; // not a valid compression level, incoherent data provided to the compression library
62 const int WR_DATA_ERROR = 4; // data has been corrupted
63 const int WR_NO_FLUSH = 5; // parameter to let the compression library decide at which time to output data (from zlib Z_NO_FLUSH, no other way is done in libdar)
64 const int WR_BUF_ERROR = 6; // no possible work to perform for the request action without additional provided data/or storage space to the compression library
65 const int WR_STREAM_END = 7; // end of compressed data met
66 const int WR_FINISH = 8; // parameter requiring the compression library to cleanly stop the running operation
67
68 enum wrapperlib_mode { zlib_mode, bzlib_mode, xz_mode };
69
71
75 {
76 public:
77 wrapperlib(wrapperlib_mode mode);
78 wrapperlib(const wrapperlib & ref) = delete;
79 wrapperlib(wrapperlib && ref) noexcept = delete;
80 wrapperlib & operator = (const wrapperlib & ref) = delete;
81 wrapperlib & operator = (wrapperlib && ref) noexcept = delete;
83
84 void set_next_in(const char *x) { return (this->*x_set_next_in)(x); };
85 void set_avail_in(U_I x) { return (this->*x_set_avail_in)(x); };
86 U_I get_avail_in() const { return (this->*x_get_avail_in)(); };
87 U_64 get_total_in() const { return (this->*x_get_total_in)(); };
88
89 void set_next_out(char *x) { return (this->*x_set_next_out)(x); };
90 char *get_next_out() const { return (this->*x_get_next_out)(); };
91 void set_avail_out(U_I x) { return (this->*x_set_avail_out)(x); };
92 U_I get_avail_out() const { return (this->*x_get_avail_out)(); };
93 U_64 get_total_out() const { return (this->*x_get_total_out)(); };
94
95 S_I compressInit(U_I compression_level) { level = compression_level; return (this->*x_compressInit)(compression_level); };
96 S_I decompressInit() { return (this->*x_decompressInit)(); };
97 S_I compressEnd() { return (this->*x_compressEnd)(); };
98 S_I decompressEnd() { return (this->*x_decompressEnd)(); };
99 S_I compress(S_I flag) { return (this->*x_compress)(flag); };
100 S_I decompress(S_I flag) { return (this->*x_decompress)(flag);};
101 S_I compressReset();
102 S_I decompressReset();
103
104 private:
105#if LIBZ_AVAILABLE
106 z_stream *z_ptr;
107#endif
108#if LIBBZ2_AVAILABLE
109 bz_stream *bz_ptr;
110#endif
111#if LIBLZMA_AVAILABLE
112 lzma_stream *lzma_ptr;
113#endif
114
115 S_I level;
116
117 void (wrapperlib::*x_set_next_in)(const char *x);
118 void (wrapperlib::*x_set_avail_in)(U_I x);
119 U_I (wrapperlib::*x_get_avail_in)() const;
120 U_64 (wrapperlib::*x_get_total_in)() const;
121
122 void (wrapperlib::*x_set_next_out)(char *x);
123 char *(wrapperlib::*x_get_next_out)() const;
124 void (wrapperlib::*x_set_avail_out)(U_I x);
125 U_I (wrapperlib::*x_get_avail_out)() const;
126 U_64 (wrapperlib::*x_get_total_out)() const;
127
128 S_I (wrapperlib::*x_compressInit)(U_I compression_level);
129 S_I (wrapperlib::*x_decompressInit)();
130 S_I (wrapperlib::*x_compressEnd)();
131 S_I (wrapperlib::*x_decompressEnd)();
132 S_I (wrapperlib::*x_compress)(S_I flag);
133 S_I (wrapperlib::*x_decompress)(S_I flag);
134
135
136 // set of routines for zlib
137#if LIBZ_AVAILABLE
138 S_I z_compressInit(U_I compression_level);
139 S_I z_decompressInit();
140 S_I z_compressEnd();
141 S_I z_decompressEnd();
142 S_I z_compress(S_I flag);
143 S_I z_decompress(S_I flag);
144 void z_set_next_in(const char *x);
145 void z_set_avail_in(U_I x);
146 U_I z_get_avail_in() const;
147 U_64 z_get_total_in() const;
148 void z_set_next_out(char *x);
149 char *z_get_next_out() const;
150 void z_set_avail_out(U_I x);
151 U_I z_get_avail_out() const;
152 U_64 z_get_total_out() const;
153#endif
154
155 // set of routines for bzlib
156#if LIBBZ2_AVAILABLE
157 S_I bz_compressInit(U_I compression_level);
158 S_I bz_decompressInit();
159 S_I bz_compressEnd();
160 S_I bz_decompressEnd();
161 S_I bz_compress(S_I flag);
162 S_I bz_decompress(S_I flag);
163 void bz_set_next_in(const char *x);
164 void bz_set_avail_in(U_I x);
165 U_I bz_get_avail_in() const;
166 U_64 bz_get_total_in() const;
167 void bz_set_next_out(char *x);
168 char *bz_get_next_out() const;
169 void bz_set_avail_out(U_I x);
170 U_I bz_get_avail_out() const;
171 U_64 bz_get_total_out() const;
172#endif
173
174 // set of routines for liblzma
175#if LIBLZMA_AVAILABLE
176 S_I lzma_compressInit(U_I compression_level);
177 S_I lzma_decompressInit();
178 S_I lzma_end();
179 S_I lzma_encode(S_I flag);
180 void lzma_set_next_in(const char *x);
181 void lzma_set_avail_in(U_I x);
182 U_I lzma_get_avail_in() const;
183 U_64 lzma_get_total_in() const;
184 void lzma_set_next_out(char *x);
185 char *lzma_get_next_out() const;
186 void lzma_set_avail_out(U_I x);
187 U_I lzma_get_avail_out() const;
188 U_64 lzma_get_total_out() const;
189#endif
190
191 };
192
194
195} // end of namespace
196
197#endif
this class encapsulates calls to libz or libbz2
are defined here basic integer types that tend to be portable
include macro defined by the configure script and some specific additional ones
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47