bit7z 4.0.0
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bitabstractarchivehandler.hpp
1/*
2 * bit7z - A C++ static library to interface with the 7-zip shared libraries.
3 * Copyright (c) 2014-2023 Riccardo Ostani - All Rights Reserved.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef BITABSTRACTARCHIVEHANDLER_HPP
11#define BITABSTRACTARCHIVEHANDLER_HPP
12
13#include <cstdint>
14#include <functional>
15
16#include "bit7zlibrary.hpp"
17#include "bitdefines.hpp"
18
19namespace bit7z {
20
21class BitInFormat;
22
26using TotalCallback = std::function< void( uint64_t ) >;
27
32using ProgressCallback = std::function< bool( uint64_t ) >;
33
38using RatioCallback = std::function< void( uint64_t, uint64_t ) >;
39
45
50
54enum struct OverwriteMode {
55 None = 0,
56 Overwrite,
57 Skip,
58//TODO: RenameOutput,
59//TODO: RenameExisting
60};
61
66enum struct FilterPolicy {
67 Include,
68 Exclude
69};
70
75 public:
77
79
80 auto operator=( const BitAbstractArchiveHandler& ) -> BitAbstractArchiveHandler& = delete;
81
82 auto operator=( BitAbstractArchiveHandler&& ) -> BitAbstractArchiveHandler& = delete;
83
84 virtual ~BitAbstractArchiveHandler() = default;
85
89 BIT7Z_NODISCARD auto library() const noexcept -> const Bit7zLibrary&;
90
94 BIT7Z_NODISCARD virtual auto format() const -> const BitInFormat& = 0;
95
99 BIT7Z_NODISCARD auto password() const -> tstring;
100
105 BIT7Z_NODISCARD auto retainDirectories() const noexcept -> bool;
106
110 BIT7Z_NODISCARD auto isPasswordDefined() const noexcept -> bool;
111
115 BIT7Z_NODISCARD auto totalCallback() const -> TotalCallback;
116
120 BIT7Z_NODISCARD auto progressCallback() const -> ProgressCallback;
121
125 BIT7Z_NODISCARD auto ratioCallback() const -> RatioCallback;
126
130 BIT7Z_NODISCARD auto fileCallback() const -> FileCallback;
131
135 BIT7Z_NODISCARD auto passwordCallback() const -> PasswordCallback;
136
140 BIT7Z_NODISCARD auto overwriteMode() const -> OverwriteMode;
141
161 virtual void setPassword( const tstring& password );
162
170 void clearPassword() noexcept;
171
177 void setRetainDirectories( bool retain ) noexcept;
178
184 void setTotalCallback( const TotalCallback& callback );
185
194 void setProgressCallback( const ProgressCallback& callback );
195
205 void setRatioCallback( const RatioCallback& callback );
206
212 void setFileCallback( const FileCallback& callback );
213
219 void setPasswordCallback( const PasswordCallback& callback );
220
227
228 protected:
229 explicit BitAbstractArchiveHandler( const Bit7zLibrary& lib,
230 tstring password = {},
232
233 private:
234 const Bit7zLibrary& mLibrary;
235 tstring mPassword;
236 bool mRetainDirectories;
237 OverwriteMode mOverwriteMode;
238
239 //CALLBACKS
240 TotalCallback mTotalCallback;
241 ProgressCallback mProgressCallback;
242 RatioCallback mRatioCallback;
243 FileCallback mFileCallback;
244 PasswordCallback mPasswordCallback;
245};
246
247} // namespace bit7z
248
249#endif // BITABSTRACTARCHIVEHANDLER_HPP
The Bit7zLibrary class allows accessing the basic functionalities provided by the 7z DLLs.
Definition bit7zlibrary.hpp:56
Abstract class representing a generic archive handler.
Definition bitabstractarchivehandler.hpp:74
void clearPassword() noexcept
Clear the current password used by the handler.
auto library() const noexcept -> const Bit7zLibrary &
auto overwriteMode() const -> OverwriteMode
virtual auto format() const -> const BitInFormat &=0
void setPasswordCallback(const PasswordCallback &callback)
Sets the function to be called when a password is needed to complete the ongoing operation.
void setFileCallback(const FileCallback &callback)
Sets the function to be called when the current file being processed changes.
void setRatioCallback(const RatioCallback &callback)
Sets the function to be called when the input processed size and current output size of the ongoing o...
virtual void setPassword(const tstring &password)
Sets up a password to be used by the archive handler.
auto password() const -> tstring
auto ratioCallback() const -> RatioCallback
void setProgressCallback(const ProgressCallback &callback)
Sets the function to be called when the processed size of the ongoing operation is updated.
auto totalCallback() const -> TotalCallback
auto progressCallback() const -> ProgressCallback
void setTotalCallback(const TotalCallback &callback)
Sets the function to be called when the total size of an operation is available.
auto fileCallback() const -> FileCallback
auto isPasswordDefined() const noexcept -> bool
auto retainDirectories() const noexcept -> bool
void setOverwriteMode(OverwriteMode mode)
Sets how the handler should behave when it tries to output to an existing file or buffer.
void setRetainDirectories(bool retain) noexcept
Sets whether the operations' output will preserve the input's directory structure or not.
auto passwordCallback() const -> PasswordCallback
The BitInFormat class specifies an extractable archive format.
Definition bitformat.hpp:58
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:30
FilterPolicy
Enumeration representing the policy according to which the archive handler should treat the items tha...
Definition bitabstractarchivehandler.hpp:66
@ Exclude
Do not extract/compress the items that match the pattern.
@ Include
Extract/compress the items that match the pattern.
OverwriteMode
Enumeration representing how a handler should deal when an output file already exists.
Definition bitabstractarchivehandler.hpp:54
@ None
The handler will throw an exception if the output file or buffer already exists.
@ Skip
The handler will skip writing to the output file or buffer.
std::basic_string< tchar > tstring
Definition bittypes.hpp:90
@ None
The creator will throw an exception (unless the OverwriteMode is not None).