OpenVDB 13.2.0
Loading...
Searching...
No Matches
CodecData Struct Reference

Mutable per-operation state created by Codec::createData() and passed into every read and write call on a given codec. More...

#include <openvdb/io/Codec.h>

Public Types

using Ptr = std::unique_ptr<CodecData>

Public Member Functions

virtual ~CodecData ()=default

Public Attributes

SharedPtr< GridBase > grid
 The grid being populated on read, or being serialized on write.

Detailed Description

Mutable per-operation state created by Codec::createData() and passed into every read and write call on a given codec.

The main purpose of this class is to provide a mechanism for passing additional state between the different methods in the codec. ReadOptions is immutable and cannot carry per-operation state; the codec itself is stateless by design (to allow sharing across threads) and therefore also cannot be used for this purpose.

The base class provides the single field that every codec requires: a shared pointer to the GridBase being populated (on read) or inspected (on write). Derived codecs that need additional transient state should subclass CodecData and add those fields.

A CodecData instance is created once per grid per read or write operation by Codec::createData(), which also allocates the concrete GridBase subclass and stores it in grid.

Deriving from CodecData
struct MyCodecData : public io::CodecData {
// Additional per-operation state goes here
SomeCache intermediateBuffer;
};
Mutable per-operation state created by Codec::createData() and passed into every read and write call ...
Definition Codec.h:300

Inside Codec::createData(), the derived type is allocated and returned:

io::CodecData::Ptr createData() override {
auto data = std::make_unique<MyCodecData>();
data->grid = MyGridType::create();
return data;
}
std::unique_ptr< CodecData > Ptr
Definition Codec.h:301

In the read and write methods, downcast the reference back to the concrete type to access the extra fields:

void readBuffers(std::istream& is, int64_t size, io::CodecData& data, ...) const override {
auto& myData = static_cast<MyCodecData&>(data);
MyGridType& grid = static_cast<MyGridType&>(*myData.grid);
// Use myData.intermediateBuffer, grid, etc.
}
SharedPtr< GridBase > grid
The grid being populated on read, or being serialized on write.
Definition Codec.h:306

Member Typedef Documentation

◆ Ptr

using Ptr = std::unique_ptr<CodecData>

Constructor & Destructor Documentation

◆ ~CodecData()

virtual ~CodecData ( )
virtualdefault

Member Data Documentation

◆ grid

The grid being populated on read, or being serialized on write.