Mercurial > hg > svcore
changeset 1447:5bd240517c1a streaming-csv-writer
Fix multi-selection output line break issue, compare against end frame of last region.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Tue, 17 Apr 2018 10:03:50 +0100 |
parents | 0a743cd7b83d |
children | 8305d442d1f7 |
files | data/fileio/CSVStreamWriter.h |
diffstat | 1 files changed, 7 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fileio/CSVStreamWriter.h Tue Apr 17 10:03:50 2018 +0100 +++ b/data/fileio/CSVStreamWriter.h Tue Apr 17 10:03:50 2018 +0100 @@ -38,17 +38,19 @@ DataExportOptions options = DataExportDefaults, const sv_frame_t blockSize = 16384) { - if (blockSize <= 0) return false; + const auto selections = regions.getSelections(); + if (blockSize <= 0 || selections.empty()) return false; // TODO, some form of checking validity of selections? const auto nFramesToWrite = std::accumulate( - regions.getSelections().begin(), - regions.getSelections().end(), + selections.begin(), + selections.end(), 0, [](sv_frame_t acc, const Selection& current) -> sv_frame_t { return acc + (current.getEndFrame() - current.getStartFrame()); } ); + const auto finalFrameOfLastRegion = (*selections.crbegin()).getEndFrame(); const auto wasCancelled = [&reporter]() { return reporter && reporter->wasCancelled(); @@ -57,7 +59,7 @@ sv_frame_t nFramesWritten = 0; int previousProgress = 0; - for (const auto& extents : regions.getSelections()) { + for (const auto& extents : selections) { const auto startFrame = extents.getStartFrame(); const auto endFrame = extents.getEndFrame(); auto readPtr = startFrame; @@ -72,7 +74,7 @@ options, start, end - ) << (end < endFrame ? "\n" : ""); + ) << (end < finalFrameOfLastRegion ? "\n" : ""); nFramesWritten += end - start; const auto currentProgress = 100 * nFramesWritten / nFramesToWrite; const bool hasIncreased = currentProgress > previousProgress;