From: Michal MalĂ˝ Date: Fri, 17 Apr 2015 17:01:10 +0000 (+0200) Subject: Use std::vector instead of plain array to store supported output formats X-Git-Tag: 0.5c~10 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=b25d0a1eb8dc45d85ac0b7955e9c426d5de103d0;p=anyanka.git Use std::vector instead of plain array to store supported output formats --- diff --git a/datafileexporter.cpp b/datafileexporter.cpp index d1b3294..27eb5a3 100644 --- a/datafileexporter.cpp +++ b/datafileexporter.cpp @@ -28,7 +28,8 @@ #include #include -const OutputFormat DataFileExporter::SUPPORTED_FORMATS[] = { OutputFormat("Comma separated values", "csv") }; + +const std::vector DataFileExporter::SUPPORTED_FORMATS({DataFileExporter::OutputFormat("Comma separated values", "csv")}); /* Static methods */ QStringList DataFileExporter::supportedFormats() @@ -36,7 +37,7 @@ QStringList DataFileExporter::supportedFormats() QStringList list; for (const OutputFormat& of : SUPPORTED_FORMATS) { - list << of.first; + list << of.description; } return list; @@ -59,7 +60,7 @@ exportData(const WriteList& list, const QString& path, const int formatIdx) DataFileExporter::ReturnCode ret; DataWriterBackend* backend; - if (formatIdx < 0 || formatIdx >= sizeof(SUPPORTED_FORMATS)) { + if (formatIdx < 0 || formatIdx >= SUPPORTED_FORMATS.size()) { return ReturnCode::E_INVAL_FORMAT; } @@ -154,10 +155,9 @@ void DataFileExporter::guessFormatFromSuffix(const QString& name) if (suffix.length() == 0) return; - for (size_t i = 0; i < sizeof(SUPPORTED_FORMATS); i++) { - const OutputFormat& of = SUPPORTED_FORMATS[i]; - if (suffix.compare(of.second) == 0) { - emit formatChanged(i); + for (int idx = 0; idx < SUPPORTED_FORMATS.size(); idx++) { + if (suffix.compare(SUPPORTED_FORMATS[idx].suffix) == 0) { + emit formatChanged(idx); return; } } diff --git a/datafileexporter.h b/datafileexporter.h index 136000e..447eb25 100644 --- a/datafileexporter.h +++ b/datafileexporter.h @@ -31,8 +31,6 @@ #include #include -typedef std::pair OutputFormat; - class DataFileExporter : public QObject { Q_OBJECT @@ -56,12 +54,19 @@ private: CSV, INVALID }; + struct OutputFormat { + OutputFormat(const QString& description, const QString& suffix) : + description(description), suffix(suffix) {} + + const QString description; + const QString suffix; + }; OutputFormats formatIdxToFormat(const int idx); QString toCSVLine(double time, double value); ReturnCode writeToFile(QFile& file, const DataWriterBackend* writer, const std::pair>& data); - static const OutputFormat SUPPORTED_FORMATS[]; + static const std::vector SUPPORTED_FORMATS; signals: void formatChanged(const int idx);