Skip to content

Commit

Permalink
common XMLControlRegistry in six::DataParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Jun 29, 2023
1 parent 9fd661a commit e6b12c7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
1 change: 0 additions & 1 deletion six/modules/c++/six.sicd/include/six/sicd/DataParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace sicd
class DataParser final
{
six::DataParser mDataParser;
XMLControlRegistry mXmlRegistry;

public:

Expand Down
7 changes: 3 additions & 4 deletions six/modules/c++/six.sicd/source/DataParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ namespace fs = std::filesystem;
six::sicd::DataParser::DataParser(const std::vector<std::filesystem::path>* pSchemaPaths, logging::Logger* pLog)
: mDataParser(pSchemaPaths, pLog)
{
mXmlRegistry.addCreator<ComplexXMLControl>();
mDataParser.addCreator<ComplexXMLControl>();
}

std::unique_ptr<six::sicd::ComplexData> six::sicd::DataParser::DataParser::fromXML(::io::InputStream& xmlStream) const
{
auto pData = mDataParser.fromXML(xmlStream, mXmlRegistry, DataType::NOT_SET);
return std::unique_ptr<ComplexData>(static_cast<ComplexData*>(pData.release()));
return mDataParser.fromXML<ComplexData>(xmlStream);
}

std::unique_ptr<six::sicd::ComplexData> six::sicd::DataParser::DataParser::fromXML(const std::filesystem::path& pathname) const
Expand All @@ -62,7 +61,7 @@ std::unique_ptr<six::sicd::ComplexData> six::sicd::DataParser::DataParser::fromX

std::u8string six::sicd::DataParser::DataParser::toXML(const six::sicd::ComplexData& data) const
{
return mDataParser.toXML(data, mXmlRegistry);
return mDataParser.toXML(data);
}

void six::sicd::DataParser::DataParser::preserveCharacterData(bool preserve)
Expand Down
1 change: 0 additions & 1 deletion six/modules/c++/six.sidd/include/six/sidd/DataParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class DataParser final
{
std::vector<std::filesystem::path> mAdjustedSchemaPaths; // used to initialized six::DataParser
six::DataParser mDataParser;
XMLControlRegistry mXmlRegistry;

public:

Expand Down
7 changes: 3 additions & 4 deletions six/modules/c++/six.sidd/source/DataParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ static auto adjustSchemaPaths(const std::vector<std::filesystem::path>* pSchemaP
six::sidd::DataParser::DataParser(const std::vector<std::filesystem::path>* pSchemaPaths, logging::Logger* pLog)
: mDataParser(adjustSchemaPaths(pSchemaPaths, mAdjustedSchemaPaths), pLog)
{
mXmlRegistry.addCreator<DerivedXMLControl>();
mDataParser.addCreator<DerivedXMLControl>();
}

std::unique_ptr<six::sidd::DerivedData> six::sidd::DataParser::DataParser::fromXML(::io::InputStream& xmlStream) const
{
auto pData = mDataParser.fromXML(xmlStream, mXmlRegistry, DataType::NOT_SET);
return std::unique_ptr<DerivedData>(static_cast<DerivedData*>(pData.release()));
return mDataParser.fromXML<DerivedData>(xmlStream);
}

std::unique_ptr<six::sidd::DerivedData> six::sidd::DataParser::DataParser::fromXML(const std::filesystem::path& pathname) const
Expand All @@ -94,7 +93,7 @@ std::unique_ptr<six::sidd::DerivedData> six::sidd::DataParser::DataParser::fromX

std::u8string six::sidd::DataParser::DataParser::toXML(const six::sidd::DerivedData& data) const
{
return mDataParser.toXML(data, mXmlRegistry);
return mDataParser.toXML(data);
}

void six::sidd::DataParser::DataParser::preserveCharacterData(bool preserve)
Expand Down
14 changes: 14 additions & 0 deletions six/modules/c++/six/include/six/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class DataParser final
const std::vector<std::filesystem::path>* mpSchemaPaths = nullptr;
logging::NullLogger mNullLogger;
logging::Logger& mLog;
XMLControlRegistry mXmlRegistry;

// The default is `true` because:
// * many (most?) other parts of SIX unconditionally set `preserveCharacterData(true)`.
Expand Down Expand Up @@ -353,13 +354,25 @@ class DataParser final
*/
void preserveCharacterData(bool preserve);

template<typename TXMLControlCreator>
void addCreator()
{
mXmlRegistry.addCreator<TXMLControlCreator>();
}

/* Parses the XML in 'xmlStream'.
*
* \param xmlStream Input stream containing XML
*
* \return Data representation of 'xmlStr'
*/
std::unique_ptr<Data> fromXML(::io::InputStream& xmlStream, const XMLControlRegistry&, DataType) const;
template<typename TData>
std::unique_ptr<TData> fromXML(::io::InputStream& xmlStream) const
{
auto pData = fromXML(xmlStream, mXmlRegistry, DataType::NOT_SET);
return std::unique_ptr<TData>(static_cast<TData*>(pData.release()));
}

/*
* Parses the XML in 'pathname'.
Expand All @@ -383,6 +396,7 @@ class DataParser final
* Additionally performs schema validation --
*/
std::u8string toXML(const Data&, const XMLControlRegistry&) const;
std::u8string toXML(const Data&) const;
};

namespace testing
Expand Down
4 changes: 4 additions & 0 deletions six/modules/c++/six/source/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ std::u8string six::DataParser::DataParser::toXML(const Data& data, const XMLCon
{
return ::six::toValidXMLString(data, mpSchemaPaths, &mLog, &xmlReg);
}
std::u8string six::DataParser::DataParser::toXML(const Data& data) const
{
return toXML(data, mXmlRegistry);
}

void six::DataParser::DataParser::preserveCharacterData(bool preserve)
{
Expand Down

0 comments on commit e6b12c7

Please sign in to comment.