Skip to content

Commit

Permalink
Merge branch 'main' into develop/FmtX-to-str-Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Dec 19, 2023
2 parents f816590 + d76cbe7 commit a4c7a30
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 178 deletions.
3 changes: 1 addition & 2 deletions externals/coda-oss/UnitTest/UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down Expand Up @@ -97,6 +95,7 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
14 changes: 13 additions & 1 deletion externals/coda-oss/modules/c++/sys/include/sys/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
#include <string>
#include <deque>
#include <utility>
#include <vector>

#include "config/Exports.h"

#include <import/str.h>
#include "coda_oss/span.h"

#include "sys/OS.h"
#include "sys/filesystem.h"
#include "sys/Span.h"


/*!
Expand Down Expand Up @@ -295,6 +297,16 @@ class CODA_OSS_API Path

std::ostream& operator<<(std::ostream& os, const sys::Path& path);
std::istream& operator>>(std::istream& os, sys::Path& path);

// Convert between collections of paths as strings and sys::filesystem::path
CODA_OSS_API std::vector<std::string> convertPaths(coda_oss::span<const filesystem::path>);
CODA_OSS_API std::vector<filesystem::path> convertPaths(coda_oss::span<const std::string>);
template<typename T>
inline auto convertPaths(const std::vector<T>& paths)
{
return convertPaths(make_span(paths));
}

}

#endif // CODA_OSS_sys_Path_h_INCLUDED_
19 changes: 2 additions & 17 deletions externals/coda-oss/modules/c++/sys/source/AbstractOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,14 @@ AbstractOS::search(const std::vector<std::string>& searchPaths,
return elementsFound;
}

inline auto convert(const std::vector<fs::path>& paths)
{
std::vector<std::string> retval;
std::transform(paths.begin(), paths.end(), std::back_inserter(retval),
[](const fs::path& p) { return p.string(); });
return retval;
}
inline auto convert(const std::vector<std::string>& paths)
{
std::vector<fs::path> retval;
std::transform(paths.begin(), paths.end(), std::back_inserter(retval),
[](const auto& p) { return p; });
return retval;
}

std::vector<coda_oss::filesystem::path> AbstractOS::search(
const std::vector<coda_oss::filesystem::path>& searchPaths,
const std::string& fragment,
const std::string& extension,
bool recursive) const
{
const auto results = search(convert(searchPaths), fragment, extension, recursive);
return convert(results);
const auto results = search(convertPaths(searchPaths), fragment, extension, recursive);
return convertPaths(results);
}

void AbstractOS::remove(const std::string& path) const
Expand Down
17 changes: 17 additions & 0 deletions externals/coda-oss/modules/c++/sys/source/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "sys/Path.h"

#include <algorithm>
#include <iterator>

#include <sys/filesystem.h>
namespace fs = coda_oss::filesystem;
Expand Down Expand Up @@ -849,4 +850,20 @@ std::string Path::expandEnvironmentVariables(const std::string& path, fs::file_t
return expandEnvironmentVariables_(path, unused_checkIfExists, &type);
}

template<typename TReturn, typename TSpan, typename TFunc>
inline auto convertPaths_(coda_oss::span<const TSpan> paths, TFunc fun)
{
std::vector<TReturn> retval;
std::transform(paths.begin(), paths.end(), std::back_inserter(retval), fun);
return retval;
}
std::vector<std::string> convertPaths(coda_oss::span<const fs::path> paths)
{
return convertPaths_<std::string>(paths, [](const auto& p) { return p.string(); });
}
std::vector<fs::path> convertPaths(coda_oss::span<const std::string> paths)
{
return convertPaths_<fs::path>(paths, [](const auto& p) { return p; });
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <string>
#include <mutex>
#include <type_traits>
#include <memory>

#include "config/compiler_extensions.h"
#include "config/Exports.h"
Expand Down Expand Up @@ -409,17 +410,20 @@ struct XercesErrorHandler final : public XercesErrorHandlerInterface_T
*/
struct CODA_OSS_API XercesContext final
{
//! Constructor
XercesContext();

//! Destructor
~XercesContext();

XercesContext(const XercesContext&) = delete;
XercesContext& operator=(const XercesContext&) = delete;
XercesContext(XercesContext&&) = delete;
XercesContext& operator=(XercesContext&&) = delete;

void destroy();

private:
static std::mutex mMutex;
bool mIsDestroyed;
struct Impl;
static std::shared_ptr<Impl> getInstance();
std::shared_ptr<Impl> mpImpl;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ struct ValidationErrorHandler final : public xercesc::DOMErrorHandler
*
* This class is the Xercesc schema validator
*/
class CODA_OSS_API ValidatorXerces : public ValidatorInterface
struct CODA_OSS_API ValidatorXerces : public ValidatorInterface
{
XercesContext mCtxt; //! this must be the first member listed

public:

/*!
* Constructor
* \param schemaPaths Vector of both paths and singular schemas
Expand All @@ -104,10 +100,10 @@ class CODA_OSS_API ValidatorXerces : public ValidatorInterface
* input
*/
ValidatorXerces(const std::vector<std::string>& schemaPaths,
logging::Logger* log,
logging::Logger* log = nullptr,
bool recursive = true);
ValidatorXerces(const std::vector<coda_oss::filesystem::path>&, // fs::path -> mLegacyStringConversion = false
logging::Logger* log,
ValidatorXerces(const std::vector<coda_oss::filesystem::path>&,
logging::Logger* log = nullptr,
bool recursive = true);

ValidatorXerces(const ValidatorXerces&) = delete;
Expand All @@ -133,6 +129,8 @@ class CODA_OSS_API ValidatorXerces : public ValidatorInterface
static std::vector<coda_oss::filesystem::path> loadSchemas(const std::vector<coda_oss::filesystem::path>& schemaPaths, bool recursive=true);

private:
XercesContext mCtxt;

bool validate_(const coda_oss::u8string& xml,
const std::string& xmlID,
std::vector<ValidationInfo>& errors) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace lite
*/
class CODA_OSS_API XMLReaderXerces final : public XMLReaderInterface
{
XercesContext mCtxt; //! this must be the first member listed
XercesContext mCtxt;
std::unique_ptr<SAX2XMLReader> mNative;
std::unique_ptr<XercesContentHandler> mDriverContentHandler;
std::unique_ptr<XercesErrorHandler> mErrorHandler;
Expand Down
39 changes: 33 additions & 6 deletions externals/coda-oss/modules/c++/xml.lite/source/UtilitiesXerces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ namespace xml
{
namespace lite
{
std::mutex XercesContext::mMutex;

XercesLocalString::XercesLocalString(XMLCh* xmlStr) :
mLocal(xmlStr)
{
Expand Down Expand Up @@ -186,8 +184,16 @@ fatalError(const SAXParseException &exception)
throw except::Error(Ctxt(xex.getMessage()));
}

XercesContext::XercesContext() :
mIsDestroyed(false)
/*!
* \class XercesContext::Impl
* \brief This class safely creates and destroys Xerces
*/
struct XercesContext::Impl final
{
static std::mutex mMutex;
bool mIsDestroyed = false;

Impl()
{
//! XMLPlatformUtils::Initialize is not thread safe!
try
Expand All @@ -203,7 +209,7 @@ XercesContext::XercesContext() :
}
}

XercesContext::~XercesContext()
~Impl()
{
try
{
Expand All @@ -214,7 +220,7 @@ XercesContext::~XercesContext()
}
}

void XercesContext::destroy()
void destroy()
{
// wrapping it here saves the mutex lock
if (!mIsDestroyed)
Expand All @@ -235,7 +241,28 @@ void XercesContext::destroy()
}
}
}
};
std::mutex XercesContext::Impl::mMutex;

std::shared_ptr<XercesContext::Impl> XercesContext::getInstance()
{
// The one and only instance; call XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate() just once.
static auto impl = std::make_shared<XercesContext::Impl>();
return impl; // increment reference count
}
XercesContext::XercesContext() : mpImpl(getInstance()) // increment reference count
{
}
XercesContext::~XercesContext()
{
destroy();
}
void XercesContext::destroy()
{
mpImpl.reset();
}

} // lite
} // xml

#endif
29 changes: 9 additions & 20 deletions externals/coda-oss/modules/c++/xml.lite/source/ValidatorXerces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CODA_OSS_disable_warning(-Wshadow)
CODA_OSS_disable_warning_pop

#include <sys/OS.h>
#include <sys/Path.h>
#include <io/StringStream.h>
#include <mem/ScopedArray.h>

Expand Down Expand Up @@ -89,26 +90,11 @@ bool ValidationErrorHandler::handleError(
return true;
}

inline std::vector<std::string> convert(const std::vector<fs::path>& schemaPaths)
{
std::vector<std::string> retval;
std::transform(schemaPaths.begin(), schemaPaths.end(), std::back_inserter(retval),
[](const fs::path& p) { return p.string(); });
return retval;
}
inline auto convert(const std::vector<std::string>& paths)
{
std::vector<fs::path> retval;
std::transform(paths.begin(), paths.end(), std::back_inserter(retval),
[](const auto& p) { return p; });
return retval;
}

ValidatorXerces::ValidatorXerces(
const std::vector<fs::path>& schemaPaths,
logging::Logger* log,
bool recursive) :
ValidatorXerces(convert(schemaPaths), log, recursive)
ValidatorXerces(sys::convertPaths(schemaPaths), log, recursive)
{
}
ValidatorXerces::ValidatorXerces(
Expand Down Expand Up @@ -169,7 +155,7 @@ ValidatorXerces::ValidatorXerces(

// load our schemas --
// search each directory for schemas
const auto schemas = loadSchemas(convert(schemaPaths), recursive);
const auto schemas = loadSchemas(sys::convertPaths(schemaPaths), recursive);

// add the schema to the validator
// add the schema to the validator
Expand All @@ -179,9 +165,12 @@ ValidatorXerces::ValidatorXerces(
xercesc::Grammar::SchemaGrammarType,
true))
{
std::ostringstream oss;
oss << "Error: Failure to load schema " << schema;
log->warn(Ctxt(oss));
if (log != nullptr)
{
std::ostringstream oss;
oss << "Error: Failure to load schema " << schema;
log->warn(Ctxt(oss));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ static void testValidateXmlFile_(const std::string& testName, const std::string&
static const auto xsd = find_unittest_file("doc.xsd");
const auto path = find_unittest_file(xmlFile);

const std::vector<std::filesystem::path> schemaPaths{xsd.parent_path()}; // fs::path -> new string-conversion code
const xml::lite::Validator validator(schemaPaths, nullptr /*log*/);
const std::vector<std::filesystem::path> schemaPaths{xsd.parent_path()};
const xml::lite::Validator validator(schemaPaths);

io::FileInputStream fis(path);
std::vector<xml::lite::ValidationInfo> errors;
Expand Down
6 changes: 2 additions & 4 deletions six/modules/c++/cphd/source/CPHDReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <mem/ScopedArray.h>
#include <xml/lite/MinidomParser.h>
#include <gsl/gsl.h>
#include <sys/Path.h>

#include <six/XmlLite.h>
#include <cphd/CPHDXMLControl.h>
Expand Down Expand Up @@ -60,10 +61,7 @@ static cphd::Metadata fromXML(io::SeekableInputStream& inStream,
logger = std::make_shared<logging::NullLogger>();
}

std::vector<std::filesystem::path> schemaPaths;
std::transform(schemaPaths_.begin(), schemaPaths_.end(), std::back_inserter(schemaPaths),
[](const std::string& s) { return s; });

const auto schemaPaths = sys::convertPaths(schemaPaths_);
return cphd::CPHDXMLControl(logger.get()).fromXML(xmlParser.getDocument(), schemaPaths);
}
cphd::CPHDReader::CPHDReader(std::shared_ptr<io::SeekableInputStream> inStream,
Expand Down
10 changes: 2 additions & 8 deletions six/modules/c++/cphd/source/CPHDWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <algorithm>

#include <except/Exception.h>
#include <sys/Path.h>

#include <cphd/ByteSwap.h>
#include <cphd/CPHDXMLControl.h>
Expand Down Expand Up @@ -62,13 +63,6 @@ CPHDWriter::CPHDWriter(const Metadata& metadata,
{
}

static auto transform(const std::vector<std::string>& schemaPaths)
{
std::vector<std::filesystem::path> retval;
std::transform(schemaPaths.begin(), schemaPaths.end(), std::back_inserter(retval),
[](const std::string& s) { return s; });
return retval;
}
CPHDWriter::CPHDWriter(const Metadata& metadata,
std::shared_ptr<io::SeekableOutputStream> outStream,
const std::vector<std::string>& schemaPaths,
Expand All @@ -78,7 +72,7 @@ CPHDWriter::CPHDWriter(const Metadata& metadata,
mElementSize(metadata.data.getNumBytesPerSample()),
mScratchSpaceSize(scratchSpaceSize),
mNumThreads(numThreads),
mSchemaPaths(transform(schemaPaths)),
mSchemaPaths(sys::convertPaths(schemaPaths)),
mpSchemaPaths(&mSchemaPaths),
mSharedStream(outStream),
mStream(*mSharedStream),
Expand Down
Loading

0 comments on commit a4c7a30

Please sign in to comment.