Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more CPHD tweaks #701

Merged
merged 19 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions six/modules/c++/cphd/include/cphd/CPHDWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ struct CPHDWriter final
*
* \param data A pointer to the start of the support array data block
*/
sys::Off_T getSupportBlockByteOffset(const Data::SupportArray&) const;
void writeSupportDataArray(io::SeekableOutputStream&, DataWriter&,
std::span<const std::byte>, const Data::SupportArray&);
void writeSupportDataArray(io::SeekableOutputStream&, std::span<const std::byte>, const Data::SupportArray&);
void writeSupportData(io::SeekableOutputStream&, std::span<const std::byte>);

template <typename T>
Expand Down
28 changes: 20 additions & 8 deletions six/modules/c++/cphd/source/CPHDWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,34 @@ static auto make_span(std::span<const std::byte> data, const cphd::Data::Support
const auto pData = data.data() + dataArray.arrayByteOffset;
return sys::make_span(pData, dataArray.size_bytes());
}
void CPHDWriter::writeSupportData(io::SeekableOutputStream& stream, std::span<const std::byte> data)
sys::Off_T CPHDWriter::getSupportBlockByteOffset(const Data::SupportArray& dataArray) const
{
const auto supportBlockByteOffset = mHeader.getSupportBlockByteOffset();
return supportBlockByteOffset + dataArray.arrayByteOffset;
}

void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream, DataWriter& dataWriter,
std::span<const std::byte> data, const Data::SupportArray& dataArray)
{
// Move inputstream head to offset of particular support array
stream.seek(getSupportBlockByteOffset(dataArray), io::SeekableOutputStream::START);
dataWriter(make_span(data, dataArray), dataArray.bytesPerElement);
}
void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream,
std::span<const std::byte> data, const Data::SupportArray& dataArray)
{
auto dataWriter = make_DataWriter(stream);
writeSupportDataArray(stream, *dataWriter, data, dataArray);
}
void CPHDWriter::writeSupportData(io::SeekableOutputStream& stream, std::span<const std::byte> data)
{
auto dataWriter = make_DataWriter(stream);
for (auto&& mapEntry : mMetadata.data.supportArrayMap)
{
auto&& dataArray = mapEntry.second;

// Move inputstream head to offset of particular support array
stream.seek(supportBlockByteOffset + dataArray.arrayByteOffset, io::SeekableOutputStream::START);

(*dataWriter)(make_span(data, dataArray), dataArray.bytesPerElement);
writeSupportDataArray(stream, *dataWriter, data, mapEntry.second);
}
// Move inputstream head to the end of the support block after all supports have been written
stream.seek(supportBlockByteOffset + mHeader.getSupportBlockSize(), io::SeekableOutputStream::START);
stream.seek(mHeader.getSupportBlockByteOffset() + mHeader.getSupportBlockSize(), io::SeekableOutputStream::START);
}

template <typename T>
Expand Down
Loading