diff --git a/include/E57SimpleReader.h b/include/E57SimpleReader.h index d2fb2e3..f795567 100644 --- a/include/E57SimpleReader.h +++ b/include/E57SimpleReader.h @@ -35,15 +35,26 @@ namespace e57 { + struct E57_DLL ReaderOptions + { + //! Set how frequently to verify the checksums (see ReadChecksumPolicy). + ReadChecksumPolicy checksumPolicy = CHECKSUM_POLICY_ALL; + }; //! @brief Used for reading of the E57 file with E57 Simple API class E57_DLL Reader { public: //! @brief This function is the constructor for the reader class - //! @param [in] filePath file path to E57 file + //! @param [in] filePath Path to E57 file + [[deprecated( "Will be removed in 4.0. Use Reader( ustring, ReaderOptions )." )]] // TODO Remove in 4.0 explicit Reader( const ustring &filePath ); + //! @brief This function is the constructor for the reader class + //! @param [in] filePath Path to E57 file + //! @param [in] options Options to be used for the file + Reader( const ustring &filePath, const ReaderOptions &options ); + //! @brief This function returns true if the file is open bool IsOpen() const; diff --git a/src/E57SimpleReader.cpp b/src/E57SimpleReader.cpp index b2ca220..4fbd0a7 100644 --- a/src/E57SimpleReader.cpp +++ b/src/E57SimpleReader.cpp @@ -31,7 +31,13 @@ namespace e57 { - Reader::Reader( const ustring &filePath ) : impl_( new ReaderImpl( filePath ) ) + // Note that this constructor is deprecated (see header). + Reader::Reader( const ustring &filePath ) : Reader( filePath, {} ) + { + } + + Reader::Reader( const ustring &filePath, const ReaderOptions &options ) : + impl_( new ReaderImpl( filePath, options ) ) { } diff --git a/src/ReaderImpl.cpp b/src/ReaderImpl.cpp index f84b584..ec7fa0a 100644 --- a/src/ReaderImpl.cpp +++ b/src/ReaderImpl.cpp @@ -30,8 +30,8 @@ namespace e57 { - ReaderImpl::ReaderImpl( const ustring &filePath ) : - imf_( filePath, "r" ), root_( imf_.root() ), data3D_( root_.get( "/data3D" ) ), + ReaderImpl::ReaderImpl( const ustring &filePath, const ReaderOptions &options ) : + imf_( filePath, "r", options.checksumPolicy ), root_( imf_.root() ), data3D_( root_.get( "/data3D" ) ), images2D_( root_.isDefined( "/images2D" ) ? root_.get( "/images2D" ) : VectorNode( imf_ ) ) { } diff --git a/src/ReaderImpl.h b/src/ReaderImpl.h index 6399084..1324f6b 100644 --- a/src/ReaderImpl.h +++ b/src/ReaderImpl.h @@ -28,6 +28,7 @@ #pragma once #include "E57SimpleData.h" +#include "E57SimpleReader.h" namespace e57 { @@ -36,7 +37,7 @@ namespace e57 class ReaderImpl { public: - explicit ReaderImpl( const ustring &filePath ); + explicit ReaderImpl( const ustring &filePath, const ReaderOptions &options ); ~ReaderImpl(); diff --git a/test/src/test_SimpleReader.cpp b/test/src/test_SimpleReader.cpp index 3fc099d..4144ec9 100644 --- a/test/src/test_SimpleReader.cpp +++ b/test/src/test_SimpleReader.cpp @@ -23,14 +23,14 @@ namespace TEST( SimpleReader, PathError ) { - E57_ASSERT_THROW( e57::Reader( "./no-path/empty.e57" ) ); + E57_ASSERT_THROW( e57::Reader( "./no-path/empty.e57", {} ) ); } TEST( SimpleReaderData, ReadEmpty ) { e57::Reader *reader = nullptr; - E57_ASSERT_NO_THROW( reader = new e57::Reader( TestData::Path() + "/self/empty.e57" ) ); + E57_ASSERT_NO_THROW( reader = new e57::Reader( TestData::Path() + "/self/empty.e57", {} ) ); ASSERT_TRUE( reader->IsOpen() ); EXPECT_EQ( reader->GetImage2DCount(), 0 ); @@ -47,7 +47,12 @@ TEST( SimpleReaderData, ReadEmpty ) TEST( SimpleReaderData, BadCRC ) { - E57_ASSERT_THROW( e57::Reader( TestData::Path() + "/self/bad-crc.e57" ) ); + E57_ASSERT_THROW( e57::Reader( TestData::Path() + "/self/bad-crc.e57", {} ) ); +} + +TEST( SimpleReaderData, DoNotCheckCRC ) +{ + E57_ASSERT_NO_THROW( e57::Reader( TestData::Path() + "/self/bad-crc.e57", { e57::CHECKSUM_POLICY_NONE } ) ); } // https://github.com/asmaloney/libE57Format/issues/26 @@ -55,7 +60,7 @@ TEST( SimpleReaderData, BadCRC ) TEST( SimpleReaderData, ReadChineseFileName ) { E57_ASSERT_NO_THROW( - e57::Reader( TestData::Path() + "/self/\xe6\xb5\x8b\xe8\xaf\x95\xe7\x82\xb9\xe4\xba\x91.e57" ) ); + e57::Reader( TestData::Path() + "/self/\xe6\xb5\x8b\xe8\xaf\x95\xe7\x82\xb9\xe4\xba\x91.e57", {} ) ); } // https://github.com/asmaloney/libE57Format/issues/69 @@ -64,14 +69,14 @@ TEST( SimpleReaderData, ReadChineseFileName ) // TEST( SimpleReaderData, ReadUmlautFileName ) //{ // E57_ASSERT_NO_THROW( -// e57::Reader( TestData::Path() + "/self/test filename \x61\xcc\x88\x6f\xcc\x88\x75\xcc\x88.e57" ) ); +// e57::Reader( TestData::Path() + "/self/test filename \x61\xcc\x88\x6f\xcc\x88\x75\xcc\x88.e57", {} ) ); //} TEST( SimpleReaderData, ReadBunnyDouble ) { e57::Reader *reader = nullptr; - E57_ASSERT_NO_THROW( reader = new e57::Reader( TestData::Path() + "/reference/bunnyDouble.e57" ) ); + E57_ASSERT_NO_THROW( reader = new e57::Reader( TestData::Path() + "/reference/bunnyDouble.e57", {} ) ); ASSERT_TRUE( reader->IsOpen() ); EXPECT_EQ( reader->GetImage2DCount(), 0 ); @@ -115,7 +120,7 @@ TEST( SimpleReaderData, ReadBunnyInt32 ) { e57::Reader *reader = nullptr; - E57_ASSERT_NO_THROW( reader = new e57::Reader( TestData::Path() + "/reference/bunnyInt32.e57" ) ); + E57_ASSERT_NO_THROW( reader = new e57::Reader( TestData::Path() + "/reference/bunnyInt32.e57", {} ) ); ASSERT_TRUE( reader->IsOpen() ); EXPECT_EQ( reader->GetImage2DCount(), 0 );