Skip to content

Commit

Permalink
Reduce code duplication in BitInputArchive
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed May 22, 2024
1 parent e46e03d commit 5edcd9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions include/bit7z/bitinputarchive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class BitInputArchive {

auto openArchiveStream( const fs::path& name, IInStream* inStream ) -> IInArchive*;

void testArchive( const std::vector< uint32_t >& indices ) const;

public:
/**
* @brief An iterator for the elements contained in an archive.
Expand Down
14 changes: 7 additions & 7 deletions src/bitinputarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ void BitInputArchive::extractTo( std::map< tstring, buffer_t >& outMap ) const {
}

void BitInputArchive::test() const {
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 );
testArchive( {} );
}

void BitInputArchive::test( const std::vector< uint32_t >& indices ) const {
Expand All @@ -348,9 +346,7 @@ void BitInputArchive::test( const std::vector< uint32_t >& indices ) const {
make_error_code( BitError::InvalidIndex ) );
}

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, indices, extractCallback, ExtractMode::Test );
testArchive( indices );
}

void BitInputArchive::testItem( uint32_t index ) const {
Expand All @@ -360,9 +356,13 @@ void BitInputArchive::testItem( uint32_t index ) const {
make_error_code( BitError::InvalidIndex ) );
}

testArchive( { index } );
}

void BitInputArchive::testArchive( const std::vector< uint32_t >& indices ) const {
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 );
extract_arc( mInArchive, indices, extractCallback, ExtractMode::Test );
}

auto BitInputArchive::close() const noexcept -> HRESULT {
Expand Down

0 comments on commit 5edcd9a

Please sign in to comment.