Skip to content

Commit

Permalink
[Test] Optimize includes
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Oct 28, 2023
1 parent 13af5ec commit 97fdfbf
Show file tree
Hide file tree
Showing 46 changed files with 110 additions and 94 deletions.
5 changes: 2 additions & 3 deletions include/bit7z/bitarchiveeditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <istream>
#include <unordered_map>
#include <vector>

namespace bit7z {

Expand Down Expand Up @@ -102,7 +101,7 @@ class BIT7Z_MAYBE_UNUSED BitArchiveEditor final : public BitArchiveWriter {
* @param index the index of the item to be updated.
* @param inBuffer the buffer containing the new data for the item.
*/
void updateItem( uint32_t index, const std::vector< byte_t >& inBuffer );
void updateItem( uint32_t index, const buffer_t& inBuffer );

/**
* @brief Requests to update the content of the item at the specified index
Expand All @@ -129,7 +128,7 @@ class BIT7Z_MAYBE_UNUSED BitArchiveEditor final : public BitArchiveWriter {
* @param itemPath the path (in the archive) of the item to be updated.
* @param inBuffer the buffer containing the new data for the item.
*/
void updateItem( const tstring& itemPath, const std::vector< byte_t >& inBuffer );
void updateItem( const tstring& itemPath, const buffer_t& inBuffer );

/**
* @brief Requests to update the content of the item at the specified path
Expand Down
3 changes: 1 addition & 2 deletions include/bit7z/bitarchivereader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <istream>
#include <map>
#include <system_error>
#include <vector>

struct IInArchive;
struct IOutArchive;
Expand Down Expand Up @@ -68,7 +67,7 @@ class BitArchiveReader final : public BitAbstractArchiveOpener, public BitInputA
* @param password the password needed for opening the input archive.
*/
BitArchiveReader( const Bit7zLibrary& lib,
const std::vector< byte_t >& inArchive,
const buffer_t& inArchive,
const BitInFormat& format BIT7Z_DEFAULT_FORMAT,
const tstring& password = {} );

Expand Down
3 changes: 1 addition & 2 deletions include/bit7z/bitarchivewriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "bittypes.hpp"

#include <istream>
#include <vector>

namespace bit7z {

Expand Down Expand Up @@ -56,7 +55,7 @@ class BitArchiveWriter : public BitAbstractArchiveCreator, public BitOutputArchi
* @param password (optional) the password needed to read the input archive.
*/
BitArchiveWriter( const Bit7zLibrary& lib,
const std::vector< byte_t >& inArchive,
const buffer_t& inArchive,
const BitInOutFormat& format,
const tstring& password = {} );

Expand Down
3 changes: 1 addition & 2 deletions include/bit7z/bitcompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <ostream>
#include <type_traits>
#include <vector>

namespace bit7z {

Expand Down Expand Up @@ -90,7 +89,7 @@ class BitCompressor : public BitAbstractArchiveCreator {
* @param inputName (optional) the name to give to the compressed file inside the output archive.
*/
void compressFile( Input inFile,
std::vector< byte_t >& outBuffer,
buffer_t& outBuffer,
const tstring& inputName = {} ) const {
BitOutputArchive outputArchive{ *this, outBuffer };
outputArchive.addFile( inFile, inputName );
Expand Down
11 changes: 5 additions & 6 deletions include/bit7z/bitextractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <algorithm>
#include <functional>
#include <map>
#include <vector>
#include <ostream>

#ifdef BIT7Z_REGEX_MATCHING
Expand Down Expand Up @@ -81,7 +80,7 @@ class BitExtractor final : public BitAbstractArchiveOpener {
* @param outBuffer the output buffer where the content of the extracted file will be put.
* @param index the index of the file to be extracted from the archive.
*/
void extract( Input inArchive, std::vector< byte_t >& outBuffer, uint32_t index = 0 ) const {
void extract( Input inArchive, buffer_t& outBuffer, uint32_t index = 0 ) const {
BitInputArchive inputArchive( *this, inArchive );
inputArchive.extractTo( outBuffer, index );
}
Expand All @@ -105,7 +104,7 @@ class BitExtractor final : public BitAbstractArchiveOpener {
* @param inArchive the input archive to be extracted.
* @param outMap the output map.
*/
void extract( Input inArchive, std::map< tstring, std::vector< byte_t > >& outMap ) const {
void extract( Input inArchive, std::map< tstring, buffer_t >& outMap ) const {
BitInputArchive inputArchive( *this, inArchive );
inputArchive.extractTo( outMap );
}
Expand Down Expand Up @@ -141,7 +140,7 @@ class BitExtractor final : public BitAbstractArchiveOpener {
*/
void extractMatching( Input inArchive,
const tstring& itemFilter,
std::vector< byte_t >& outBuffer,
buffer_t& outBuffer,
FilterPolicy policy = FilterPolicy::Include ) const {
if ( itemFilter.empty() ) {
throw BitException( "Cannot extract items", make_error_code( BitError::FilterNotSpecified ) );
Expand Down Expand Up @@ -221,7 +220,7 @@ class BitExtractor final : public BitAbstractArchiveOpener {
*/
void extractMatchingRegex( Input inArchive,
const tstring& regex,
std::vector< byte_t >& outBuffer,
buffer_t& outBuffer,
FilterPolicy policy = FilterPolicy::Include ) const {
if ( regex.empty() ) {
throw BitException( "Cannot extract items", make_error_code( BitError::FilterNotSpecified ) );
Expand Down Expand Up @@ -278,7 +277,7 @@ class BitExtractor final : public BitAbstractArchiveOpener {
}

void extractMatchingFilter( Input inArchive,
std::vector< byte_t >& outBuffer,
buffer_t& outBuffer,
FilterPolicy policy,
const std::function< bool( const tstring& ) >& filter ) const {
BitInputArchive inputArchive( *this, inArchive );
Expand Down
11 changes: 5 additions & 6 deletions include/bit7z/bitinputarchive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <istream>
#include <map>
#include <ostream>
#include <vector>

struct IInStream;
struct IInArchive;
Expand Down Expand Up @@ -63,7 +62,7 @@ class BitInputArchive {
* be used for reading the input archive
* @param inBuffer the buffer containing the input archive
*/
BitInputArchive( const BitAbstractArchiveHandler& handler, const std::vector< byte_t >& inBuffer );
BitInputArchive( const BitAbstractArchiveHandler& handler, const buffer_t& inBuffer );

/**
* @brief Constructs a BitInputArchive object, opening the archive by reading the given input stream.
Expand Down Expand Up @@ -152,7 +151,7 @@ class BitInputArchive {
void extractTo( const tstring& outDir, const std::vector< uint32_t >& indices = {} ) const;

BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
inline void extract( std::vector< byte_t >& outBuffer, uint32_t index = 0 ) const {
inline void extract( buffer_t& outBuffer, uint32_t index = 0 ) const {
extractTo( outBuffer, index );
}

Expand All @@ -162,7 +161,7 @@ class BitInputArchive {
* @param outBuffer the output buffer where the content of the archive will be put.
* @param index the index of the file to be extracted.
*/
void extractTo( std::vector< byte_t >& outBuffer, uint32_t index = 0 ) const;
void extractTo( buffer_t& outBuffer, uint32_t index = 0 ) const;

template< std::size_t N >
BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
Expand Down Expand Up @@ -231,7 +230,7 @@ class BitInputArchive {
void extractTo( std::ostream& outStream, uint32_t index = 0 ) const;

BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
inline void extract( std::map< tstring, std::vector< byte_t > >& outMap ) const {
inline void extract( std::map< tstring, buffer_t >& outMap ) const {
extractTo( outMap );
}

Expand All @@ -241,7 +240,7 @@ class BitInputArchive {
*
* @param outMap the output map.
*/
void extractTo( std::map< tstring, std::vector< byte_t > >& outMap ) const;
void extractTo( std::map< tstring, buffer_t >& outMap ) const;

/**
* @brief Tests the archive without extracting its content.
Expand Down
3 changes: 1 addition & 2 deletions include/bit7z/bititemsvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <istream>
#include <map>
#include <memory>
#include <vector>

namespace bit7z {

Expand Down Expand Up @@ -113,7 +112,7 @@ class BitItemsVector final {
* @param inBuffer the buffer containing the file to be indexed in the vector.
* @param name user-defined path to be used inside archives.
*/
void indexBuffer( const std::vector< byte_t >& inBuffer, const tstring& name );
void indexBuffer( const buffer_t& inBuffer, const tstring& name );

/**
* @brief Indexes the given standard input stream, using the given name as a path when compressed in archives.
Expand Down
4 changes: 1 addition & 3 deletions include/bit7z/bitmemcompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "bitdefines.hpp"
#include "bittypes.hpp"

#include <vector>

namespace bit7z {

/**
Expand All @@ -25,7 +23,7 @@ namespace bit7z {
* It let decide various properties of the produced archive, such as the password
* protection and the compression level desired.
*/
using BitMemCompressor BIT7Z_MAYBE_UNUSED = BitCompressor< const std::vector< byte_t >& >;
using BitMemCompressor BIT7Z_MAYBE_UNUSED = BitCompressor< const buffer_t& >;

} // namespace bit7z
#endif // BITMEMCOMPRESSOR_HPP
4 changes: 1 addition & 3 deletions include/bit7z/bitmemextractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
#include "bitextractor.hpp"
#include "bittypes.hpp"

#include <vector>

namespace bit7z {

/**
* @brief The BitMemExtractor alias allows extracting the content of in-memory archives.
*/
using BitMemExtractor BIT7Z_MAYBE_UNUSED = BitExtractor< const std::vector< byte_t >& >;
using BitMemExtractor BIT7Z_MAYBE_UNUSED = BitExtractor< const buffer_t& >;

} // namespace bit7z

Expand Down
7 changes: 3 additions & 4 deletions include/bit7z/bitoutputarchive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <ostream>
#include <set>
#include <utility>
#include <vector>

//! @cond IGNORE_BLOCK_IN_DOXYGEN
struct ISequentialInStream;
Expand Down Expand Up @@ -95,7 +94,7 @@ class BitOutputArchive {
* be used for creating the new archive and reading the (optional) input archive.
* @param inBuffer the buffer containing an input archive file.
*/
BitOutputArchive( const BitAbstractArchiveCreator& creator, const std::vector< byte_t >& inBuffer );
BitOutputArchive( const BitAbstractArchiveCreator& creator, const buffer_t& inBuffer );

/**
* @brief Constructs a BitOutputArchive object, reading an input file archive from the given std::istream.
Expand Down Expand Up @@ -146,7 +145,7 @@ class BitOutputArchive {
* @param inBuffer the buffer containing the file to be added to the output archive.
* @param name user-defined path to be used inside the output archive.
*/
void addFile( const std::vector< byte_t >& inBuffer, const tstring& name );
void addFile( const buffer_t& inBuffer, const tstring& name );

/**
* @brief Adds the given standard input stream, using the given name as a path when compressed
Expand Down Expand Up @@ -214,7 +213,7 @@ class BitOutputArchive {
*
* @param outBuffer the output buffer.
*/
void compressTo( std::vector< byte_t >& outBuffer );
void compressTo( buffer_t& outBuffer );

/**
* @brief Compresses all the items added to this object to the specified buffer.
Expand Down
5 changes: 2 additions & 3 deletions src/bitarchiveeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <memory>
#include <string>
#include <system_error>
#include <vector>

namespace bit7z {

Expand Down Expand Up @@ -81,7 +80,7 @@ void BitArchiveEditor::updateItem( uint32_t index, const tstring& inFile ) {
mEditedItems[ index ] = std::make_unique< FilesystemItem >( tstring_to_path( inFile ), itemName.getNativeString() ); //-V108
}

void BitArchiveEditor::updateItem( uint32_t index, const std::vector< byte_t >& inBuffer ) {
void BitArchiveEditor::updateItem( uint32_t index, const buffer_t& inBuffer ) {
checkIndex( index );
auto itemName = inputArchive()->itemProperty( index, BitProperty::Path );
mEditedItems[ index ] = std::make_unique< BufferItem >( inBuffer, itemName.getNativeString() ); //-V108
Expand All @@ -98,7 +97,7 @@ void BitArchiveEditor::updateItem( const tstring& itemPath, const tstring& inFil
tstring_to_path( itemPath ) );
}

void BitArchiveEditor::updateItem( const tstring& itemPath, const std::vector< byte_t >& inBuffer ) {
void BitArchiveEditor::updateItem( const tstring& itemPath, const buffer_t& inBuffer ) {
mEditedItems[ findItem( itemPath ) ] = std::make_unique< BufferItem >( inBuffer, itemPath ); //-V108
}

Expand Down
3 changes: 1 addition & 2 deletions src/bitarchivereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <map>
#include <numeric>
#include <system_error>
#include <vector>

namespace bit7z {

Expand All @@ -38,7 +37,7 @@ BitArchiveReader::BitArchiveReader( const Bit7zLibrary& lib,
: BitAbstractArchiveOpener( lib, format, password ), BitInputArchive( *this, inArchive ) {}

BitArchiveReader::BitArchiveReader( const Bit7zLibrary& lib,
const std::vector< byte_t >& inArchive,
const buffer_t& inArchive,
const BitInFormat& format,
const tstring& password )
: BitAbstractArchiveOpener( lib, format, password ), BitInputArchive( *this, inArchive ) {}
Expand Down
3 changes: 1 addition & 2 deletions src/bitarchivewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "bittypes.hpp"

#include <istream>
#include <vector>

namespace bit7z {

Expand All @@ -34,7 +33,7 @@ BitArchiveWriter::BitArchiveWriter( const Bit7zLibrary& lib,
BitOutputArchive( *this, inArchive ) {}

BitArchiveWriter::BitArchiveWriter( const Bit7zLibrary& lib,
const std::vector< byte_t >& inArchive,
const buffer_t& inArchive,
const BitInOutFormat& format,
const tstring& password )
: BitAbstractArchiveCreator( lib, format, password, UpdateMode::Append ),
Expand Down
12 changes: 6 additions & 6 deletions src/bitinputarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ BitInputArchive::BitInputArchive( const BitAbstractArchiveHandler& handler, cons
mInArchive = openArchiveStream( arcPath, fileStream );
}

BitInputArchive::BitInputArchive( const BitAbstractArchiveHandler& handler, const std::vector< byte_t >& inBuffer )
BitInputArchive::BitInputArchive( const BitAbstractArchiveHandler& handler, const buffer_t& inBuffer )
: mDetectedFormat{ &handler.format() }, // if auto, detect the format from content, otherwise try the passed format.
mArchiveHandler{ handler } {
auto bufStream = bit7z::make_com< CBufferInStream, IInStream >( inBuffer );
Expand Down Expand Up @@ -215,7 +215,7 @@ void BitInputArchive::extractTo( const tstring& outDir, const std::vector< uint3
extract_arc( mInArchive, indices, callback );
}

void BitInputArchive::extractTo( std::vector< byte_t >& outBuffer, uint32_t index ) const {
void BitInputArchive::extractTo( buffer_t& outBuffer, uint32_t index ) const {
const uint32_t numberItems = itemsCount();
if ( index >= numberItems ) {
throw BitException( "Cannot extract item at the index " + std::to_string( index ),
Expand All @@ -228,7 +228,7 @@ void BitInputArchive::extractTo( std::vector< byte_t >& outBuffer, uint32_t inde
}

const std::vector< uint32_t > indices( 1, index );
std::map< tstring, std::vector< byte_t > > buffersMap;
std::map< tstring, buffer_t > buffersMap;
auto extractCallback = bit7z::make_com< BufferExtractCallback, ExtractCallback >( *this, buffersMap );
extract_arc( mInArchive, indices, extractCallback );
outBuffer = std::move( buffersMap.begin()->second );
Expand Down Expand Up @@ -274,7 +274,7 @@ void BitInputArchive::extractTo( byte_t* buffer, std::size_t size, uint32_t inde
extract_arc( mInArchive, indices, extractCallback );
}

void BitInputArchive::extractTo( std::map< tstring, std::vector< byte_t > >& outMap ) const {
void BitInputArchive::extractTo( std::map< tstring, buffer_t >& outMap ) const {
const uint32_t numberItems = itemsCount();
std::vector< uint32_t > filesIndices;
for ( uint32_t i = 0; i < numberItems; ++i ) {
Expand All @@ -288,7 +288,7 @@ void BitInputArchive::extractTo( std::map< tstring, std::vector< byte_t > >& out
}

void BitInputArchive::test() const {
std::map< tstring, std::vector< byte_t > > dummyMap; // output map (not used since we are testing).
std::map< tstring, buffer_t > dummyMap; // output map (not used since we are testing).
auto extractCallback = bit7z::make_com< BufferExtractCallback, ExtractCallback >( *this, dummyMap );
extract_arc( mInArchive, {}, extractCallback, ExtractMode::Test );
}
Expand All @@ -300,7 +300,7 @@ void BitInputArchive::testItem( uint32_t index ) const {
make_error_code( BitError::InvalidIndex ) );
}

std::map< tstring, std::vector< byte_t > > dummyMap; // output map (not used since we are testing).
std::map< tstring, buffer_t > dummyMap; // output map (not used since we are testing).
auto extractCallback = bit7z::make_com< BufferExtractCallback, ExtractCallback >( *this, dummyMap );
extract_arc( mInArchive, { index }, extractCallback, ExtractMode::Test );
}
Expand Down
2 changes: 1 addition & 1 deletion src/bititemsvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void BitItemsVector::indexFile( const tstring& inFile, const tstring& name, bool
mItems.emplace_back( std::make_unique< FilesystemItem >( filePath, tstring_to_path( name ), symlinkPolicy ) );
}

void BitItemsVector::indexBuffer( const std::vector< byte_t >& inBuffer, const tstring& name ) {
void BitItemsVector::indexBuffer( const buffer_t& inBuffer, const tstring& name ) {
mItems.emplace_back( std::make_unique< BufferItem >( inBuffer, tstring_to_path( name ) ) );
}

Expand Down
Loading

0 comments on commit 97fdfbf

Please sign in to comment.