Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

MatrixStreamReader Class Template Reference

#include <matrix-stream.h>

Inheritance diagram for MatrixStreamReader:

DenseReader MapleDense1Reader MapleSparse1Reader MatrixMarketReader SMSReader SparseRowReader List of all members.

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.


Public Types

typedef Field::Element Element

Public Methods

virtual const char * getName () const=0
virtual bool isSparse () const=0
MatrixStreamError init (istream *, MatrixStream< Field > *)
MatrixStreamError nextTriple (int &, int &, Element &)
MatrixStreamError saveNext ()
MatrixStreamError getRows (int &)
MatrixStreamError getColumns (int &)
virtual int getLineNumber () const
virtual ~MatrixStreamReader ()

Protected Methods

bool readWhiteSpace (bool allowBreaks=false)
bool readSomeWhiteSpace (bool allowBreaks=false)
bool readWhiteSpace (int &breaks, bool allowBreaks=true)
bool readSomeWhiteSpace (int &breaks, bool allowBreaks=true)
bool readBreaks (int breaks=1)
bool readUntil (char c, stringstream *ss=NULL, int limit=-1)
vector< char * >::const_iterator readUntil (const vector< char * > &cm, stringstream *ss=NULL, int limit=-1)
bool readElement (Element &x)
template<class Object> bool readObject (Object &o)
bool moreData ()
void saveTriple (int m, int n, const Element &v)
virtual MatrixStreamError nextTripleImpl (int &, int &, Element &)=0
virtual MatrixStreamError initImpl ()=0
 MatrixStreamReader ()

Protected Attributes

istream * sin
MatrixStream< Field > * ms
int lineNumber
int _m
int _n
bool atEnd


Member Typedef Documentation

typedef Field::Element Element
 

Reimplemented in DenseReader, MapleDense1Reader, MapleSparse1Reader, MatrixMarketReader, SMSReader, and SparseRowReader.


Constructor & Destructor Documentation

MatrixStreamReader   [inline, protected]
 

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

virtual ~MatrixStreamReader   [inline, virtual]
 

Virtual destructor.


Member Function Documentation

MatrixStreamError getColumns int &   
 

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

virtual int getLineNumber   const [inline, virtual]
 

Get the line number that this reader is currently on.

virtual const char* getName   [pure virtual]
 

Get a unique string describing this format.

Implemented in DenseReader, MapleDense1Reader, MapleSparse1Reader, MatrixMarketReader, SMSReader, and SparseRowReader.

MatrixStreamError getRows int &   
 

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

MatrixStreamError init istream *   ,
MatrixStream< Field > *   
 

Initialize this MatrixStreamReader. Calls the initImpl method of the subclass.

virtual MatrixStreamError initImpl   [protected, pure virtual]
 

Read the beginning (header) 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

Implemented in DenseReader, MatrixMarketReader, SMSReader, and SparseRowReader.

virtual bool isSparse   [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

Implemented in DenseReader, MapleDense1Reader, MapleSparse1Reader, MatrixMarketReader, SMSReader, and SparseRowReader.

bool moreData   [protected]
 

Try and get more data from the underlying input stream. Should be called when an EOF is reached on input.

Returns:
true iff more data was available and has been added to sin.

MatrixStreamError nextTriple int &   ,
int &   ,
Element  
 

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.

virtual MatrixStreamError nextTripleImpl int &   ,
int &   ,
Element  
[protected, pure 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

Implemented in DenseReader, MatrixMarketReader, SMSReader, and SparseRowReader.

bool readBreaks int    breaks = 1 [inline, protected]
 

Read up to breaks breaks. Reading will stop on the first non-whitespace character or first newline after breaks newlines. After a successful call, there will be at least one character available on the stream.

Parameters:
breaks  The number of breaks to read.
Exceptions:
END_OF_FILE  if an EOF is encountered before any non-whitespace characters.

bool readElement Element   x [protected]
 

Read a field element. Uses the read method of the field for the parent MatrixStream object.

Parameters:
x  Where to store the read element.
Returns:
True iff the read was successful

bool readObject Object &    o [protected]
 

Read any object. Uses the overloaded stream extraction operator>>, which must be defined for this type.

Parameters:
o  Where to store the read object
Returns:
True iff the read was successful.

bool readSomeWhiteSpace int &    breaks,
bool    allowBreaks = true
[inline, protected]
 

Read white space. Does not require that any white space characters be read. After a successful call, there will be at least one character available on the stream.

Parameters:
breaks  Upon successful return, this int will contain the number of breaks (newlines) that were read.
allowBreaks  If false, the function will return false if it encounters a newline.
Exceptions:
END_OF_FILE  if an EOF is encountered before any non-whitespace characters.

bool readSomeWhiteSpace bool    allowBreaks = false [inline, protected]
 

Read white space. Does not require that any white space characters be read. After a successful call, there will be at least one character available on the stream.

Parameters:
allowBreaks  If false, the function will return false if it encounters a newline.
Exceptions:
END_OF_FILE  if an EOF is encountered before any non-whitespace characters.

vector< char * >::const_iterator readUntil const vector< char * > &    cm,
stringstream *    ss = NULL,
int    limit = -1
[protected]
 

Read until an unmatched character.

Parameters:
cm  A vector of char* strings, each containing (at least) two characters: the left-match and the right-match, e.g. "()". If the character has no match (e.g. ','), the first character in the array should be null, e.g. "\0,".
ss  A pointer to a stringstream to which to write all characters read (except for the unmatched one)
limit  The maximum number of characters to read.
Returns:
The iterator that points to the pair in cm that was unmatched.

bool readUntil char    c,
stringstream *    ss = NULL,
int    limit = -1
[protected]
 

Read up to a given character.

Parameters:
c  The character to read until. This character is extracted and not put back.
ss  A pointer to a stringstream to which to write all characters read (except, again, for c)
limit  The maximum number of characters to read.
Returns:
True if c is read before limit characters are seen, false o.w.

bool readWhiteSpace int &    breaks,
bool    allowBreaks = true
[inline, protected]
 

Read white space. Function returns true if and only if at least one character of white space is read. After a successful call, there will be at least one character available on the stream.

Parameters:
breaks  Upon successful return, this int will contain the number of breaks (newlines) that were read.
allowBreaks  If false, the function will return false if it encounters a newline.
Exceptions:
END_OF_FILE  if an EOF is encountered before any non-whitespace characters.

bool readWhiteSpace bool    allowBreaks = false [inline, protected]
 

Read white space. Function returns true if and only if at least one character of white space is read. After a successful call, there will be at least one character available on the stream.

Parameters:
allowBreaks  If false, the function will return false if it encounters a newline.
Exceptions:
END_OF_FILE  if an EOF is encountered before any non-whitespace characters.

MatrixStreamError saveNext  
 

Reads the next triple from the subclass nextTripleImpl method and saves it to the savedTriples queue rather than returning it. The error returned is that given from the subclass method.

void saveTriple int    m,
int    n,
const Element   v
[protected]
 

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


Member Data Documentation

int _m [protected]
 

The number of rows in the matrix. This will be set by default to -1. Its value should not be set to a meaningful number until the reader is confident in the number of rows in the matrix.

int _n [protected]
 

Number of columns in the matrix. Similar requirements as _m above.

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 nextTripleImple returns END_OF_MATRIX.

int lineNumber [protected]
 

The lineNumber is recorded in case the user wants to know at which line an error occurs. This will be updated automatically by any of the read methods below if they encounter breaks; it is up to the subclasses to increment lineNumber if they read any newline characters independently.

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

istream* sin [protected]
 

The stream that provides the data to the reader. NOTE: subclasses should NOT use this stream directly except for one-byte reading as in sin->get(). This stream only contains a portion of the matrix data; this data must be replentished with calls to moreData(). If at all possible use sin->get() only and use the various read... methods below to read data.


Generated on Mon Jun 20 09:16:52 2005 for linbox by doxygen1.2.18