Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to simple reader constructor #139

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion include/E57SimpleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 7 additions & 1 deletion src/E57SimpleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/ReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_ ) )
{
}
Expand Down
3 changes: 2 additions & 1 deletion src/ReaderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#pragma once

#include "E57SimpleData.h"
#include "E57SimpleReader.h"

namespace e57
{
Expand All @@ -36,7 +37,7 @@ namespace e57
class ReaderImpl
{
public:
explicit ReaderImpl( const ustring &filePath );
explicit ReaderImpl( const ustring &filePath, const ReaderOptions &options );

~ReaderImpl();

Expand Down
19 changes: 12 additions & 7 deletions test/src/test_SimpleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -47,15 +47,20 @@ 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
// File name UTF-8 encoded to avoid editor issues.
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
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down