Thea
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
CodecCsv< MatrixT, Enable > Class Template Referenceabstract

Codec for reading/writing matrices to/from comma-separated values (CSV) text files. More...

#include <MatrixIO.hpp>

Inheritance diagram for CodecCsv< MatrixT, Enable >:
MatrixCodec< MatrixT > Codec INamedObject

Public Types

typedef std::array< int8,(size_t) MAGIC_LENGTHMagicString
 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...
 

Detailed Description

template<typename MatrixT, typename Enable = void>
class Thea::CodecCsv< MatrixT, Enable >

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:

#rows,#cols
R0,C1,V0
R1,C1,V1
...
RN, CN, VN

(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.

Member Typedef Documentation

typedef std::array<int8, (size_t)MAGIC_LENGTH> MagicString
inherited

The type of the codec's magic string (an array of MAGIC_LENGTH bytes).

Definition at line 42 of file Codec.hpp.

Member Function Documentation

virtual MagicString const& getMagic ( ) const
virtualinherited

Get the magic string for the codec, if it has one (else a string of all zeros).

Reimplemented in CodecJpeg.

Definition at line 127 of file Codec.hpp.

virtual char const* getName ( ) const
pure virtualinherited
virtual bool matches ( BinaryInputStream input,
Codec::BlockHeader const *  block_header 
) const
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.

operator intx ( ) const
inherited

Implicitly convert to an integer value for use in switch statements etc.

This value will be common to all instances of the codec class

Definition at line 136 of file Codec.hpp.

bool operator== ( Codec const &  other) const
inherited

Check if two codecs are equal.

All instances of a codec class must be considered equal.

Definition at line 130 of file Codec.hpp.

virtual void readMatrix ( MatrixT &  m,
BinaryInputStream input,
BlockHeader const *  block_header 
) const
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.

int8 setName ( char const *  s)
virtualinherited

Set the name of the object.

Returns
True if the name was successfully set, else false (e.g. if the name is read-only).

Implements INamedObject.

Definition at line 124 of file Codec.hpp.

static MagicString toMagic ( std::string const &  s)
staticinherited

Convenience function to convert a string literal to a magic string.

Definition at line 139 of file Codec.hpp.

virtual void writeMatrix ( MatrixT const &  m,
BinaryOutputStream output,
bool  write_block_header 
) const
pure virtualinherited

Write the matrix to an output stream, optionally preceded by a block header.

Member Data Documentation

intx const MAGIC_LENGTH = 8
staticinherited

The standard length (in bytes) of the codec's magic string as used in BlockHeader.

Definition at line 39 of file Codec.hpp.


The documentation for this class was generated from the following file: