Skip to content

Commit

Permalink
use std::vector<std::filesystem::path>*
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Sep 27, 2023
1 parent d4c7f4a commit cea095e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
17 changes: 16 additions & 1 deletion six/modules/c++/cphd/include/cphd/CPHDWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <std/span>
#include <std/cstddef>
#include <functional>
#include <memory>
#include <std/filesystem>

#include <types/RowCol.h>
#include <io/FileOutputStream.h>
Expand Down Expand Up @@ -75,6 +77,12 @@ struct CPHDWriter final
* that may be used if byte swapping is necessary.
* Default is 4 MB
*/
CPHDWriter(
const Metadata& metadata,
io::SeekableOutputStream& stream,
const std::vector<std::filesystem::path>* pSchemaPaths = nullptr,
size_t numThreads = 0,
size_t scratchSpaceSize = 4 * 1024 * 1024);
CPHDWriter(
const Metadata& metadata,
std::shared_ptr<io::SeekableOutputStream> stream,
Expand Down Expand Up @@ -107,6 +115,12 @@ struct CPHDWriter final
const std::vector<std::string>& schemaPaths = std::vector<std::string>(),
size_t numThreads = 0,
size_t scratchSpaceSize = 4 * 1024 * 1024);
CPHDWriter(
const Metadata& metadata,
const std::filesystem::path& pathname,
const std::vector<std::filesystem::path>* pSchemaPaths = nullptr,
size_t numThreads = 0,
size_t scratchSpaceSize = 4 * 1024 * 1024);

CPHDWriter() = delete;
CPHDWriter(const CPHDWriter&) = delete;
Expand Down Expand Up @@ -314,7 +328,8 @@ struct CPHDWriter final
//! number of threads for parallelism
const size_t mNumThreads;
//! schemas for XML validation
const std::vector<std::string> mSchemaPaths;
const std::vector<std::filesystem::path> mSchemaPaths;
const std::vector<std::filesystem::path>* mpSchemaPaths = nullptr;
//! Output stream contains CPHD file
std::shared_ptr<io::SeekableOutputStream> mSharedStream;
io::SeekableOutputStream& mStream;
Expand Down
44 changes: 41 additions & 3 deletions six/modules/c++/cphd/source/CPHDWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <thread>
#include <std/bit>
#include <std/memory>
#include <algorithm>

#include <except/Exception.h>

Expand All @@ -46,6 +46,28 @@ static Version getVersion(const Metadata& metadata)
return retval;
}

CPHDWriter::CPHDWriter(const Metadata& metadata,
io::SeekableOutputStream& outStream,
const std::vector<std::filesystem::path>* pSchemaPaths,
size_t numThreads,
size_t scratchSpaceSize) :
mMetadata(metadata),
mElementSize(metadata.data.getNumBytesPerSample()),
mScratchSpaceSize(scratchSpaceSize),
mNumThreads(numThreads),
mpSchemaPaths(pSchemaPaths),
mStream(outStream),
mHeader(getVersion(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 @@ -55,7 +77,8 @@ CPHDWriter::CPHDWriter(const Metadata& metadata,
mElementSize(metadata.data.getNumBytesPerSample()),
mScratchSpaceSize(scratchSpaceSize),
mNumThreads(numThreads),
mSchemaPaths(schemaPaths),
mSchemaPaths(transform(schemaPaths)),
mpSchemaPaths(&mSchemaPaths),
mSharedStream(outStream),
mStream(*mSharedStream),
mHeader(getVersion(metadata))
Expand All @@ -74,6 +97,21 @@ CPHDWriter::CPHDWriter(const Metadata& metadata,
scratchSpaceSize)
{
}
CPHDWriter::CPHDWriter(const Metadata& metadata,
const std::filesystem::path& pathname,
const std::vector<std::filesystem::path>* pSchemaPaths,
size_t numThreads,
size_t scratchSpaceSize) :
mMetadata(metadata),
mElementSize(metadata.data.getNumBytesPerSample()),
mScratchSpaceSize(scratchSpaceSize),
mNumThreads(numThreads),
mpSchemaPaths(pSchemaPaths),
mSharedStream(std::make_shared<io::FileOutputStream>(pathname)), // Initialize output stream
mStream(*mSharedStream),
mHeader(getVersion(metadata))
{
}

void CPHDWriter::writeMetadata(io::OutputStream& stream,
size_t supportSize, size_t pvpSize, size_t cphdSize)
Expand All @@ -92,7 +130,7 @@ void CPHDWriter::writeMetadata(io::OutputStream& stream,
throw except::Exception(Ctxt("Classification level and Release informaion must be specified"));
}

const auto xmlMetadata(CPHDXMLControl().toXMLString(mMetadata, mSchemaPaths));
const auto xmlMetadata(CPHDXMLControl().toXMLString(mMetadata, mpSchemaPaths));

// set header size, final step before write
mHeader.set(xmlMetadata.size(), supportSize, pvpSize, cphdSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void writeCompressedCPHD(const std::string& outPathname, size_t numThreads,
}
}

cphd::CPHDWriter writer(metadata, outPathname, std::vector<std::string>(), numThreads);
cphd::CPHDWriter writer(metadata, outPathname, nullptr /*pSchemaPaths*/, numThreads);

writer.writeMetadata(pvpBlock);

Expand Down
2 changes: 1 addition & 1 deletion six/modules/c++/cphd/unittests/test_pvp_block_round.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void writeCPHD(const std::string& outPathname,

cphd::CPHDWriter writer(metadata,
outPathname,
std::vector<std::string>(),
nullptr /*pSchemaPaths*/,
numThreads);
writer.writeMetadata(pvpBlock);
writer.writePVPData(pvpBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void writeSupportData(const std::string& outPathname, size_t numThreads,
cphd::setVectorParameters(ii, jj, pvpBlock);
}
}
cphd::CPHDWriter writer(metadata, outPathname, std::vector<std::string>(), numThreads);
cphd::CPHDWriter writer(metadata, outPathname, nullptr /*pSchemaPaths*/, numThreads);
writer.writeMetadata(pvpBlock);
writer.writeSupportData(writeData);
writer.writePVPData(pvpBlock);
Expand Down

0 comments on commit cea095e

Please sign in to comment.