diff --git a/six/modules/c++/six.sidd/include/six/sidd/DerivedData.h b/six/modules/c++/six.sidd/include/six/sidd/DerivedData.h index 91dd9a95c..4eee55263 100644 --- a/six/modules/c++/six.sidd/include/six/sidd/DerivedData.h +++ b/six/modules/c++/six.sidd/include/six/sidd/DerivedData.h @@ -19,9 +19,9 @@ * see . * */ +#pragma once #ifndef SIX_six_sidd_DerivedData_h_INCLUDED_ #define SIX_six_sidd_DerivedData_h_INCLUDED_ -#pragma once #include @@ -44,8 +44,42 @@ namespace six { +// Emphasize that this is for SIDD 3.0.0 +namespace sidd300 +{ + // We have to support two ISM versions with SIDD 3.0 :-( + enum class ISMVersion + { + v201609, // the "newer" version; default + v13, // the "original" version + + current = v201609 + }; + std::string to_string(ISMVersion); // "v201609" or "v13" + + ISMVersion get(ISMVersion defaultIfNotSet); // overloaded on ISMVersion + std::optional set(ISMVersion); // returns previous value, if any + std::optional getISMVersion(); + std::optional clearISMVersion(); // returns previous value, if any + + std::vector find_SIDD_schema_V_files(const std::vector& schemaPaths); +} + namespace sidd { +// six.sidd only currently supports -- +// SIDD 1.0.0 +// SIDD 2.0.0 +// SIDD 3.0.0 +enum class Version +{ + v100, + v200, + v300, +}; +std::string to_string(Version); // "1.0.0", "2.0.0", "3.0.0" +Version normalizeVersion(const std::string&); + /*! * \class DerivedData * \brief The implementation of Data for derived products @@ -54,7 +88,7 @@ namespace sidd * Contains the structs that are the model for SIDD products * */ -struct DerivedData: public Data +struct DerivedData : public Data { /*! * Information related to processor, classification, @@ -142,6 +176,8 @@ struct DerivedData: public Data * rather than invoking this object directly. */ DerivedData(); + DerivedData(Version); + DerivedData(Version, six::sidd300::ISMVersion); // SIDD 3.0.0 must use this overload /*! * We are dealing with derived data @@ -316,15 +352,14 @@ struct DerivedData: public Data return std::string(VENDOR_ID); } - virtual std::string getVersion() const - { - return mVersion; - } + virtual std::string getVersion() const; + virtual void setVersion(const std::string&); + void setVersion(const std::string&, six::sidd300::ISMVersion); // SIDD 3.0.0 must use this overload - virtual void setVersion(const std::string& strVersion) - { - mVersion = strVersion; - } + Version getSIDDVersion() const; + void setSIDDVersion(Version); + void setSIDDVersion(Version, six::sidd300::ISMVersion); // SIDD 3.0.0 must use this overload + six::sidd300::ISMVersion getISMVersion() const; /* * Convert the output plane pixel location into meters from the reference @@ -341,7 +376,9 @@ struct DerivedData: public Data bool operator_eq(const DerivedData& rhs) const; static const char VENDOR_ID[]; bool equalTo(const Data& rhs) const override; - std::string mVersion; + + Version mVersion = Version::v100; // existing code + six::sidd300::ISMVersion mISMVersion = six::sidd300::ISMVersion::current; // only for SIDD 3.0.0 }; } } diff --git a/six/modules/c++/six.sidd/include/six/sidd/DerivedXMLControl.h b/six/modules/c++/six.sidd/include/six/sidd/DerivedXMLControl.h index abc832dee..ae761fafa 100644 --- a/six/modules/c++/six.sidd/include/six/sidd/DerivedXMLControl.h +++ b/six/modules/c++/six.sidd/include/six/sidd/DerivedXMLControl.h @@ -19,8 +19,9 @@ * see . * */ -#ifndef __SIX_DERIVED_XML_CONTROL_H__ -#define __SIX_DERIVED_XML_CONTROL_H__ +#pragma once +#ifndef SIX_six_sidd_DerivedXMLControl_h_INCLUDED_ +#define SIX_six_sidd_DerivedXMLControl_h_INCLUDED_ #include #include @@ -28,46 +29,13 @@ #include #include +#include #include namespace six { - -// Emphasize that this is for SIDD 3.0.0 -namespace sidd300 -{ - // We have to support two ISM versions with SIDD 3.0 :-( - enum class ISMVersion - { - v201609, // the "newer" version; default - v13, // the "original" version - - current = v201609 - }; - std::string to_string(ISMVersion); // "v201609" or "v13" - - ISMVersion get(ISMVersion defaultIfNotSet); // overloaded on ISMVersion - std::optional set(ISMVersion); // returns previous value, if any - std::optional getISMVersion(); - std::optional clearISMVersion(); // returns previous value, if any - - std::vector find_SIDD_schema_V_files(const std::vector& schemaPaths); -} - namespace sidd { - // six.sidd only currently supports -- - // SIDD 1.0.0 - // SIDD 2.0.0 - // SIDD 3.0.0 - enum class Version - { - v100, - v200, - v300, - }; - std::string to_string(Version); // "v100", "v200", "v300" - /*! * \class DerivedXMLControl * \brief Turns an DerivedData object into XML and vice versa @@ -117,5 +85,4 @@ struct DerivedXMLControl : public XMLControl } } -#endif - +#endif // SIX_six_sidd_DerivedXMLControl_h_INCLUDED_ diff --git a/six/modules/c++/six.sidd/include/six/sidd/DerivedXMLParser.h b/six/modules/c++/six.sidd/include/six/sidd/DerivedXMLParser.h index 6e21d63ec..ffc160e52 100644 --- a/six/modules/c++/six.sidd/include/six/sidd/DerivedXMLParser.h +++ b/six/modules/c++/six.sidd/include/six/sidd/DerivedXMLParser.h @@ -19,8 +19,9 @@ * see . * */ -#ifndef __SIX_SIDD_DERIVED_XML_PARSER_H__ -#define __SIX_SIDD_DERIVED_XML_PARSER_H__ +#pragma once +#ifndef SIX_six_sidd_DerivedXMLParser_h_INCLUDED_ +#define SIX_six_sidd_DerivedXMLParser_h_INCLUDED_ #include #include @@ -58,13 +59,13 @@ struct DerivedXMLParser : public six::XMLParser XMLElem parent = nullptr) const; protected: - DerivedXMLParser(const std::string& version, + DerivedXMLParser(Version, std::unique_ptr&& comParser, logging::Logger* log = nullptr, bool ownLog = false); - DerivedXMLParser(const std::string& version, + DerivedXMLParser(Version, std::unique_ptr&&, std::unique_ptr&&); - DerivedXMLParser(const std::string& version, + DerivedXMLParser(Version, std::unique_ptr&&, logging::Logger&); @@ -235,10 +236,9 @@ struct DerivedXMLParser : public six::XMLParser XMLElem parsePlaneProjection(const xml::lite::Element* projElem, const Measurement& measurement) const; XMLElem parseCylindricalProjection(const xml::lite::Element* projElem, const Measurement& measurement) const; - static - std::string versionToURI(const std::string& strVersion) + static std::string versionToURI(Version siddVersion) { - return ("urn:SIDD:" + strVersion); + return "urn:SIDD:" + to_string(siddVersion); } private: @@ -247,4 +247,4 @@ struct DerivedXMLParser : public six::XMLParser } } -#endif +#endif // SIX_six_sidd_DerivedXMLParser_h_INCLUDED_ diff --git a/six/modules/c++/six.sidd/include/six/sidd/Utilities.h b/six/modules/c++/six.sidd/include/six/sidd/Utilities.h index 91b495b48..1bc5713bd 100644 --- a/six/modules/c++/six.sidd/include/six/sidd/Utilities.h +++ b/six/modules/c++/six.sidd/include/six/sidd/Utilities.h @@ -19,8 +19,9 @@ * see . * */ -#ifndef __SIX_SIDD_UTILITIES_H__ -#define __SIX_SIDD_UTILITIES_H__ +#pragma once +#ifndef SIX_six_sidd_Utilities_h_INCLUDED_ +#define SIX_six_sidd_Utilities_h_INCLUDED_ #include #include @@ -31,6 +32,7 @@ #include #include #include +#include namespace six { @@ -82,8 +84,8 @@ class Utilities * \return mock DerivedData object */ static std::unique_ptr createFakeDerivedData(); - static std::unique_ptr createFakeDerivedData(const std::string& strVersion); - + static std::unique_ptr createFakeDerivedData(Version); + static std::unique_ptr createFakeDerivedData(Version, six::sidd300::ISMVersion); // for SIDD 3.0.0 /* * Parses the XML in 'xmlStream' and converts it into a DerivedData object. @@ -156,4 +158,4 @@ class Utilities }; } } -#endif +#endif // SIX_six_sidd_Utilities_h_INCLUDED_ diff --git a/six/modules/c++/six.sidd/source/DerivedData.cpp b/six/modules/c++/six.sidd/source/DerivedData.cpp index 8e985035b..9e2930f35 100644 --- a/six/modules/c++/six.sidd/source/DerivedData.cpp +++ b/six/modules/c++/six.sidd/source/DerivedData.cpp @@ -30,9 +30,19 @@ namespace sidd { const char DerivedData::VENDOR_ID[] = "MDA-IS"; -DerivedData::DerivedData() : +DerivedData::DerivedData(Version siddVersion, six::sidd300::ISMVersion ismVersion) : productCreation(new ProductCreation), - mVersion("1.0.0") + mVersion(siddVersion), mISMVersion(ismVersion) +{ +} +DerivedData::DerivedData(Version siddVersion) : DerivedData(siddVersion, six::sidd300::get(six::sidd300::ISMVersion::current)) +{ + if (siddVersion == Version::v300) + { + throw std::invalid_argument("Must use ISMVersion overload."); + } +} +DerivedData::DerivedData() : DerivedData(Version::v100) // existing code { } @@ -89,7 +99,7 @@ DateTime DerivedData::getCollectionStartDateTime() const const mem::ScopedCopyablePtr& DerivedData::getDisplayLUT() const { - if (mVersion == "1.0.0") + if (mVersion == Version::v100) { if (display->remapInformation.get() == nullptr) { @@ -97,14 +107,12 @@ const mem::ScopedCopyablePtr& DerivedData::getDisplayLUT() const } return display->remapInformation->remapLUT; } - else if ((mVersion == "2.0.0") || (mVersion == "3.0.0")) + else if ((mVersion == Version::v200) || (mVersion == Version::v300)) { return nitfLUT; } - else - { - throw except::Exception(Ctxt("Unknown version. Expected 3.0.0, 2.0.0, or 1.0.0")); - } + + throw except::Exception(Ctxt("Unknown version. Expected 3.0.0, 2.0.0, or 1.0.0")); } void DerivedData::setDisplayLUT(std::unique_ptr&& pLUT) { @@ -166,5 +174,45 @@ bool DerivedData::equalTo(const Data& rhs) const } return false; } + +Version DerivedData::getSIDDVersion() const +{ + return mVersion; +} +std::string DerivedData::getVersion() const +{ + return to_string(getSIDDVersion()); +} + +void DerivedData::setSIDDVersion(Version siddVersion, six::sidd300::ISMVersion ismVersion) +{ + mVersion = siddVersion; + mISMVersion = ismVersion; +} +void DerivedData::setSIDDVersion(Version siddVersion) +{ + if (siddVersion == Version::v300) + { + throw std::invalid_argument("Must use ISMVersion overload."); // TODO + } + setSIDDVersion(siddVersion, six::sidd300::get(six::sidd300::ISMVersion::current)); +} + +void DerivedData::setVersion(const std::string& strVersion) +{ + // This is an `override` of `six::Data` so there's no way to pass + // as six::sidd300::ISMVersion for SIDD 3.0.0. + setVersion(strVersion, six::sidd300::get(six::sidd300::ISMVersion::current)); +} +void DerivedData::setVersion(const std::string& strVersion, six::sidd300::ISMVersion ismVersion) +{ + setSIDDVersion(normalizeVersion(strVersion), ismVersion); +} + +six::sidd300::ISMVersion DerivedData::getISMVersion() const +{ + return mISMVersion; +} + } } diff --git a/six/modules/c++/six.sidd/source/DerivedXMLControl.cpp b/six/modules/c++/six.sidd/source/DerivedXMLControl.cpp index 3c9c0de56..ba3c0e54a 100644 --- a/six/modules/c++/six.sidd/source/DerivedXMLControl.cpp +++ b/six/modules/c++/six.sidd/source/DerivedXMLControl.cpp @@ -37,9 +37,7 @@ #include #include -namespace -{ -six::sidd::Version normalizeVersion(const std::string& strVersion) +six::sidd::Version six::sidd::normalizeVersion(const std::string& strVersion) { std::vector versionParts; six::XMLControl::splitVersion(strVersion, versionParts); @@ -84,7 +82,6 @@ six::sidd::Version normalizeVersion(const std::string& strVersion) throw except::Exception(Ctxt("Unsupported SIDD Version: " + strVersion)); } -} namespace six { @@ -92,11 +89,12 @@ namespace sidd { std::string to_string(Version siddVersion) { + // Match "incoming" SIDD version strings; this is also what the XML expects, see normalizeVersion() switch (siddVersion) { - case Version::v100: return "v100"; - case Version::v200: return "v200"; - case Version::v300: return "v300"; + case Version::v100: return "1.0.0"; + case Version::v200: return "2.0.0"; + case Version::v300: return "3.0.0"; default: break; } throw std::logic_error("Unkown 'Version' value."); diff --git a/six/modules/c++/six.sidd/source/DerivedXMLParser.cpp b/six/modules/c++/six.sidd/source/DerivedXMLParser.cpp index 34594a106..4f88c5676 100644 --- a/six/modules/c++/six.sidd/source/DerivedXMLParser.cpp +++ b/six/modules/c++/six.sidd/source/DerivedXMLParser.cpp @@ -43,17 +43,14 @@ namespace sidd { const char DerivedXMLParser::SFA_URI[] = "urn:SFA:1.2.0"; -DerivedXMLParser::DerivedXMLParser(const std::string& strVersion, - std::unique_ptr&& comParser, - logging::Logger* log, bool ownLog) : XMLParser(versionToURI(strVersion), false, log, ownLog), +DerivedXMLParser::DerivedXMLParser(Version siddVersion, std::unique_ptr&& comParser, + logging::Logger* log, bool ownLog) : XMLParser(versionToURI(siddVersion), false, log, ownLog), mCommon(std::move(comParser)) { } -DerivedXMLParser::DerivedXMLParser(const std::string& strVersion, - std::unique_ptr&& comParser, - std::unique_ptr&& log) : XMLParser(versionToURI(strVersion), false, std::move(log)), +DerivedXMLParser::DerivedXMLParser(Version siddVersion, std::unique_ptr&& comParser, + std::unique_ptr&& log) : XMLParser(versionToURI(siddVersion), false, std::move(log)), mCommon(std::move(comParser)) { } -DerivedXMLParser::DerivedXMLParser(const std::string& strVersion, - std::unique_ptr&& comParser, - logging::Logger& log) : XMLParser(versionToURI(strVersion), false, log), +DerivedXMLParser::DerivedXMLParser(Version siddVersion, std::unique_ptr&& comParser, + logging::Logger& log) : XMLParser(versionToURI(siddVersion), false, log), mCommon(std::move(comParser)) { } void DerivedXMLParser::getAttributeList( diff --git a/six/modules/c++/six.sidd/source/DerivedXMLParser100.cpp b/six/modules/c++/six.sidd/source/DerivedXMLParser100.cpp index 93d658e89..d9f5e4c6f 100644 --- a/six/modules/c++/six.sidd/source/DerivedXMLParser100.cpp +++ b/six/modules/c++/six.sidd/source/DerivedXMLParser100.cpp @@ -34,7 +34,7 @@ namespace six { namespace sidd { -const char VERSION[] = "1.0.0"; +constexpr Version VERSION = Version::v100; const char SI_COMMON_URI[] = "urn:SICommon:0.1"; const char ISM_URI[] = "urn:us:gov:ic:ism"; inline static xml::lite::Uri getISMUri() diff --git a/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp b/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp index de52840aa..9228dabd7 100644 --- a/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp +++ b/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp @@ -113,7 +113,7 @@ ProjectionType DerivedXMLParser200::getProjectionType(const xml::lite::Element& } -const char VERSION[] = "2.0.0"; +constexpr Version VERSION = Version::v200; const char SI_COMMON_URI[] = "urn:SICommon:1.0"; inline static xml::lite::Uri getISMUri() { diff --git a/six/modules/c++/six.sidd/source/DerivedXMLParser300.cpp b/six/modules/c++/six.sidd/source/DerivedXMLParser300.cpp index b5751945c..7392a50d5 100644 --- a/six/modules/c++/six.sidd/source/DerivedXMLParser300.cpp +++ b/six/modules/c++/six.sidd/source/DerivedXMLParser300.cpp @@ -39,24 +39,16 @@ namespace six { namespace sidd { -static const char VERSION[] = "3.0.0"; +constexpr Version VERSION = Version::v300; static const char SI_COMMON_URI[] = "urn:SICommon:1.0"; // There is a need to support two different versions of ISM with SIDD 3.0 :-( -inline static auto getISM_201609_Uri() -{ - return xml::lite::Uri("urn:us:gov:ic:ism:201609"); -} -inline static auto getISM_13_Uri() -{ - return xml::lite::Uri("urn:us:gov:ic:ism:13"); -} inline static xml::lite::Uri getISMUri(six::sidd300::ISMVersion ismVersion) { switch (ismVersion) { - case six::sidd300::ISMVersion::v201609: return getISM_201609_Uri(); - case six::sidd300::ISMVersion::v13: return getISM_13_Uri(); + case six::sidd300::ISMVersion::v201609: return xml::lite::Uri("urn:us:gov:ic:ism:201609"); + case six::sidd300::ISMVersion::v13: return xml::lite::Uri("urn:us:gov:ic:ism:13"); default: break; } diff --git a/six/modules/c++/six.sidd/source/Utilities.cpp b/six/modules/c++/six.sidd/source/Utilities.cpp index 9698b49bc..fc65f6f64 100644 --- a/six/modules/c++/six.sidd/source/Utilities.cpp +++ b/six/modules/c++/six.sidd/source/Utilities.cpp @@ -710,7 +710,20 @@ static void initDED(mem::ScopedCopyablePtr& ded ded->nullValue = -32768; } -static void initProductCreation(six::sidd::ProductCreation& productCreation, const std::string& strVersion) +static int32_t getDESVersion(six::sidd300::ISMVersion ismVersion) +{ + if (ismVersion == six::sidd300::ISMVersion::v13) + { + return 13; + } + if (ismVersion == six::sidd300::ISMVersion::v201609) + { + return 201609; + } + throw std::invalid_argument("Unknown 'ISMVersion' value."); +} + +static void initProductCreation(six::sidd::ProductCreation& productCreation, Version siddVersion, six::sidd300::ISMVersion ismVersion) { productCreation.productName = "ProductName"; productCreation.productClass = "Unclassified"; @@ -719,18 +732,18 @@ static void initProductCreation(six::sidd::ProductCreation& productCreation, con productCreation.productCreationExtensions.push_back(parameter); productCreation.classification.securityExtensions.push_back(parameter); - if (strVersion != "3.0.0") + if (siddVersion != Version::v300) { productCreation.classification.desVersion = 234; // existing code } else { - productCreation.classification.desVersion = 201609; // SIDD 3.0 + productCreation.classification.desVersion = getDESVersion(ismVersion); } productCreation.classification.createDate = six::DateTime(); productCreation.classification.classification = "U"; - if (strVersion == "1.0.0") + if (siddVersion == Version::v100) { productCreation.classification.compliesWith.push_back("ICD-710"); } @@ -934,7 +947,7 @@ static void initGeoData(six::GeoDataBase& geoData) geoData.geoInfos.push_back(newGeoInfo); } -static void initExploitationFeatures(six::sidd::ExploitationFeatures& exFeatures, const std::string& strVersion) +static void initExploitationFeatures(six::sidd::ExploitationFeatures& exFeatures, Version siddVersion) { // The first collection is corresponds to the parent image six::sidd::Collection& collection = *exFeatures.collections[0]; @@ -968,7 +981,7 @@ static void initExploitationFeatures(six::sidd::ExploitationFeatures& exFeatures polarization->txPolarization = six::PolarizationSequenceType::V; polarization->rcvPolarization = six::PolarizationSequenceType::OTHER; polarization->rcvPolarizationOffset = 1.37; - if (strVersion == "1.0.0") + if (siddVersion == Version::v100) { polarization->processed = six::BooleanType::IS_TRUE; } @@ -986,7 +999,7 @@ static void initExploitationFeatures(six::sidd::ExploitationFeatures& exFeatures collection.geometry->extensions.push_back(param); collection.phenomenology.reset(new six::sidd::Phenomenology()); - if (strVersion != "3.0.0") + if (siddVersion != Version::v300) { // [-180, 180) before SIDD 3.0 collection.phenomenology->shadow = six::AngleMagnitude(-1.5, 3.7); @@ -1008,7 +1021,7 @@ static void initExploitationFeatures(six::sidd::ExploitationFeatures& exFeatures exFeatures.product[0].north = 58.332; exFeatures.product[0].extensions.push_back(param); - if (strVersion == "2.0.0") + if (siddVersion == Version::v200) { exFeatures.product[0].ellipticity = 12.0; exFeatures.product[0].polarization.resize(1); @@ -1149,14 +1162,12 @@ static void initProductProcessing(six::sidd::ProductProcessing& processing) static void populateData(six::sidd::DerivedData& siddData, const std::string& lutType = "Mono") { - const auto strVersion = siddData.getVersion(); + const auto siddVersion = siddData.getSIDDVersion(); constexpr bool smallImage = true; - - siddData.setVersion(strVersion); const auto elementSize = static_cast(lutType == "Mono" ? 2 : 3); - if ((strVersion == "2.0.0") || (strVersion == "3.0.0")) + if ((siddVersion == Version::v200) || (siddVersion == Version::v300)) { // This will naturally get constructed in the course of 1.0.0 // Separate field in 2.0.0 @@ -1181,7 +1192,7 @@ static void populateData(six::sidd::DerivedData& siddData, const std::string& lu //siddData.setImageCorners(makeUpCornersFromDMS()); // Can certainly be init'ed in a function - initProductCreation(*siddData.productCreation, strVersion); + initProductCreation(*siddData.productCreation, siddVersion, siddData.getISMVersion()); // Or directly if preferred siddData.display->decimationMethod = DecimationMethod::BRIGHTEST_PIXEL; @@ -1238,7 +1249,7 @@ static void populateData(six::sidd::DerivedData& siddData, const std::string& lu planeProjection->productPlane.rowUnitVector = six::Vector3(0.0); planeProjection->productPlane.colUnitVector = six::Vector3(0.0); - initExploitationFeatures(*siddData.exploitationFeatures, strVersion); + initExploitationFeatures(*siddData.exploitationFeatures, siddVersion); initDED(siddData.digitalElevationData); initProductProcessing(*siddData.productProcessing); initDownstreamReprocessing(*siddData.downstreamReprocessing); @@ -1307,10 +1318,10 @@ static void update_for_SIDD_300(DerivedData& data) // n.b., much of this was add populateData(data); } -static std::unique_ptr createFakeDerivedData_(const std::string& strVersion) +static std::unique_ptr createFakeDerivedData_(const Version* pSiddVersion, const six::sidd300::ISMVersion* pISMVersion = nullptr) { std::unique_ptr data; - if (!strVersion.empty()) // preserve behavior of existing code + if (pSiddVersion != nullptr) // preserve behavior of existing code { //----------------------------------------------------------- // Make the object. You could do this directly, but this way @@ -1346,11 +1357,18 @@ static std::unique_ptr createFakeDerivedData_(const std::string& st data = std::make_unique(); } - if (!strVersion.empty()) + if (pSiddVersion != nullptr) { - data->setVersion(strVersion); + if (pISMVersion != nullptr) + { + data->setSIDDVersion(*pSiddVersion, *pISMVersion); + } + else + { + data->setSIDDVersion(*pSiddVersion); + } } - data->productCreation.reset(new ProductCreation()); + data->productCreation->classification.classification = "U"; data->display.reset(new Display()); data->geographicAndTarget.reset(new GeographicAndTarget()); @@ -1406,24 +1424,36 @@ static std::unique_ptr createFakeDerivedData_(const std::string& st data->exploitationFeatures->product[0].resolution.row = 0; data->exploitationFeatures->product[0].resolution.col = 0; - if (!strVersion.empty()) // TODO: better check for version; this avoid changing any existing test code + if (pSiddVersion != nullptr) // TODO: better check for version; this avoid changing any existing test code { update_for_SIDD_300(*data); } return data; } -std::unique_ptr Utilities::createFakeDerivedData(const std::string& strVersion) +std::unique_ptr Utilities::createFakeDerivedData(Version siddVersion) +{ + if (siddVersion == Version::v300) + { + throw std::invalid_argument("Must use ISMVersion overload."); + } + if (siddVersion == Version::v200) + { + return createFakeDerivedData_(&siddVersion); + } + throw std::invalid_argument("SIDD version = '" + to_string(siddVersion) + "' is not supported."); +} +std::unique_ptr Utilities::createFakeDerivedData(Version siddVersion, six::sidd300::ISMVersion ismVersion) { - if ((strVersion == "2.0.0") || (strVersion == "3.0.0")) + if (siddVersion != Version::v300) { - return createFakeDerivedData_(strVersion); + return createFakeDerivedData(siddVersion); } - throw std::invalid_argument("strVersion = '" + strVersion + "' is not supported."); + return createFakeDerivedData_(&siddVersion, &ismVersion); } std::unique_ptr Utilities::createFakeDerivedData() { - return std::unique_ptr(createFakeDerivedData_("").release()); + return createFakeDerivedData_(nullptr); } } diff --git a/six/modules/c++/six.sidd/unittests/test_valid_sixsidd.cpp b/six/modules/c++/six.sidd/unittests/test_valid_sixsidd.cpp index d56fe85fc..036d1d939 100644 --- a/six/modules/c++/six.sidd/unittests/test_valid_sixsidd.cpp +++ b/six/modules/c++/six.sidd/unittests/test_valid_sixsidd.cpp @@ -75,9 +75,9 @@ static std::unique_ptr test_assert_round_trip(const std: return six::sidd::Utilities::parseDataFromString(strXML, pSchemaPaths); } -inline static const six::UnmodeledS* get_Unmodeled(const six::sidd::DerivedData& derivedData, const std::string& strVersion) +inline static const six::UnmodeledS* get_Unmodeled(const six::sidd::DerivedData& derivedData, six::sidd::Version siddVersion) { - if (strVersion != "3.0.0") // Unmodeled added in SIDD 3.0 + if (siddVersion != six::sidd::Version::v300) // Unmodeled added in SIDD 3.0 { return nullptr; } @@ -87,28 +87,33 @@ inline static const six::UnmodeledS* get_Unmodeled(const six::sidd::DerivedData& } } -static void test_createFakeDerivedData_(const std::string& testName, const std::string& strVersion, bool validate) +static void test_createFakeDerivedData_(const std::string& testName, bool validate, + six::sidd::Version siddVersion, six::sidd300::ISMVersion ismVersion) { - const auto pFakeDerivedData = six::sidd::Utilities::createFakeDerivedData(strVersion); - auto Unmodeled = get_Unmodeled(*pFakeDerivedData, strVersion); + const auto pFakeDerivedData = six::sidd::Utilities::createFakeDerivedData(siddVersion, ismVersion); + auto Unmodeled = get_Unmodeled(*pFakeDerivedData, siddVersion); TEST_ASSERT_NULL(Unmodeled); // not part of the fake data, only added in SIDD 3.0 const auto schemaPaths = getSchemaPaths(); const std::vector* pSchemaPaths = validate ? & schemaPaths: nullptr; // NULL schemaPaths, no validation auto pDerivedData = test_assert_round_trip(testName, *pFakeDerivedData, pSchemaPaths); - Unmodeled = get_Unmodeled(*pDerivedData, strVersion); + Unmodeled = get_Unmodeled(*pDerivedData, siddVersion); TEST_ASSERT_NULL(Unmodeled); // not part of the fake data, only added in SIDD 3.0 } TEST_CASE(test_createFakeDerivedData) { - test_createFakeDerivedData_(testName, "2.0.0", false /*validate*/); - test_createFakeDerivedData_(testName, "3.0.0", false /*validate*/); + test_createFakeDerivedData_(testName, false /*validate*/, six::sidd::Version::v200, six::sidd300::get(six::sidd300::ISMVersion::current)); + + test_createFakeDerivedData_(testName, false /*validate*/, six::sidd::Version::v300, six::sidd300::ISMVersion::v13); + test_createFakeDerivedData_(testName, false /*validate*/, six::sidd::Version::v300, six::sidd300::ISMVersion::v201609); } TEST_CASE(test_createFakeDerivedData_validate) { - test_createFakeDerivedData_(testName, "2.0.0", true /*validate*/); - test_createFakeDerivedData_(testName, "3.0.0", true /*validate*/); + test_createFakeDerivedData_(testName, true /*validate*/, six::sidd::Version::v200, six::sidd300::get(six::sidd300::ISMVersion::current)); + + test_createFakeDerivedData_(testName, true /*validate*/, six::sidd::Version::v300, six::sidd300::ISMVersion::v13); + test_createFakeDerivedData_(testName, true /*validate*/, six::sidd::Version::v300, six::sidd300::ISMVersion::v201609); } static void test_assert_unmodeled_(const std::string& testName, const six::UnmodeledS& Unmodeled)