Skip to content

Commit 53af683

Browse files
committed
Make Codec read/write methods const
Signed-off-by: Dan Bailey <danbailey@ilm.com>
1 parent fc294a0 commit 53af683

7 files changed

Lines changed: 24 additions & 22 deletions

File tree

openvdb/openvdb/codecs/BoolCodec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct BoolCodec final: public TopologyCodec<GridT>
110110

111111
static inline std::string name() { return GridT::gridType(); }
112112

113-
void readBuffers(std::istream& is, Index64 /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics&) final
113+
void readBuffers(std::istream& is, int64_t /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics&) const final
114114
{
115115
GridT& grid = static_cast<GridT&>(*data.grid);
116116

@@ -134,7 +134,7 @@ struct BoolCodec final: public TopologyCodec<GridT>
134134
tools::visitNodesDepthFirst(grid.tree(), readBuffersOp, /*idx=*/0, /*topDown=*/false);
135135
}
136136

137-
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) final
137+
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) const final
138138
{
139139
const GridT& grid = static_cast<const GridT&>(gridBase);
140140

openvdb/openvdb/codecs/PointDataCodec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ struct PointDataCodec final: public TopologyCodec<GridT>
311311

312312
static inline std::string name() { return GridT::gridType(); }
313313

314-
void readBuffers(std::istream& is, Index64 /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics&) final
314+
void readBuffers(std::istream& is, int64_t /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics&) const final
315315
{
316316
OPENVDB_ASSERT(dynamic_cast<GridT*>(data.grid.get()));
317317

@@ -422,7 +422,7 @@ struct PointDataCodec final: public TopologyCodec<GridT>
422422
}
423423
}
424424

425-
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) final
425+
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) const final
426426
{
427427
const GridT& grid = static_cast<const GridT&>(gridBase);
428428
bool saveFloatAsHalf = grid.saveFloatAsHalf();

openvdb/openvdb/codecs/PointIndexCodec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct PointIndexCodec final: public TopologyCodec<GridT>
116116

117117
static inline std::string name() { return GridT::gridType(); }
118118

119-
void readBuffers(std::istream& is, Index64 /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics& diagnostics) final
119+
void readBuffers(std::istream& is, int64_t /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics& diagnostics) const final
120120
{
121121
OPENVDB_ASSERT(dynamic_cast<GridT*>(data.grid.get()));
122122

@@ -143,7 +143,7 @@ struct PointIndexCodec final: public TopologyCodec<GridT>
143143
tools::visitNodesDepthFirst(grid.tree(), readBuffersOp, /*idx=*/0, /*topDown=*/false);
144144
}
145145

146-
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) final
146+
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) const final
147147
{
148148
const GridT& grid = static_cast<const GridT&>(gridBase);
149149

openvdb/openvdb/codecs/ScalarCodec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ struct ScalarCodec final: public TopologyCodec<GridT, StorageGridT, Mode>
159159
}
160160
}
161161

162-
void readBuffers(std::istream& is, Index64 /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics&) final
162+
void readBuffers(std::istream& is, int64_t /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics&) const final
163163
{
164164
using StorageValueT = typename StorageGridT::TreeType::ValueType;
165165
GridT& grid = static_cast<GridT&>(*data.grid);
166166
auto& topoData = static_cast<TopologyCodecData<StorageValueT>&>(data);
167167
internal::scalarCodecReadBuffers<GridT, StorageGridT>(grid, is, options, &topoData.storageBackground);
168168
}
169169

170-
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) final
170+
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) const final
171171
{
172172
// Note: the write body must live inside the negated if constexpr branch
173173
// so it is not instantiated for read-only codecs. A bare

openvdb/openvdb/codecs/TopologyCodec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ struct TopologyCodec : public io::Codec
356356
}
357357

358358
void readTopology(std::istream& is, io::CodecData& data, const io::ReadOptions& options,
359-
io::ReadDiagnostics& diagnostics) final
359+
io::ReadDiagnostics& diagnostics) const final
360360
{
361361
// Warn when a conversion readMode was requested but this codec is a
362362
// non-conversion instance (GridT == StorageGridT), meaning no conversion
@@ -379,7 +379,7 @@ struct TopologyCodec : public io::Codec
379379
internal::topologyCodecReadTopology<GridT, StorageGridT>(*data.grid, is, options, diagnostics, topoData);
380380
}
381381

