Mercurial > hg > svcore
comparison data/fileio/CSVStreamWriter.h @ 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 | 0684c6698e3f |
children | 51493540a753 |
comparison
equal
deleted
inserted
replaced
1437:de385fed1197 | 1438:09c2ba31a711 |
---|---|
2 | 2 |
3 /* | 3 /* |
4 Sonic Visualiser | 4 Sonic Visualiser |
5 An audio file viewer and annotation editor. | 5 An audio file viewer and annotation editor. |
6 Centre for Digital Music, Queen Mary, University of London. | 6 Centre for Digital Music, Queen Mary, University of London. |
7 This file copyright 2017 Lucas Thompson. | 7 This file copyright 2017 Queen Mary, University of London. |
8 | 8 |
9 This program is free software; you can redistribute it and/or | 9 This program is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU General Public License as | 10 modify it under the terms of the GNU General Public License as |
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #ifndef _CSV_STREAM_WRITER_H_ | 16 #ifndef CSV_STREAM_WRITER_H |
17 #define _CSV_STREAM_WRITER_H_ | 17 #define CSV_STREAM_WRITER_H |
18 | 18 |
19 #include "base/BaseTypes.h" | 19 #include "base/BaseTypes.h" |
20 #include "base/Selection.h" | 20 #include "base/Selection.h" |
21 #include "base/ProgressReporter.h" | 21 #include "base/ProgressReporter.h" |
22 #include "base/DataExportOptions.h" | 22 #include "base/DataExportOptions.h" |
23 #include "data/model/Model.h" | 23 #include "data/model/Model.h" |
24 #include <QString> | 24 #include <QString> |
25 #include <algorithm> | 25 #include <algorithm> |
26 | 26 |
27 namespace CSV | 27 namespace CSVStreamWriter |
28 { | 28 { |
29 using Completed = bool; | |
30 | 29 |
31 template <class OutStream> | 30 template <class OutStream> |
32 auto writeToStreamInChunks( | 31 bool writeInChunks(OutStream& oss, |
33 OutStream& oss, | 32 const Model& model, |
34 const Model& model, | 33 const Selection& extents, |
35 const Selection& extents, | 34 ProgressReporter* reporter = nullptr, |
36 ProgressReporter* reporter = nullptr, | 35 QString delimiter = ",", |
37 QString delimiter = ",", | 36 DataExportOptions options = DataExportDefaults, |
38 DataExportOptions options = DataExportDefaults, | 37 const sv_frame_t blockSize = 16384) |
39 const sv_frame_t blockSize = 16384 | |
40 ) -> Completed | |
41 { | 38 { |
42 if (blockSize <= 0) return false; | 39 if (blockSize <= 0) return false; |
43 sv_frame_t readPtr = extents.isEmpty() ? | 40 sv_frame_t readPtr = extents.isEmpty() ? |
44 model.getStartFrame() : extents.getStartFrame(); | 41 model.getStartFrame() : extents.getStartFrame(); |
45 sv_frame_t endFrame = extents.isEmpty() ? | 42 sv_frame_t endFrame = extents.isEmpty() ? |
74 } | 71 } |
75 return !wasCancelled(); // setProgress could process event loop | 72 return !wasCancelled(); // setProgress could process event loop |
76 } | 73 } |
77 | 74 |
78 template <class OutStream> | 75 template <class OutStream> |
79 auto writeToStreamInChunks( | 76 bool writeInChunks(OutStream& oss, |
80 OutStream& oss, | 77 const Model& model, |
81 const Model& model, | 78 ProgressReporter* reporter = nullptr, |
82 ProgressReporter* reporter = nullptr, | 79 QString delimiter = ",", |
83 QString delimiter = ",", | 80 DataExportOptions options = DataExportDefaults, |
84 DataExportOptions options = DataExportDefaults, | 81 const sv_frame_t blockSize = 16384) |
85 const sv_frame_t blockSize = 16384 | |
86 ) -> Completed | |
87 { | 82 { |
88 const Selection empty; | 83 const Selection empty; |
89 return CSV::writeToStreamInChunks( | 84 return CSV::writeInChunks( |
90 oss, | 85 oss, |
91 model, | 86 model, |
92 empty, | 87 empty, |
93 reporter, | 88 reporter, |
94 delimiter, | 89 delimiter, |
95 options, | 90 options, |
96 blockSize | 91 blockSize |
97 ); | 92 ); |
98 } | 93 } |
99 } // namespace | 94 } // namespace CSVStreamWriter |
100 #endif | 95 #endif |