Skip to content

Commit

Permalink
Merge branch 'master' into develop/update-externals
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Aug 10, 2022
2 parents 1f80869 + f0b4d42 commit cd60927
Show file tree
Hide file tree
Showing 22 changed files with 163 additions and 72 deletions.
6 changes: 6 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# SIX [Release](https://github.com/ngageoint/six-library/releases) Notes

## [Version 3.?.??](https://github.com/ngageoint/six-library/releases/tag/SIX-3.?.??); ??? ?, 202?
* [coda-oss](https://github.com/mdaus/coda-oss) version [202?-??-??](https://github.com/mdaus/coda-oss/releases/tag/202?-??-??)
* [nitro](https://github.com/mdaus/nitro) version [2.??.??](https://github.com/mdaus/nitro/releases/tag/NITRO-2.??.??)
* Routines that "traffic" in XML strings (e.g., `parseDataFromString()` or `toXMLString()`) now use
`std::u8string` (actually `coda_oss::u8string`) instead of `std::string`.

## [Version 3.1.13](https://github.com/ngageoint/six-library/releases/tag/SIX-3.1.13); August 2, 2022
* [coda-oss](https://github.com/mdaus/coda-oss) version [2022-08-02](https://github.com/mdaus/coda-oss/releases/tag/2022-08-02)
* [nitro](https://github.com/mdaus/nitro) version [2.10.11](https://github.com/mdaus/nitro/releases/tag/NITRO-2.10.11)
Expand Down
5 changes: 5 additions & 0 deletions six/modules/c++/cphd/include/cphd/CPHDXMLControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <unordered_map>
#include <std/filesystem>
#include <vector>
#include <std/string>

#include <scene/sys_Conf.h>
#include <xml/lite/Element.h>
Expand Down Expand Up @@ -87,6 +88,10 @@ class CPHDXMLControl
const Metadata& metadata,
const std::vector<std::string>& schemaPaths = std::vector<std::string>(),
bool prettyPrint = false);
virtual std::u8string toXMLString(
const Metadata& metadata,
const std::vector<std::filesystem::path>* pSchemaPaths,
bool prettyPrint = false);

/*!
* \func toXML
Expand Down
3 changes: 1 addition & 2 deletions six/modules/c++/cphd/source/CPHDWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ void CPHDWriter::writeMetadata(size_t supportSize,
size_t pvpSize,
size_t cphdSize)
{
const std::string xmlMetadata(
CPHDXMLControl().toXMLString(mMetadata, mSchemaPaths));
const auto xmlMetadata(CPHDXMLControl().toXMLString(mMetadata, mSchemaPaths));

// update header version, or remains default if unset
mHeader.setVersion(mMetadata.getVersion());
Expand Down
35 changes: 28 additions & 7 deletions six/modules/c++/cphd/source/CPHDXMLControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
#include <unordered_map>
#include <algorithm>
#include <std/memory>
#include <iterator>

#include <io/StringStream.h>
#include <logging/NullLogger.h>
#include <xml/lite/MinidomParser.h>
#include <str/EncodedStringView.h>

#include <six/XMLControl.h>
#include <six/XmlLite.h>
Expand All @@ -50,18 +52,37 @@ CPHDXMLControl::CPHDXMLControl(logging::Logger* log, bool ownLog) :
}

/* TO XML */
std::string CPHDXMLControl::toXMLString(
const Metadata& metadata,
const std::vector<std::string>& schemaPaths,
bool prettyPrint)
std::u8string CPHDXMLControl::toXMLString(
const Metadata& metadata,
const std::vector<std::filesystem::path>* pSchemaPaths,
bool prettyPrint)
{
std::vector<std::string> schemaPaths;
if (pSchemaPaths != nullptr)
{
std::transform(pSchemaPaths->begin(), pSchemaPaths->end(), std::back_inserter(schemaPaths),
[](const std::filesystem::path& p) { return p.string(); });
}

std::unique_ptr<xml::lite::Document> doc(toXML(metadata, schemaPaths));
io::StringStream ss;
io::U8StringStream ss;
(prettyPrint) ?
doc->getRootElement()->prettyPrint(ss) :
doc->getRootElement()->print(ss);
doc->getRootElement()->prettyPrint(ss) :
doc->getRootElement()->print(ss);
return ss.stream().str();
}
std::string CPHDXMLControl::toXMLString(
const Metadata& metadata,
const std::vector<std::string>& schemaPaths_,
bool prettyPrint)
{
std::vector<std::filesystem::path> schemaPaths;
std::transform(schemaPaths_.begin(), schemaPaths_.end(), std::back_inserter(schemaPaths),
[](const std::string& s) { return s; });

const auto result = toXMLString(metadata, &schemaPaths, prettyPrint);
return str::EncodedStringView(result).native();
}

mem::auto_ptr<xml::lite::Document> CPHDXMLControl::toXML(
const Metadata& metadata,
Expand Down
2 changes: 1 addition & 1 deletion six/modules/c++/cphd/tests/test_metadata_round.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool testEqual(const std::string& inPathname, const std::string& outPathname,
const std::unique_ptr<cphd::Metadata> metadata =
xmlControl.fromXML(xmlParser.getDocument(), schemas);

const std::string xmlMetadata(xmlControl.toXMLString(*metadata));
const auto xmlMetadata(xmlControl.toXMLString(*metadata));

//Output XML file to temp file
io::FileOutputStream ofs(outPathname);
Expand Down
5 changes: 4 additions & 1 deletion six/modules/c++/cphd03/include/cphd03/CPHDXMLControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ class CPHDXMLControl : public six::XMLParser
Metadata fromXML(const xml::lite::Document& doc);

mem::auto_ptr<Metadata> fromXML(const std::string& xmlString);
std::unique_ptr<Metadata> fromXML(const std::u8string& xmlString);

std::string toXMLString_(const Metadata& metadata);
std::u8string toXMLString(const Metadata& metadata);

std::string toXMLString(const Metadata& metadata);
size_t getXMLsize(const Metadata& metadata);

private:
Expand Down
2 changes: 1 addition & 1 deletion six/modules/c++/cphd03/source/CPHDWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void CPHDWriter::writeMetadata(size_t vbmSize,
const std::string& classification,
const std::string& releaseInfo)
{
const std::string xmlMetadata(CPHDXMLControl().toXMLString(mMetadata));
const auto xmlMetadata(CPHDXMLControl().toXMLString(mMetadata));

FileHeader header;
if (!classification.empty())
Expand Down
11 changes: 8 additions & 3 deletions six/modules/c++/cphd03/source/CPHDXMLControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <io/StringStream.h>
#include <logging/NullLogger.h>
#include <str/EncodedStringView.h>
#include <six/Utilities.h>
#include <six/XmlLite.h>

Expand Down Expand Up @@ -63,13 +64,17 @@ std::string CPHDXMLControl::getSICommonURI() const
return CPHD03_URI;
}

std::string CPHDXMLControl::toXMLString(const Metadata& metadata)
std::u8string CPHDXMLControl::toXMLString(const Metadata& metadata)
{
std::unique_ptr<xml::lite::Document> doc(toXML( metadata));
io::StringStream ss;
io::U8StringStream ss;
doc->getRootElement()->print(ss);

return (std::string("<?xml version=\"1.0\"?>") + ss.stream().str());
return str::EncodedStringView("<?xml version=\"1.0\"?>").u8string() + ss.stream().str();
}
std::string CPHDXMLControl::toXMLString_(const Metadata& metadata)
{
return str::EncodedStringView(toXMLString(metadata)).native();
}

size_t CPHDXMLControl::getXMLsize(const Metadata& metadata)
Expand Down
2 changes: 1 addition & 1 deletion six/modules/c++/samples/extract_cphd_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int main(int argc, char** argv)
// Reads in CPHD and verifies XML using schema
cphd::CPHDReader reader(inputFile, std::thread::hardware_concurrency());
cphd::CPHDXMLControl xmlControl;
std::string xml = xmlControl.toXMLString(reader.getMetadata(), schemaPathnames, prettyPrint);
const auto xml = xmlControl.toXMLString(reader.getMetadata(), schemaPathnames, prettyPrint);

std::unique_ptr<io::OutputStream> os;
if (toConsole)
Expand Down
4 changes: 2 additions & 2 deletions six/modules/c++/six.sicd/include/six/sicd/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class Utilities
* \return Data representation of 'xmlStr'
*/
static mem::auto_ptr<ComplexData> parseDataFromString(
const std::u8string& xmlStr,
const std::string& xmlStr,
const std::vector<std::string>& schemaPaths,
logging::Logger& log);
static std::unique_ptr<ComplexData> parseDataFromString(
Expand All @@ -453,7 +453,7 @@ class Utilities
*
* \return XML string representation of 'data'
*/
static std::u8string toXMLString(
static std::string toXMLString(
const ComplexData& data,
const std::vector<std::string>& schemaPaths = std::vector<std::string>(),
logging::Logger* logger = nullptr);
Expand Down
36 changes: 18 additions & 18 deletions six/modules/c++/six.sicd/source/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <six/sicd/ComplexXMLControl.h>
#include <six/sicd/SICDMesh.h>
#include <str/Manip.h>
#include <str/EncodedStringView.h>
#include <sys/Conf.h>
#include <types/RowCol.h>
#include <units/Angles.h>
Expand Down Expand Up @@ -1024,11 +1025,11 @@ std::unique_ptr<ComplexData> Utilities::parseDataFromFile(const std::filesystem:
}

mem::auto_ptr<ComplexData> Utilities::parseDataFromString(
const std::u8string& xmlStr,
const std::string& xmlStr,
const std::vector<std::string>& schemaPaths,
logging::Logger& log)
{
io::U8StringStream inStream;
io::StringStream inStream;
inStream.write(xmlStr);
return parseData(inStream, schemaPaths, log);
}
Expand All @@ -1043,28 +1044,27 @@ std::unique_ptr<ComplexData> Utilities::parseDataFromString(const std::u8string&
return parseData(inStream, pSchemaPaths, *log);
}

template<typename TSchemaPaths>
std::u8string Utilities_toXMLString(const ComplexData& data,
const TSchemaPaths& schemaPaths, logging::Logger* pLogger)
std::string Utilities::toXMLString(const ComplexData& data,
const std::vector<std::string>& schemaPaths_,
logging::Logger* logger)
{
std::vector<std::filesystem::path> schemaPaths;
std::transform(schemaPaths_.begin(), schemaPaths_.end(), std::back_inserter(schemaPaths),
[](const std::string& s) { return s; });

const auto result = toXMLString(data, &schemaPaths, logger);
return str::EncodedStringView(result).native();
}
std::u8string Utilities::toXMLString(const ComplexData& data,
const std::vector<std::filesystem::path>* pSchemaPaths, logging::Logger* pLogger)
{
XMLControlRegistry xmlRegistry;
xmlRegistry.addCreator<ComplexXMLControl>();

logging::NullLogger nullLogger;
logging::Logger* const logger = (pLogger == nullptr) ? &nullLogger : pLogger;
logging::Logger* const pLogger_ = (pLogger == nullptr) ? &nullLogger : pLogger;

return ::six::toValidXMLString(data, schemaPaths, logger, &xmlRegistry);
}
std::u8string Utilities::toXMLString(const ComplexData& data,
const std::vector<std::string>& schemaPaths,
logging::Logger* logger)
{
return Utilities_toXMLString(data, schemaPaths, logger);
}
std::u8string Utilities::toXMLString(const ComplexData& data,
const std::vector<std::filesystem::path>* pSchemaPaths, logging::Logger* logger)
{
return Utilities_toXMLString(data, pSchemaPaths, logger);
return ::six::toValidXMLString(data, pSchemaPaths, pLogger_, &xmlRegistry);
}

static void update_for_SICD_130(ComplexData& data)
Expand Down
6 changes: 2 additions & 4 deletions six/modules/c++/six.sicd/unittests/test_CollectionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ TEST_CASE(Classification)
data->collectionInformation->setClassificationLevel(classificationText);
TEST_ASSERT_TRUE(data->getClassification().isUnclassified());

const std::vector<std::string> schemaPaths;
io::U8StringStream ss;
ss.stream() << six::sicd::Utilities::toXMLString(*data, schemaPaths);
ss.stream() << six::sicd::Utilities::toXMLString(*data, nullptr /*pSchemaPaths*/);

six::MinidomParser xmlParser;
xmlParser.parse(ss);
Expand Down Expand Up @@ -103,8 +102,7 @@ TEST_CASE(ClassificationCanada)
data->collectionInformation->setClassificationLevel(classificationText);
TEST_ASSERT_TRUE(data->getClassification().isUnclassified());

const std::vector<std::string> schemaPaths;
const auto strXml = six::sicd::Utilities::toXMLString(*data, schemaPaths);
const auto strXml = six::sicd::Utilities::toXMLString(*data, nullptr /*pSchemaPaths*/);

const auto NON_CLASSIFI = strXml.find(U8("NON CLASSIFI"));
TEST_ASSERT(NON_CLASSIFI != std::string::npos);
Expand Down
4 changes: 2 additions & 2 deletions six/modules/c++/six.sidd/include/six/sidd/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Utilities
* \return Data representation of 'xmlStr'
*/
static mem::auto_ptr<DerivedData> parseDataFromString(
const std::u8string& xmlStr,
const std::string& xmlStr,
const std::vector<std::string>& schemaPaths,
logging::Logger& log);
static std::unique_ptr<DerivedData> parseDataFromString(
Expand All @@ -148,7 +148,7 @@ class Utilities
* \return XML string representation of
*'data'
*/
static std::u8string toXMLString(const DerivedData& data,
static std::string toXMLString(const DerivedData& data,
const std::vector<std::string>& schemaPaths,
logging::Logger* logger);
static std::u8string toXMLString(const DerivedData&,
Expand Down
35 changes: 18 additions & 17 deletions six/modules/c++/six.sidd/source/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <stdexcept>

#include <str/EncodedStringView.h>

#include "six/Utilities.h"
#include "six/sidd/DerivedXMLControl.h"
#include "six/sidd/DerivedDataBuilder.h"
Expand Down Expand Up @@ -559,10 +561,10 @@ std::unique_ptr<DerivedData> Utilities::parseDataFromFile(const std::filesystem:
return parseData(inStream, pSchemaPaths, *logger);
}

mem::auto_ptr<DerivedData> Utilities::parseDataFromString(const std::u8string& xmlStr,
mem::auto_ptr<DerivedData> Utilities::parseDataFromString(const std::string& xmlStr,
const std::vector<std::string>& schemaPaths, logging::Logger& log)
{
io::U8StringStream inStream;
io::StringStream inStream;
inStream.write(xmlStr);
return parseData(inStream, schemaPaths, log);
}
Expand All @@ -577,27 +579,26 @@ std::unique_ptr<DerivedData> Utilities::parseDataFromString(const std::u8string&
return parseData(inStream, pSchemaPaths, *log);
}

template<typename TSchemaPaths>
std::u8string Utilities_toXMLString(const DerivedData& data,
const TSchemaPaths& schemaPaths, logging::Logger* pLogger)
std::string Utilities::toXMLString(const DerivedData& data,
const std::vector<std::string>& schemaPaths_, logging::Logger* logger)
{
std::vector<std::filesystem::path> schemaPaths;
std::transform(schemaPaths_.begin(), schemaPaths_.end(), std::back_inserter(schemaPaths),
[](const std::string& s) { return s; });

const auto result = toXMLString(data, &schemaPaths, logger);
return str::EncodedStringView(result).native();
}
std::u8string Utilities::toXMLString(const DerivedData& data,
const std::vector<std::filesystem::path>* pSchemaPaths, logging::Logger* pLogger)
{
XMLControlRegistry xmlRegistry;
xmlRegistry.addCreator<DerivedXMLControl>();

logging::NullLogger nullLogger;
logging::Logger* const logger = (pLogger == nullptr) ? &nullLogger : pLogger;
logging::Logger* const pLogger_ = (pLogger == nullptr) ? &nullLogger : pLogger;

return ::six::toValidXMLString(data, schemaPaths, logger, &xmlRegistry);
}
std::u8string Utilities::toXMLString(const DerivedData& data,
const std::vector<std::string>& schemaPaths, logging::Logger* logger)
{
return Utilities_toXMLString(data, schemaPaths, logger);
}
std::u8string Utilities::toXMLString(const DerivedData& data,
const std::vector<std::filesystem::path>* pSchemaPaths, logging::Logger* logger)
{
return Utilities_toXMLString(data, pSchemaPaths, logger);
return ::six::toValidXMLString(data, pSchemaPaths, pLogger_, &xmlRegistry);
}

static void createPredefinedFilter(six::sidd::Filter& filter)
Expand Down
3 changes: 1 addition & 2 deletions six/modules/c++/six/include/six/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ namespace details
#define SIX_Enum_constructors_SWIGPYTHON_(name)
#endif
#define SIX_Enum_constructors_(name) SIX_Enum_default_ctor_assign_(name); SIX_Enum_constructors_SWIGPYTHON_(name); \
name(values v) : Enum(static_cast<int>(v)) {} name& operator=(values v) { *this = std::move(name(v)); return *this; } \
static name cast(int i) { return six::Enum::cast<name>(i); }
name(values v) : Enum(static_cast<int>(v)) {} name& operator=(values v) { *this = std::move(name(v)); return *this; }
#define SIX_Enum_BEGIN_enum enum values {
#define SIX_Enum_BEGIN_DEFINE(name) struct name final : public six::details::Enum<name> {
#define SIX_Enum_END_DEFINE(name) SIX_Enum_constructors_(name); }
Expand Down
10 changes: 10 additions & 0 deletions six/modules/c++/six/include/six/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <std/span>
#include <std/cstddef>
#include <std/filesystem>
#include <std/string>

#include <import/io.h>
#include <import/xml/lite.h>
Expand Down Expand Up @@ -276,6 +277,11 @@ mem::auto_ptr<Data> parseDataFromString(const XMLControlRegistry& xmlReg,
DataType dataType,
const std::vector<std::string>& schemaPaths,
logging::Logger& log);
std::unique_ptr<Data> parseDataFromString(const XMLControlRegistry& xmlReg,
const std::u8string& xmlStr,
DataType dataType,
const std::vector<std::filesystem::path>* pSchemaPaths,
logging::Logger* pLogger = nullptr);

/*
* Parses the XML in 'xmlStr' and converts it into a Data object. Same as
Expand All @@ -292,6 +298,10 @@ mem::auto_ptr<Data> parseDataFromString(const XMLControlRegistry& xmlReg,
const std::string& xmlStr,
const std::vector<std::string>& schemaPaths,
logging::Logger& log);
std::unique_ptr<Data> parseDataFromString(const XMLControlRegistry& xmlReg,
const std::u8string& xmlStr,
const std::vector<std::filesystem::path>* pSchemaPaths,
logging::Logger* pLogger = nullptr);

void getErrors(const ErrorStatistics* errorStats,
const types::RgAz<double>& sampleSpacing,
Expand Down
Loading

0 comments on commit cd60927

Please sign in to comment.