Mercurial > hg > svcore
changeset 1438:09c2ba31a711 streaming-csv-writer
Formatting and naming changes more in line with SV conventions.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Tue, 17 Apr 2018 10:03:49 +0100 |
parents | de385fed1197 |
children | 9d4d4de3dced |
files | data/fileio/CSVFileWriter.cpp data/fileio/CSVFileWriter.h data/fileio/CSVStreamWriter.h data/fileio/test/CSVStreamWriterTest.h |
diffstat | 4 files changed, 31 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fileio/CSVFileWriter.cpp Tue Apr 17 10:03:49 2018 +0100 +++ b/data/fileio/CSVFileWriter.cpp Tue Apr 17 10:03:49 2018 +0100 @@ -88,7 +88,7 @@ bool completed = false; for (const auto& bounds : selection->getSelections()) { - completed = CSV::writeToStreamInChunks( + completed = CSVStreamWriter::writeInChunks( out, *m_model, bounds,
--- a/data/fileio/CSVFileWriter.h Tue Apr 17 10:03:49 2018 +0100 +++ b/data/fileio/CSVFileWriter.h Tue Apr 17 10:03:49 2018 +0100 @@ -35,13 +35,12 @@ QString delimiter = ",", DataExportOptions options = DataExportDefaults); - CSVFileWriter( - QString path, - Model *model, - ProgressReporter *reporter, - QString delimiter = ",", - DataExportOptions options = DataExportDefaults - ) : CSVFileWriter(path, model, delimiter, options) + CSVFileWriter(QString path, + Model *model, + ProgressReporter *reporter, + QString delimiter = ",", + DataExportOptions options = DataExportDefaults) + : CSVFileWriter(path, model, delimiter, options) { m_reporter = reporter; }
--- a/data/fileio/CSVStreamWriter.h Tue Apr 17 10:03:49 2018 +0100 +++ b/data/fileio/CSVStreamWriter.h Tue Apr 17 10:03:49 2018 +0100 @@ -4,7 +4,7 @@ Sonic Visualiser An audio file viewer and annotation editor. Centre for Digital Music, Queen Mary, University of London. - This file copyright 2017 Lucas Thompson. + This file copyright 2017 Queen Mary, University of London. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _CSV_STREAM_WRITER_H_ -#define _CSV_STREAM_WRITER_H_ +#ifndef CSV_STREAM_WRITER_H +#define CSV_STREAM_WRITER_H #include "base/BaseTypes.h" #include "base/Selection.h" @@ -24,20 +24,17 @@ #include <QString> #include <algorithm> -namespace CSV +namespace CSVStreamWriter { -using Completed = bool; template <class OutStream> -auto writeToStreamInChunks( - OutStream& oss, - const Model& model, - const Selection& extents, - ProgressReporter* reporter = nullptr, - QString delimiter = ",", - DataExportOptions options = DataExportDefaults, - const sv_frame_t blockSize = 16384 -) -> Completed +bool writeInChunks(OutStream& oss, + const Model& model, + const Selection& extents, + ProgressReporter* reporter = nullptr, + QString delimiter = ",", + DataExportOptions options = DataExportDefaults, + const sv_frame_t blockSize = 16384) { if (blockSize <= 0) return false; sv_frame_t readPtr = extents.isEmpty() ? @@ -76,17 +73,15 @@ } template <class OutStream> -auto writeToStreamInChunks( - OutStream& oss, - const Model& model, - ProgressReporter* reporter = nullptr, - QString delimiter = ",", - DataExportOptions options = DataExportDefaults, - const sv_frame_t blockSize = 16384 -) -> Completed +bool writeInChunks(OutStream& oss, + const Model& model, + ProgressReporter* reporter = nullptr, + QString delimiter = ",", + DataExportOptions options = DataExportDefaults, + const sv_frame_t blockSize = 16384) { const Selection empty; - return CSV::writeToStreamInChunks( + return CSV::writeInChunks( oss, model, empty, @@ -96,5 +91,5 @@ blockSize ); } -} // namespace +} // namespace CSVStreamWriter #endif \ No newline at end of file
--- a/data/fileio/test/CSVStreamWriterTest.h Tue Apr 17 10:03:49 2018 +0100 +++ b/data/fileio/test/CSVStreamWriterTest.h Tue Apr 17 10:03:49 2018 +0100 @@ -4,7 +4,7 @@ Sonic Visualiser An audio file viewer and annotation editor. Centre for Digital Music, Queen Mary, University of London. - This file copyright 2017 Lucas Thompson. + This file copyright 2017 Queen Mary, University of London. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -87,7 +87,7 @@ MockWaveModel mwm({ DC, DC }, 16, 4); std::ostringstream oss; - const auto result = CSV::writeToStreamInChunks(oss, mwm); + const auto result = CSVStreamWriter::writeInChunks(oss, mwm); QVERIFY( oss.str() == getExpectedString() ); QVERIFY( result ); } @@ -100,7 +100,7 @@ std::ostringstream oss; const auto writeStreamWithBlockSize = [&](int blockSize) { - return CSV::writeToStreamInChunks( + return CSVStreamWriter::writeInChunks( oss, mwm, &reporter, @@ -144,7 +144,7 @@ StubReporter reporter { []() -> bool { return true; } }; std::ostringstream oss; - const auto cancelImmediately = CSV::writeToStreamInChunks( + const auto cancelImmediately = CSVStreamWriter::writeInChunks( oss, mwm, &reporter, @@ -158,7 +158,7 @@ StubReporter cancelMidway { [&]() { return cancelMidway.getCallCount() == 3; } }; - const auto cancelledMidway = CSV::writeToStreamInChunks( + const auto cancelledMidway = CSVStreamWriter::writeInChunks( oss, mwm, &cancelMidway,