382-
void writeTopology(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) final
382+
void writeTopology(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) const final
383383
{
384384
// Disable implementation when read only. The body must live inside the
385385
// negated if constexpr branch so it is not instantiated for read-only

openvdb/openvdb/codecs/ValueMaskCodec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct ValueMaskCodec final: public TopologyCodec<GridT>
102102

103103
static inline std::string name() { return GridT::gridType(); }
104104

105-
void readBuffers(std::istream& is, Index64 /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics&) final
105+
void readBuffers(std::istream& is, int64_t /*size*/, io::CodecData& data, const io::ReadOptions& options, io::ReadDiagnostics&) const final
106106
{
107107
GridT& grid = static_cast<GridT&>(*data.grid);
108108

@@ -126,7 +126,7 @@ struct ValueMaskCodec final: public TopologyCodec<GridT>
126126
tools::visitNodesDepthFirst(grid.tree(), readBuffersOp, /*idx=*/0, /*topDown=*/false);
127127
}
128128

129-
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) final
129+
void writeBuffers(std::ostream& os, const GridBase& gridBase, const io::WriteOptions&) const final
130130
{
131131
const GridT& grid = static_cast<const GridT&>(gridBase);
132132

openvdb/openvdb/io/Codec.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ struct OPENVDB_API ReadDiagnostics {
284284
/// In the read and write methods, downcast the reference back to the concrete
285285
/// type to access the extra fields:
286286
/// @code
287-
/// void readBuffers(std::istream& is, io::CodecData& data, ...) override {
287+
/// void readBuffers(std::istream& is, int64_t size, io::CodecData& data, ...) const override {
288288
/// auto& myData = static_cast<MyCodecData&>(data);
289289
/// MyGridType& grid = static_cast<MyGridType&>(*myData.grid);
290290
/// // Use myData.intermediateBuffer, grid, etc.
@@ -350,15 +350,15 @@ struct OPENVDB_API CodecData
350350
/// @code
351351
/// void readTopology(std::istream& is, io::CodecData& data,
352352
/// const io::ReadOptions& options,
353-
/// io::ReadDiagnostics& diagnostics) override
353+
/// io::ReadDiagnostics& diagnostics) const override
354354
/// {
355355
/// MyGridType& grid = static_cast<MyGridType&>(*data.grid);
356356
/// // Deserialize the tree structure into grid...
357357
/// }
358358
///
359-
/// void readBuffers(std::istream& is, io::CodecData& data,
359+
/// void readBuffers(std::istream& is, int64_t size, CodecData& data,
360360
/// const io::ReadOptions& options,
361-
/// io::ReadDiagnostics& diagnostics) override
361+
/// io::ReadDiagnostics& diagnostics) const override
362362
/// {
363363
/// if (options.readMode == io::ReadMode::TopologyOnly) return;
364364
/// MyGridType& grid = static_cast<MyGridType&>(*data.grid);
@@ -397,7 +397,7 @@ struct OPENVDB_API Codec
397397
/// @brief Deserialize the grid topology (tree structure and active-voxel
398398
/// mask) from @a is into the grid held by @a data.
399399
virtual void readTopology(std::istream& /*is*/, CodecData& /*data*/,
400-
const ReadOptions& /*options*/, ReadDiagnostics& /*diagnostics*/) { }
400+
const ReadOptions& /*options*/, ReadDiagnostics& /*diagnostics*/) const { }
401401

402402
/// @brief Deserialize all voxel-value buffers from @a is into the grid
403403
/// held by @a data.
@@ -410,9 +410,11 @@ struct OPENVDB_API Codec
410410
/// restrict the loaded data to the region that intersects it; if the codec
411411
/// cannot honour clipping natively, fall back to a post-process and record
412412
/// a warning via @a diagnostics. The @c size argument is the number of bytes
413-
/// occupied by the entire readBuffers data section.
414-
virtual void readBuffers(std::istream& /*is*/, Index64 /*size*/, CodecData& /*data*/,
415-
const ReadOptions& /*options*/, ReadDiagnostics& /*diagnostics*/) { }
413+
/// occupied by the readBuffers data section, measured from the stream
414+
/// position at which this method is called, or -1 when the size is not known
415+
/// (a non-seekable stream, or a stream without grid offsets).
416+
virtual void readBuffers(std::istream& /*is*/, int64_t /*size*/, CodecData& /*data*/,
417+
const ReadOptions& /*options*/, ReadDiagnostics& /*diagnostics*/) const { }
416418

417419
/// @brief Serialize the grid topology (tree structure and active-voxel
418420
/// mask) from @a grid to @a os.
@@ -421,14 +423,14 @@ struct OPENVDB_API Codec
421423
/// topology as a distinct section that precedes the value buffers in the
422424
/// stream.
423425
virtual void writeTopology(std::ostream& /*os*/, const GridBase& /*grid*/,
424-
const WriteOptions& /*options*/) { }
426+
const WriteOptions& /*options*/) const { }
425427

426428
/// @brief Serialize all voxel-value buffers from @a grid to @a os.
427429
///
428430
/// The default implementation is a no-op. Override to write the leaf-node
429431
/// value buffers that follow the topology section.
430432
virtual void writeBuffers(std::ostream& /*os*/, const GridBase& /*grid*/,
431-
const WriteOptions& /*options*/) { }
433+
const WriteOptions& /*options*/) const { }
432434
}; // struct Codec
433435

434436
/// @brief A thread-safe, process-global registry that maps codec names to

0 commit comments

Comments
 (0)