From d3daab81283b2ed38f17fd0112094f4cba9a5fe0 2017-12-21 16:38:01 From: Alexandre Leroux Date: 2017-12-21 16:38:01 Subject: [PATCH] Move the AMDA data type to a type accessible from core --- diff --git a/core/include/Data/DataSeriesType.h b/core/include/Data/DataSeriesType.h new file mode 100644 index 0000000..d019c83 --- /dev/null +++ b/core/include/Data/DataSeriesType.h @@ -0,0 +1,26 @@ +#ifndef SCIQLOP_DATASERIESTYPE_H +#define SCIQLOP_DATASERIESTYPE_H + +#include + +enum class DataSeriesType { SCALAR, SPECTROGRAM, VECTOR, UNKNOWN }; + +struct DataSeriesTypeUtils { + static DataSeriesType fromString(const QString &type) + { + if (type == QStringLiteral("scalar")) { + return DataSeriesType::SCALAR; + } + else if (type == QStringLiteral("spectrogram")) { + return DataSeriesType::SPECTROGRAM; + } + else if (type == QStringLiteral("vector")) { + return DataSeriesType::VECTOR; + } + else { + return DataSeriesType::UNKNOWN; + } + } +}; + +#endif // SCIQLOP_DATASERIESTYPE_H diff --git a/plugins/amda/include/AmdaResultParser.h b/plugins/amda/include/AmdaResultParser.h index b078f97..3601406 100644 --- a/plugins/amda/include/AmdaResultParser.h +++ b/plugins/amda/include/AmdaResultParser.h @@ -3,6 +3,8 @@ #include "AmdaGlobal.h" +#include + #include #include @@ -12,10 +14,8 @@ class IDataSeries; Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaResultParser) struct SCIQLOP_AMDA_EXPORT AmdaResultParser { - enum class ValueType { SCALAR, SPECTROGRAM, VECTOR, UNKNOWN }; - static std::shared_ptr readTxt(const QString &filePath, - ValueType valueType) noexcept; + DataSeriesType valueType) noexcept; }; #endif // SCIQLOP_AMDARESULTPARSER_H diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index 63e2ffc..ff7d177 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -39,21 +39,6 @@ QString dateFormat(double sqpRange) noexcept return dateTime.toString(AMDA_TIME_FORMAT); } -AmdaResultParser::ValueType valueType(const QString &valueType) -{ - if (valueType == QStringLiteral("scalar")) { - return AmdaResultParser::ValueType::SCALAR; - } - else if (valueType == QStringLiteral("spectrogram")) { - return AmdaResultParser::ValueType::SPECTROGRAM; - } - else if (valueType == QStringLiteral("vector")) { - return AmdaResultParser::ValueType::VECTOR; - } - else { - return AmdaResultParser::ValueType::UNKNOWN; - } -} } // namespace @@ -171,7 +156,8 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa // Retrieves the data type that determines whether the expected format for the result file is // scalar, vector... - auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString()); + auto productValueType + = DataSeriesTypeUtils::fromString(data.value(AMDA_DATA_TYPE_KEY).toString()); // /////////// // // Creates URL // diff --git a/plugins/amda/src/AmdaResultParser.cpp b/plugins/amda/src/AmdaResultParser.cpp index 7259f3c..2051e91 100644 --- a/plugins/amda/src/AmdaResultParser.cpp +++ b/plugins/amda/src/AmdaResultParser.cpp @@ -24,16 +24,16 @@ bool isCommentLine(const QString &line) * @param valueType the type of values expected in the AMDA file (scalars, vectors, spectrograms...) * @return the helper created */ -std::unique_ptr createHelper(AmdaResultParser::ValueType valueType) +std::unique_ptr createHelper(DataSeriesType valueType) { switch (valueType) { - case AmdaResultParser::ValueType::SCALAR: + case DataSeriesType::SCALAR: return std::make_unique(); - case AmdaResultParser::ValueType::SPECTROGRAM: + case DataSeriesType::SPECTROGRAM: return std::make_unique(); - case AmdaResultParser::ValueType::VECTOR: + case DataSeriesType::VECTOR: return std::make_unique(); - case AmdaResultParser::ValueType::UNKNOWN: + case DataSeriesType::UNKNOWN: // Invalid case break; } @@ -82,9 +82,9 @@ void readResults(IAmdaResultParserHelper &helper, QTextStream &stream) } // namespace std::shared_ptr AmdaResultParser::readTxt(const QString &filePath, - ValueType valueType) noexcept + DataSeriesType type) noexcept { - if (valueType == ValueType::UNKNOWN) { + if (type == DataSeriesType::UNKNOWN) { qCCritical(LOG_AmdaResultParser()) << QObject::tr("Can't retrieve AMDA data: the type of values to be read is unknown"); return nullptr; @@ -110,7 +110,7 @@ std::shared_ptr AmdaResultParser::readTxt(const QString &filePath, return nullptr; } - auto helper = createHelper(valueType); + auto helper = createHelper(type); Q_ASSERT(helper != nullptr); // Reads header file to retrieve properties diff --git a/plugins/amda/tests/TestAmdaAcquisition.cpp b/plugins/amda/tests/TestAmdaAcquisition.cpp index ca3b239..218b31f 100644 --- a/plugins/amda/tests/TestAmdaAcquisition.cpp +++ b/plugins/amda/tests/TestAmdaAcquisition.cpp @@ -115,7 +115,7 @@ void TestAmdaAcquisition::testAcquisition() // Retrieves data file QFETCH(QString, dataFilename); auto filePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath(); - auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR); + auto results = AmdaResultParser::readTxt(filePath, DataSeriesType::SCALAR); /// Lambda used to validate a variable at each step auto validateVariable = [results](std::shared_ptr variable, const SqpRange &range) { diff --git a/plugins/amda/tests/TestAmdaResultParser.cpp b/plugins/amda/tests/TestAmdaResultParser.cpp index 78d8bb3..713eb14 100644 --- a/plugins/amda/tests/TestAmdaResultParser.cpp +++ b/plugins/amda/tests/TestAmdaResultParser.cpp @@ -187,7 +187,7 @@ private: } template - void testRead(AmdaResultParser::ValueType valueType) + void testRead(DataSeriesType valueType) { QFETCH(QString, inputFileName); QFETCH(ExpectedResults, expectedResults); @@ -319,7 +319,7 @@ void TestAmdaResultParser::testReadScalarTxt_data() void TestAmdaResultParser::testReadScalarTxt() { - testRead(AmdaResultParser::ValueType::SCALAR); + testRead(DataSeriesType::SCALAR); } void TestAmdaResultParser::testReadSpectrogramTxt_data() @@ -533,7 +533,7 @@ void TestAmdaResultParser::testReadSpectrogramTxt_data() void TestAmdaResultParser::testReadSpectrogramTxt() { - testRead(AmdaResultParser::ValueType::SPECTROGRAM); + testRead(DataSeriesType::SPECTROGRAM); } void TestAmdaResultParser::testReadVectorTxt_data() @@ -572,7 +572,7 @@ void TestAmdaResultParser::testReadVectorTxt_data() void TestAmdaResultParser::testReadVectorTxt() { - testRead(AmdaResultParser::ValueType::VECTOR); + testRead(DataSeriesType::VECTOR); } QTEST_MAIN(TestAmdaResultParser)