bit7z 4.0.0
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bitformat.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 BITFORMAT_HPP
11#define BITFORMAT_HPP
12
13#include <bitset>
14#include <type_traits>
15
16#include "bitcompressionmethod.hpp"
17#include "bitdefines.hpp"
18#include "bittypes.hpp"
19
20namespace bit7z {
21
25enum struct FormatFeatures : unsigned {
26 MultipleFiles = 1u << 0,
27 SolidArchive = 1u << 1,
28 CompressionLevel = 1u << 2,
29 Encryption = 1u << 3,
30 HeaderEncryption = 1u << 4,
31 MultipleMethods = 1u << 5
32};
33
34template< typename Enum >
35using underlying_type_t = typename std::underlying_type< Enum >::type;
36
37template< typename Enum >
38inline constexpr auto to_underlying( Enum enum_value ) noexcept -> underlying_type_t< Enum > {
39 return static_cast< underlying_type_t< Enum > >( enum_value );
40}
41
42inline constexpr auto operator|( FormatFeatures lhs, FormatFeatures rhs ) noexcept -> FormatFeatures {
43 return static_cast< FormatFeatures >( to_underlying( lhs ) | to_underlying( rhs ) );
44}
45
46using FormatFeaturesType = underlying_type_t< FormatFeatures >;
47
48inline constexpr auto operator&( FormatFeatures lhs, FormatFeatures rhs ) noexcept -> FormatFeaturesType {
49 return to_underlying( lhs ) & to_underlying( rhs );
50}
51
59 public:
60 //non-copyable
61 BitInFormat( const BitInFormat& other ) = delete;
62
63 auto operator=( const BitInFormat& other ) -> BitInFormat& = delete;
64
65 //non-movable
66 BitInFormat( BitInFormat&& other ) = delete;
67
68 auto operator=( BitInFormat&& other ) -> BitInFormat& = delete;
69
70 ~BitInFormat() = default;
71
76 constexpr explicit BitInFormat( unsigned char value ) noexcept: mValue( value ) {}
77
81 BIT7Z_NODISCARD auto value() const noexcept -> unsigned char;
82
87 auto operator==( BitInFormat const& other ) const noexcept -> bool;
88
93 auto operator!=( BitInFormat const& other ) const noexcept -> bool;
94
95 private:
96 unsigned char mValue;
97};
98
105class BitInOutFormat final : public BitInFormat {
106 public:
115 constexpr BitInOutFormat( unsigned char value,
116 const tchar* ext,
117 BitCompressionMethod defaultMethod,
118 FormatFeatures features ) noexcept
119 : BitInFormat( value ), mExtension( ext ), mDefaultMethod( defaultMethod ), mFeatures( features ) {}
120
121 //non-copyable
122 BitInOutFormat( const BitInOutFormat& other ) = delete;
123
124 auto operator=( const BitInOutFormat& other ) -> BitInOutFormat& = delete;
125
126 //non-movable
127 BitInOutFormat( BitInOutFormat&& other ) = delete;
128
129 auto operator=( BitInOutFormat&& other ) -> BitInOutFormat& = delete;
130
131 ~BitInOutFormat() = default;
132
136 BIT7Z_NODISCARD
137 auto extension() const noexcept -> const tchar*;
138
142 BIT7Z_NODISCARD
143 auto features() const noexcept -> FormatFeatures;
144
152 BIT7Z_NODISCARD
153 auto hasFeature( FormatFeatures feature ) const noexcept -> bool;
154
158 BIT7Z_NODISCARD
159 auto defaultMethod() const noexcept -> BitCompressionMethod;
160
161 private:
162 const tchar* mExtension;
163 BitCompressionMethod mDefaultMethod;
164 FormatFeatures mFeatures;
165};
166
170namespace BitFormat {
171#ifdef BIT7Z_AUTO_FORMAT
175extern const BitInFormat Auto;
176#endif
177extern const BitInFormat Rar;
178extern const BitInFormat Arj;
179//NOLINTNEXTLINE(*-identifier-length)
180extern const BitInFormat Z;
181extern const BitInFormat Lzh;
182extern const BitInFormat Cab;
183extern const BitInFormat Nsis;
184extern const BitInFormat Lzma;
185extern const BitInFormat Lzma86;
186extern const BitInFormat Ppmd;
187extern const BitInFormat Vhdx;
188extern const BitInFormat COFF;
189extern const BitInFormat Ext;
190extern const BitInFormat VMDK;
191extern const BitInFormat VDI;
192extern const BitInFormat QCow;
193extern const BitInFormat GPT;
194extern const BitInFormat Rar5;
195extern const BitInFormat IHex;
196extern const BitInFormat Hxs;
197//NOLINTNEXTLINE(*-identifier-length)
198extern const BitInFormat TE;
199extern const BitInFormat UEFIc;
200extern const BitInFormat UEFIs;
201extern const BitInFormat SquashFS;
202extern const BitInFormat CramFS;
203extern const BitInFormat APM;
204extern const BitInFormat Mslz;
205extern const BitInFormat Flv;
206extern const BitInFormat Swf;
207extern const BitInFormat Swfc;
208extern const BitInFormat Ntfs;
209extern const BitInFormat Fat;
210extern const BitInFormat Mbr;
211extern const BitInFormat Vhd;
212//NOLINTNEXTLINE(*-identifier-length)
213extern const BitInFormat Pe;
214extern const BitInFormat Elf;
215extern const BitInFormat Macho;
216extern const BitInFormat Udf;
217extern const BitInFormat Xar;
218extern const BitInFormat Mub;
219extern const BitInFormat Hfs;
220extern const BitInFormat Dmg;
221extern const BitInFormat Compound;
222extern const BitInFormat Iso;
223extern const BitInFormat Chm;
224extern const BitInFormat Split;
225extern const BitInFormat Rpm;
226extern const BitInFormat Deb;
227extern const BitInFormat Cpio;
228
229extern const BitInOutFormat Zip;
230extern const BitInOutFormat BZip2;
231extern const BitInOutFormat SevenZip;
232//NOLINTNEXTLINE(*-identifier-length)
233extern const BitInOutFormat Xz;
234extern const BitInOutFormat Wim;
235extern const BitInOutFormat Tar;
236extern const BitInOutFormat GZip;
237} // namespace BitFormat
238
239
240#ifdef BIT7Z_AUTO_FORMAT
241#define BIT7Z_DEFAULT_FORMAT = BitFormat::Auto
242#else
243#define BIT7Z_DEFAULT_FORMAT
244#endif
245
246} // namespace bit7z
247
248#endif // BITFORMAT_HPP
The BitInFormat class specifies an extractable archive format.
Definition bitformat.hpp:58
auto value() const noexcept -> unsigned char
constexpr BitInFormat(unsigned char value) noexcept
Constructs a BitInFormat object with the ID value used by the 7z SDK.
Definition bitformat.hpp:76
The BitInOutFormat class specifies a format available for creating new archives and extract old ones.
Definition bitformat.hpp:105
constexpr BitInOutFormat(unsigned char value, const tchar *ext, BitCompressionMethod defaultMethod, FormatFeatures features) noexcept
Constructs a BitInOutFormat object with an ID value, an extension and a set of supported features.
Definition bitformat.hpp:115
auto extension() const noexcept -> const tchar *
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:30
FormatFeatures
The FormatFeatures enum specifies the features supported by an archive file format.
Definition bitformat.hpp:25
@ HeaderEncryption
The format can encrypt the file names (2^4 = 0010000)
@ MultipleFiles
The format can compress/extract multiple files (2^0 = 0000001)
@ MultipleMethods
The format can use different compression methods (2^6 = 0100000)
@ Encryption
The format supports archive encryption (2^3 = 0001000)
@ SolidArchive
The format supports solid archives (2^1 = 0000010)
@ CompressionLevel
The format is able to use different compression levels (2^2 = 0000100)
char tchar
Definition bittypes.hpp:82
BitCompressionMethod
The BitCompressionMethod enum represents the compression methods used by 7z when creating archives.
Definition bitcompressionmethod.hpp:18