Thea
|
Codec for reading/writing matrices to/from comma-separated values (CSV) text files. More...
#include <MatrixIO.hpp>
Public Types | |
typedef std::array< int8,(size_t) MAGIC_LENGTH > | MagicString |
The type of the codec's magic string (an array of MAGIC_LENGTH bytes). More... | |
Public Member Functions | |
virtual MagicString const & | getMagic () const |
Get the magic string for the codec, if it has one (else a string of all zeros). More... | |
virtual char const * | getName () const =0 |
Get the name of the object. More... | |
virtual bool | matches (BinaryInputStream &input, Codec::BlockHeader const *block_header) const =0 |
Given an input stream and an optional (already extracted) block header, check if the codec is suitable for decoding the stream. More... | |
operator intx () const | |
Implicitly convert to an integer value for use in switch statements etc. More... | |
bool | operator== (Codec const &other) const |
Check if two codecs are equal. More... | |
virtual void | readMatrix (MatrixT &m, BinaryInputStream &input, BlockHeader const *block_header) const =0 |
Read the matrix from an input stream. More... | |
int8 | setName (char const *s) |
Set the name of the object. More... | |
virtual void | writeMatrix (MatrixT const &m, BinaryOutputStream &output, bool write_block_header) const =0 |
Write the matrix to an output stream, optionally preceded by a block header. More... | |
Static Public Member Functions | |
static MagicString | toMagic (std::string const &s) |
Convenience function to convert a string literal to a magic string. More... | |
Static Public Attributes | |
static intx const | MAGIC_LENGTH = 8 |
The standard length (in bytes) of the codec's magic string as used in BlockHeader. More... | |
Codec for reading/writing matrices to/from comma-separated values (CSV) text files.
Instead of the comma, a different separating character may be specified (typically tab or space).
For dense matrices, each line is a row of the matrix, with elements separated by the separating character.
For sparse matrices, the format (assuming the field separator is ',') is a sequence of comma-separated (row, column, value) triplets, preceded by a line containing the dimensions of the matrix:
(This is not a standardized format, just a simple custom adaptation of CSV for sparse matrices.)
If a block header is specified for readMatrix(), it is used to set the separating character (deserialized from the custom field of the header) for this read, and the character specified when constructing the codec is ignored.
Definition at line 87 of file MatrixIO.hpp.
|
inherited |
|
virtualinherited |
|
pure virtualinherited |
Get the name of the object.
Implemented in TextureFormat, CodecJpeg, Codec_UNKNOWN, CodecAuto, NamedObject, GlTexture, GlShader, GlBufferPool, GlFramebuffer, and GlRenderSystem.
|
pure virtualinherited |
Given an input stream and an optional (already extracted) block header, check if the codec is suitable for decoding the stream.
Among other things, this function can check the magic string in the block header (if present), whether the stream name has an appropriate extension (if no block header is present), and whether the serialized and target matrix types are similarly sparse or dense.
|
inherited |
|
inherited |
|
pure virtualinherited |
Read the matrix from an input stream.
Any block header, if present, is assumed to have already been extracted from the stream and stored in the object pointed to by block_header. Else, block_header should be a null pointer.
|
virtualinherited |
Set the name of the object.
Implements INamedObject.
|
staticinherited |
|
pure virtualinherited |
Write the matrix to an output stream, optionally preceded by a block header.
|
staticinherited |
The standard length (in bytes) of the codec's magic string as used in BlockHeader.