linbox
Public Member Functions | Protected Member Functions | Protected Attributes
MatrixStreamReader< Field > Class Template Referenceabstract

An abstract base class to represent readers for specific formats. More...

#include <matrix-stream.h>

Inherited by DenseReader< Field >, MapleReader< Field >, MatrixMarketReader< Field >, SMSReader< Field >, and SparseRowReader< Field >.

Public Member Functions

virtual const char * getName () const =0
 Get a unique string describing this format. More...
 
virtual const char * shortName () const
 Get a (possibly) shortened version of the format name. More...
 
virtual bool isSparse () const =0
 Determine if this format is sparse or dense. More...
 
MatrixStreamError init (const char *, std::istream *, MatrixStream< Field > *)
 Initialize this MatrixStreamReader. More...
 
MatrixStreamError nextTriple (size_t &, size_t &, Element &)
 Get the next triple of row index, column index, value and store it into the three referenced variables. More...
 
virtual MatrixStreamError getArray (std::vector< Element > &array)
 Get the whole matrix as a dense (row-major) array of elements. More...
 
MatrixStreamError saveNext ()
 Reads the next triple from the subclass nextTripleImpl method and saves it to the savedTriples std::queue rather than returning it. More...
 
MatrixStreamError getRows (size_t &)
 Get the number of rows in this matrix, store it in the given int. More...
 
MatrixStreamError getColumns (size_t &)
 Get the number of columns in this matrix, store it in the given int. More...
 
virtual ~MatrixStreamReader ()
 Virtual destructor. More...
 

Protected Member Functions

void saveTriple (size_t m, size_t n, const Element &v)
 Save the triple (m,n,v) onto the savedTriples std::queue. More...
 
virtual MatrixStreamError nextTripleImpl (size_t &, size_t &, Element &)=0
 Read the next triple of row index, column index, value and store it in the given references. More...
 
virtual MatrixStreamError initImpl (const char *firstLine)=0
 Read the first line of the matrix from the stream and attempt to determine if it is of this reader's type. More...
 
 MatrixStreamReader ()
 A protected constructor that is called automatically when subclasses are instantiated. More...
 

Protected Attributes

std::istream * sin
 The stream that provides the data to the reader.
 
MatrixStream< Field > * ms
 A pointer to the MatrixStream that is using this reader. More...
 
size_t _m
 The number of rows in the matrix. More...
 
bool knowM
 Indicates whether the row dimension is accurate.
 
size_t _n
 Number of columns in the matrix. More...
 
bool knowN
 Indicates whether the column dimension is accurate.
 
bool atEnd
 Indicates that the end of the matrix has been reached; no more calls to nextTripleImpl will be made once this value is true. More...
 

Detailed Description

template<class Field>
class LinBox::MatrixStreamReader< Field >

An abstract base class to represent readers for specific formats.

For each format that is to be supported, make an extension of this class that implements protected methods nextTripleImpl and initImpl.

Constructor & Destructor Documentation

◆ MatrixStreamReader()

MatrixStreamReader ( )
inlineprotected

A protected constructor that is called automatically when subclasses are instantiated.

◆ ~MatrixStreamReader()

virtual ~MatrixStreamReader ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

◆ saveTriple()

void saveTriple ( size_t  m,
size_t  n,
const Element &  v 
)
protected

Save the triple (m,n,v) onto the savedTriples std::queue.

◆ nextTripleImpl()

virtual MatrixStreamError nextTripleImpl ( size_t &  ,
size_t &  ,
Element &   
)
protectedpure virtual

Read the next triple of row index, column index, value and store it in the given references.

Returns
A MatrixStreamError indicating the success or failure of the operation

◆ initImpl()

virtual MatrixStreamError initImpl ( const char *  firstLine)
protectedpure virtual

Read the first line of the matrix from the stream and attempt to determine if it is of this reader's type.

Returns
A MatrixStreamError indicating the success or failure of the operation

◆ getName()

virtual const char* getName ( ) const
pure virtual

Get a unique string describing this format.

◆ shortName()

virtual const char* shortName ( ) const
inlinevirtual

Get a (possibly) shortened version of the format name.

◆ isSparse()

virtual bool isSparse ( ) const
pure virtual

Determine if this format is sparse or dense.

Returns
true if it is a sparse format, false if it is a dense one

◆ init()

MatrixStreamError init ( const char *  firstLine,
std::istream *  i,
MatrixStream< Field > *  m 
)

Initialize this MatrixStreamReader.

Calls the initImpl method of the subclass.

◆ nextTriple()

MatrixStreamError nextTriple ( size_t &  m,
size_t &  n,
Element &  v 
)

Get the next triple of row index, column index, value and store it into the three referenced variables.

Uses the nextTripleImpl method of the subclass.

◆ getArray()

MatrixStreamError getArray ( std::vector< Element > &  array)
virtual

Get the whole matrix as a dense (row-major) array of elements.

By default, this implementation just repeatedly calls nextTriple to read in the whole matrix. Subclasses of dense formats should override this behavior.

Parameters
arrayThe array to fill with entries. May be resized as needed.

◆ saveNext()

MatrixStreamError saveNext ( )

Reads the next triple from the subclass nextTripleImpl method and saves it to the savedTriples std::queue rather than returning it.

The error returned is that given from the subclass method.

◆ getRows()

MatrixStreamError getRows ( size_t &  m)

Get the number of rows in this matrix, store it in the given int.

◆ getColumns()

MatrixStreamError getColumns ( size_t &  n)

Get the number of columns in this matrix, store it in the given int.

Field Documentation

◆ ms

MatrixStream<Field>* ms
protected

A pointer to the MatrixStream that is using this reader.

Useful to get an instance of the field via ms->getField().

◆ _m

size_t _m
protected

The number of rows in the matrix.

This will be set by default to 0.

◆ _n

size_t _n
protected

Number of columns in the matrix.

Similar requirements as _m above.

◆ atEnd

bool atEnd
protected

Indicates that the end of the matrix has been reached; no more calls to nextTripleImpl will be made once this value is true.

This will automatically be set to true if nextTripleImpl returns END_OF_MATRIX.


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