template<typename SRCTYPE, typename DSTTYPE>
class maxon::StreamConversionHelper< SRCTYPE, DSTTYPE >
This class implements a helper function for sequential access when using stream conversions Usually with stream conversions you get an arbitrary number of bytes within the ConvertImpl callback. This means you cannot longer read data in a classic linear fashion since you might not get enough bytes to finish your reading.
For example something simple like
void * buf
Definition: abstract.h:289
is not possible whithout checking for the remaning bytes left. In case of insufficient number of available bytes you have to store your current variable heap and continue reading in subsequent calls of ConvertImpl.
While this might be possible for simple algorithms it can get quite complex or even imposible when trying to read more elaborate data files which are for example arranged in hierarchies with chunks or subchunks. Or think about using an external complex library for accessing a data format like Alembic or TIFF. In this case you can not change the code structure - only replacing a ReadBytes access is possible.
StreamConversionHelper frees you from dealing with stream bytes deliverd in arbitrary chunks. First you simply overlad StreamConversionHelper template by specifying your source and dest datatype (here both Char) and fill the DoIt routine with your normal code e.g. reading the file (in this example decompressing a LZ4 stream)
class Lz4StreamConversionHelper : public StreamConversionHelper<Char, Char>
{
public:
virtual Result<void>
DoIt()
{
Lz4Decompress();
}
};
virtual Result< void > DoIt()=0
In this example if you want to read 4 bytes (aka Chars) within the DoIt routine you simply write
Result< void > Read(SRCTYPE *buf, Int count)
Definition: streamconversion_helper.h:339
maxon::Char Char
Definition: ge_sys_math.h:56
#define iferr_return
Definition: resultbase.h:1521
Second you put the helper object somewhere on the stack - ideally as a static variable in your main StreamConversion class and initialize it everytime ConvertImpl is called by simply calling AppendStream - boom you are done.
class Lz4BaseImpl :
public Component<Lz4BaseImpl, StreamConversionInterface>
{
public:
Result<Int> ConvertImpl(
const Block<const Generic>& xsrc, WritableArrayInterface<Generic>& xdst,
Int dstLimitHint,
Bool inputFinished,
Bool& outputFinished)
{
const Block<const Char>&
src =
reinterpret_cast<const Block<const Char>&
> (xsrc);
WritableArrayInterface<Char>& dst = reinterpret_cast<WritableArrayInterface<Char>&>(xdst);
if (inputFinished)
outputFinished = true;
return helper.GetCurrentPosition();
}
protected:
Lz4StreamConversionHelper helper;
};
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::Int Int
Definition: ge_sys_math.h:64
const ARG & src
Definition: apibase.h:2713
ComponentWithBase< C, ComponentRoot, INTERFACES... > Component
Definition: objectbase.h:2784
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2199
#define iferr_scope
Definition: resultbase.h:1386