From 595dafd656f63d3db5b38e1a124a1a99f551649a 2017-09-28 09:12:18 From: Alexandre Leroux Date: 2017-09-28 09:12:18 Subject: [PATCH] Generates vectors (3) Creates type according to the metadata --- diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index 682c347..7c9f3d5 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -50,6 +50,21 @@ struct VectorCosinus : public ICosinusType { } }; +/// Converts string to cosinus type +/// @return the cosinus type if the string could be converted, nullptr otherwise +std::unique_ptr cosinusType(const QString &type) noexcept +{ + if (type.compare(QStringLiteral("scalar"), Qt::CaseInsensitive) == 0) { + return std::make_unique(); + } + else if (type.compare(QStringLiteral("vector"), Qt::CaseInsensitive) == 0) { + return std::make_unique(); + } + else { + return nullptr; + } +} + } // namespace std::shared_ptr CosinusProvider::clone() const @@ -65,6 +80,19 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, // TODO: Add Mutex auto dataIndex = 0; + // Retrieves cosinus type + auto typeVariant = data.value(COSINUS_TYPE_KEY, COSINUS_TYPE_DEFAULT_VALUE); + if (!typeVariant.canConvert()) { + qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid type"); + return nullptr; + } + + auto type = cosinusType(typeVariant.toString()); + if (!type) { + qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: unknown type"); + return nullptr; + } + // Retrieves frequency auto freqVariant = data.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE); if (!freqVariant.canConvert()) {