diff --git a/six/modules/c++/cphd/include/cphd/CPHDWriter.h b/six/modules/c++/cphd/include/cphd/CPHDWriter.h index 49aef9d77..6ed8cbe43 100644 --- a/six/modules/c++/cphd/include/cphd/CPHDWriter.h +++ b/six/modules/c++/cphd/include/cphd/CPHDWriter.h @@ -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 Data::SupportArray&); + void writeSupportDataArray(io::SeekableOutputStream&, std::span, const Data::SupportArray&); void writeSupportData(io::SeekableOutputStream&, std::span); template diff --git a/six/modules/c++/cphd/source/CPHDWriter.cpp b/six/modules/c++/cphd/source/CPHDWriter.cpp index 403e74750..3f8469fcd 100644 --- a/six/modules/c++/cphd/source/CPHDWriter.cpp +++ b/six/modules/c++/cphd/source/CPHDWriter.cpp @@ -162,22 +162,34 @@ static auto make_span(std::span 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 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 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 data, const Data::SupportArray& dataArray) +{ + auto dataWriter = make_DataWriter(stream); + writeSupportDataArray(stream, *dataWriter, data, dataArray); +} +void CPHDWriter::writeSupportData(io::SeekableOutputStream& stream, std::span 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