Mercurial > hg > svcore
comparison base/EventSeries.cpp @ 1833:21c792334c2e sensible-delimited-data-strings
Rewrite all the DelimitedDataString stuff so as to return vectors of individual cell strings rather than having the classes add the delimiters themselves. Rename accordingly to names based on StringExport. Take advantage of this in the CSV writer code so as to properly quote cells that contain delimiter characters.
author | Chris Cannam |
---|---|
date | Fri, 03 Apr 2020 17:11:05 +0100 |
parents | c546429d4c2f |
children |
comparison
equal
deleted
inserted
replaced
1832:7c92c644db20 | 1833:21c792334c2e |
---|---|
13 */ | 13 */ |
14 | 14 |
15 #include "EventSeries.h" | 15 #include "EventSeries.h" |
16 | 16 |
17 #include <QMutexLocker> | 17 #include <QMutexLocker> |
18 | |
19 using std::vector; | |
20 using std::string; | |
18 | 21 |
19 EventSeries::EventSeries(const EventSeries &other) : | 22 EventSeries::EventSeries(const EventSeries &other) : |
20 EventSeries(other, QMutexLocker(&other.m_mutex)) | 23 EventSeries(other, QMutexLocker(&other.m_mutex)) |
21 { | 24 { |
22 } | 25 } |
595 } | 598 } |
596 | 599 |
597 out << indent << "</dataset>\n"; | 600 out << indent << "</dataset>\n"; |
598 } | 601 } |
599 | 602 |
600 QString | 603 QVector<QString> |
601 EventSeries::getDelimitedDataHeaderLine(QString delimiter, | 604 EventSeries::getStringExportHeaders(DataExportOptions opts, |
602 DataExportOptions opts, | 605 Event::ExportNameOptions nopts) const |
603 Event::ExportNameOptions nopts) const | |
604 { | 606 { |
605 if (m_events.empty()) { | 607 if (m_events.empty()) { |
606 return QString(); | 608 return {}; |
607 } else { | 609 } else { |
608 return m_events.begin()->getDelimitedDataHeaderLine(delimiter, | 610 return m_events.begin()->getStringExportHeaders(opts, nopts); |
609 opts, | 611 } |
610 nopts); | 612 } |
611 } | 613 |
612 } | 614 QVector<QVector<QString>> |
613 | 615 EventSeries::toStringExportRows(DataExportOptions options, |
614 QString | 616 sv_frame_t startFrame, |
615 EventSeries::toDelimitedDataString(QString delimiter, | 617 sv_frame_t duration, |
616 DataExportOptions options, | 618 sv_samplerate_t sampleRate, |
617 sv_frame_t startFrame, | 619 sv_frame_t resolution, |
618 sv_frame_t duration, | 620 Event fillEvent) const |
619 sv_samplerate_t sampleRate, | 621 { |
620 sv_frame_t resolution, | 622 QMutexLocker locker(&m_mutex); |
621 Event fillEvent) const | 623 |
622 { | 624 QVector<QVector<QString>> rows; |
623 QMutexLocker locker(&m_mutex); | |
624 | |
625 QString s; | |
626 | 625 |
627 const sv_frame_t end = startFrame + duration; | 626 const sv_frame_t end = startFrame + duration; |
628 | 627 |
629 auto pitr = lower_bound(m_events.begin(), m_events.end(), | 628 auto pitr = lower_bound(m_events.begin(), m_events.end(), |
630 Event(startFrame)); | 629 Event(startFrame)); |
631 | 630 |
632 if (!(options & DataExportFillGaps)) { | 631 if (!(options & DataExportFillGaps)) { |
633 | 632 |
634 while (pitr != m_events.end() && pitr->getFrame() < end) { | 633 while (pitr != m_events.end() && pitr->getFrame() < end) { |
635 s += pitr->toDelimitedDataString(delimiter, | 634 rows.push_back(pitr->toStringExportRow(options, sampleRate)); |
636 options, | |
637 sampleRate); | |
638 s += "\n"; | |
639 ++pitr; | 635 ++pitr; |
640 } | 636 } |
641 | 637 |
642 } else { | 638 } else { |
643 | 639 |
657 | 653 |
658 // now progress, either writing the next point (if within | 654 // now progress, either writing the next point (if within |
659 // distance) or a default fill point | 655 // distance) or a default fill point |
660 while (f < end) { | 656 while (f < end) { |
661 if (pitr != m_events.end() && pitr->getFrame() <= f) { | 657 if (pitr != m_events.end() && pitr->getFrame() <= f) { |
662 s += pitr->toDelimitedDataString | 658 rows.push_back(pitr->toStringExportRow |
663 (delimiter, | 659 (options & ~DataExportFillGaps, |
664 options & ~DataExportFillGaps, | 660 sampleRate)); |
665 sampleRate); | |
666 ++pitr; | 661 ++pitr; |
667 } else { | 662 } else { |
668 s += fillEvent.withFrame(f).toDelimitedDataString | 663 rows.push_back(fillEvent.withFrame(f).toStringExportRow |
669 (delimiter, | 664 (options & ~DataExportFillGaps, |
670 options & ~DataExportFillGaps, | 665 sampleRate)); |
671 sampleRate); | 666 } |
672 } | |
673 s += "\n"; | |
674 f += resolution; | 667 f += resolution; |
675 } | 668 } |
676 } | 669 } |
677 | 670 |
678 return s; | 671 return rows; |
679 } | 672 } |
680 | 673 |