From ae9bbf7aeb40cb9fee16ecc1f10772ebc7a2bd89 Mon Sep 17 00:00:00 2001 From: Simon Richter Date: Sat, 4 Mar 2017 16:03:28 +0100 Subject: [PATCH] Fix building benchmark test Passing a wxString to std::ifstream::ifstream() is ambiguous, at least on MSVC. --- tools/io_benchmark/io_benchmark.cpp | 49 ++++++++++---------- tools/io_benchmark/stdstream_line_reader.cpp | 8 ++-- tools/io_benchmark/stdstream_line_reader.h | 4 +- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/tools/io_benchmark/io_benchmark.cpp b/tools/io_benchmark/io_benchmark.cpp index 1d70711998..9442d9317a 100644 --- a/tools/io_benchmark/io_benchmark.cpp +++ b/tools/io_benchmark/io_benchmark.cpp @@ -32,6 +32,7 @@ #include #include +#include #include "stdstream_line_reader.h" @@ -55,7 +56,7 @@ struct BENCH_REPORT }; -using BENCH_FUNC = std::function; +using BENCH_FUNC = std::function; struct BENCHMARK @@ -70,13 +71,13 @@ struct BENCHMARK * Benchmark using a raw std::ifstream, with no LINE_READER * wrapper. The stream is recreated for each cycle. */ -static void bench_fstream( const wxString& aFile, int aReps, BENCH_REPORT& report ) +static void bench_fstream( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { std::string line; for( int i = 0; i < aReps; ++i) { - std::ifstream fstr( aFile ); + std::ifstream fstr( aFile.GetFullPath().ToUTF8() ); while( getline( fstr, line ) ) { @@ -93,10 +94,10 @@ static void bench_fstream( const wxString& aFile, int aReps, BENCH_REPORT& repor * Benchmark using a raw std::ifstream, with no LINE_READER * wrapper. The stream is not recreated for each cycle, just reset. */ -static void bench_fstream_reuse( const wxString& aFile, int aReps, BENCH_REPORT& report ) +static void bench_fstream_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { std::string line; - std::ifstream fstr( aFile ); + std::ifstream fstr( aFile.GetFullPath().ToUTF8() ); for( int i = 0; i < aReps; ++i) { @@ -118,11 +119,11 @@ static void bench_fstream_reuse( const wxString& aFile, int aReps, BENCH_REPORT& * The LINE_READER is recreated for each cycle. */ template -static void bench_line_reader( const wxString& aFile, int aReps, BENCH_REPORT& report ) +static void bench_line_reader( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { for( int i = 0; i < aReps; ++i) { - LR fstr( aFile ); + LR fstr( aFile.GetFullName() ); while( fstr.ReadLine() ) { report.linesRead++; @@ -137,9 +138,9 @@ static void bench_line_reader( const wxString& aFile, int aReps, BENCH_REPORT& r * The LINE_READER is rewound for each cycle, not recreated. */ template -static void bench_line_reader_reuse( const wxString& aFile, int aReps, BENCH_REPORT& report ) +static void bench_line_reader_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - LR fstr( aFile ); + LR fstr( aFile.GetFullName() ); for( int i = 0; i < aReps; ++i) { @@ -160,13 +161,13 @@ static void bench_line_reader_reuse( const wxString& aFile, int aReps, BENCH_REP * The wxInputStream is recreated for each cycle. */ template -static void bench_wxis( const wxString& aFile, int aReps, BENCH_REPORT& report ) +static void bench_wxis( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - S fileStream( aFile ); + S fileStream( aFile.GetFullName() ); for( int i = 0; i < aReps; ++i) { - INPUTSTREAM_LINE_READER istr( &fileStream, aFile ); + INPUTSTREAM_LINE_READER istr( &fileStream, aFile.GetFullName() ); while( istr.ReadLine() ) { @@ -185,10 +186,10 @@ static void bench_wxis( const wxString& aFile, int aReps, BENCH_REPORT& report ) * The wxInputStream is reset for each cycle. */ template -static void bench_wxis_reuse( const wxString& aFile, int aReps, BENCH_REPORT& report ) +static void bench_wxis_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - S fileStream( aFile ); - INPUTSTREAM_LINE_READER istr( &fileStream, aFile ); + S fileStream( aFile.GetFullName() ); + INPUTSTREAM_LINE_READER istr( &fileStream, aFile.GetFullName() ); for( int i = 0; i < aReps; ++i) { @@ -209,14 +210,14 @@ static void bench_wxis_reuse( const wxString& aFile, int aReps, BENCH_REPORT& re * The wxInputStream is recreated for each cycle. */ template -static void bench_wxbis( const wxString& aFile, int aReps, BENCH_REPORT& report ) +static void bench_wxbis( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - WXIS fileStream( aFile ); + WXIS fileStream( aFile.GetFullName() ); wxBufferedInputStream bufferedStream( fileStream ); for( int i = 0; i < aReps; ++i) { - INPUTSTREAM_LINE_READER istr( &bufferedStream, aFile ); + INPUTSTREAM_LINE_READER istr( &bufferedStream, aFile.GetFullName() ); while( istr.ReadLine() ) { @@ -235,12 +236,12 @@ static void bench_wxbis( const wxString& aFile, int aReps, BENCH_REPORT& report * The wxInputStream is reset for each cycle. */ template -static void bench_wxbis_reuse( const wxString& aFile, int aReps, BENCH_REPORT& report ) +static void bench_wxbis_reuse( const wxFileName& aFile, int aReps, BENCH_REPORT& report ) { - WXIS fileStream( aFile ); + WXIS fileStream( aFile.GetFullName() ); wxBufferedInputStream bufferedStream( fileStream ); - INPUTSTREAM_LINE_READER istr( &bufferedStream, aFile ); + INPUTSTREAM_LINE_READER istr( &bufferedStream, aFile.GetFullName() ); for( int i = 0; i < aReps; ++i) { @@ -310,7 +311,7 @@ static wxString getBenchDescriptions() BENCH_REPORT executeBenchMark( const BENCHMARK& aBenchmark, int aReps, - const wxString& aFilename ) + const wxFileName& aFilename ) { BENCH_REPORT report = {}; @@ -345,7 +346,7 @@ int main( int argc, char* argv[] ) return BAD_ARGS; } - wxString inFile( argv[1] ); + wxFileName inFile( argv[1] ); long reps = 0; wxString( argv[2] ).ToLong( &reps ); @@ -357,7 +358,7 @@ int main( int argc, char* argv[] ) os << "IO Bench Mark Util" << std::endl; - os << " Benchmark file: " << inFile << std::endl; + os << " Benchmark file: " << inFile.GetFullName() << std::endl; os << " Repetitions: " << (int) reps << std::endl; os << std::endl; diff --git a/tools/io_benchmark/stdstream_line_reader.cpp b/tools/io_benchmark/stdstream_line_reader.cpp index ce0042f773..a45131b864 100644 --- a/tools/io_benchmark/stdstream_line_reader.cpp +++ b/tools/io_benchmark/stdstream_line_reader.cpp @@ -67,19 +67,19 @@ void STDISTREAM_LINE_READER::setStream( std::istream& aStream ) } -IFSTREAM_LINE_READER::IFSTREAM_LINE_READER( const wxString& aFileName ) throw( IO_ERROR ) : - m_fStream( aFileName ) +IFSTREAM_LINE_READER::IFSTREAM_LINE_READER( const wxFileName& aFileName ) throw( IO_ERROR ) : + m_fStream( aFileName.GetFullName().ToUTF8() ) { if( !m_fStream.is_open() ) { wxString msg = wxString::Format( - _( "Unable to open filename '%s' for reading" ), aFileName.GetData() ); + _( "Unable to open filename '%s' for reading" ), aFileName.GetFullPath().GetData() ); THROW_IO_ERROR( msg ); } setStream( m_fStream ); - source = aFileName; + source = aFileName.GetFullName(); } diff --git a/tools/io_benchmark/stdstream_line_reader.h b/tools/io_benchmark/stdstream_line_reader.h index 1fa18a262d..2cee6090c4 100644 --- a/tools/io_benchmark/stdstream_line_reader.h +++ b/tools/io_benchmark/stdstream_line_reader.h @@ -24,6 +24,8 @@ #ifndef FSTREAM_LINE_READER_H #define FSTREAM_LINE_READER_H +#include + #include #include @@ -59,7 +61,7 @@ class IFSTREAM_LINE_READER : public STDISTREAM_LINE_READER { public: - IFSTREAM_LINE_READER( const wxString& aFileName ) throw( IO_ERROR ); + IFSTREAM_LINE_READER( const wxFileName& aFileName ) throw( IO_ERROR ); void Rewind();