Relacs DataFile Library  0.9.8
Classes | Public Types | Public Member Functions | List of all members
DataFile Class Reference

#include <datafile.h>

Inheritance diagram for DataFile:
Inheritance graph
[legend]
Collaboration diagram for DataFile:
Collaboration graph
[legend]

Public Types

enum  Levels { DataCommentLevel =-3, DataKeyLevel =-2, DataFileLevel =-1 }
 
typedef void(DataFile::* ScanDataFunc )(void)
 

Public Member Functions

 DataFile (void)
 
 DataFile (const istream &is)
 
 DataFile (const string &file)
 
 ~DataFile (void)
 
bool open (const istream &is)
 
bool open (const string &file)
 
void close (void)
 
int readEmptyLines (void)
 
bool readBlock (void)
 
int readMetaData (void)
 
bool initData (void)
 
bool readDataLine (int stopempty)
 
void scanDataLine (void)
 
int readData (int stopempty, ScanDataFunc rdf=&DataFile::scanDataLine)
 
int read (int stopempty=1, ScanDataFunc rdf=&DataFile::scanDataLine)
 
bool getline (void)
 
bool emptyLine (void) const
 
bool metaLine (void) const
 
bool dataLine (void) const
 
int levels (void) const
 
int newLevels (void) const
 
const StrQueuemetaData (int level) const
 
StrQueuemetaData (int level)
 
const OptionsmetaDataOptions (int level) const
 
OptionsmetaDataOptions (int level)
 
const StrQueuedataFile (void) const
 
const OptionsdataFileOptions (void) const
 
const StrQueuedataKey (void) const
 
const OptionsdataKeyOptions (void) const
 
const StrQueuedataComments (void) const
 
const OptionsdataCommentsOptions (void) const
 
bool newMetaData (int level) const
 
bool newDataFile (void) const
 
bool newDataKey (void) const
 
bool newDataComments (void) const
 
int metaDataIndex (int level) const
 
int dataFileIndex (void) const
 
int dataKeyIndex (void) const
 
int dataCommentIndex (void) const
 
int emptyLines (int level) const
 
int metaDataCount (int level) const
 
int metaDataTotalCount (int level) const
 
void resetMetaDataCount (void)
 
void add (int level, const string &line)
 
void addFile (const string &line)
 
void addComment (const string &line)
 
void addNewComment (const string &line)
 
void add (int level, const StrQueue &sq)
 
void addFile (const StrQueue &sq)
 
void addComment (const StrQueue &sq)
 
void insert (int level, const string &line)
 
void insertFile (const string &line)
 
void insertComment (const string &line)
 
void insert (int level, const StrQueue &sq)
 
void insertFile (const StrQueue &sq)
 
void insertComment (const StrQueue &sq)
 
string line (void) const
 
const string & line (void)
 
void splitLine (StrQueue &items, const string separators=Str::WhiteSpace) const
 
int lineNum (void) const
 
int dataLines (void) const
 
int emptyLines (void) const
 
const TableKeykey (void) const
 
int column (const string &pattern) const
 
TableDatadata (void)
 
const TableDatadata (void) const
 
double data (int col, int row) const
 
double & data (int col, int row)
 
double data (const string &pattern, int row) const
 
double & data (const string &pattern, int row)
 
double operator() (int col, int row) const
 
double operator() (const string &pattern, int row) const
 
ArrayDcol (int col)
 
ArrayDcol (const string &pattern)
 
bool newData (void) const
 
bool good (void) const
 
bool eof (void) const
 
bool fail (void) const
 
bool bad (void) const
 
string comment (void) const
 
void setComment (const string &comment)
 

Detailed Description

Reading Ascii Data Files.

Author
Jan Benda
Version
1.1

Member Typedef Documentation

typedef void(DataFile::* ScanDataFunc)(void)

Member Enumeration Documentation

enum Levels

Special meta data levels.

Enumerator
DataCommentLevel 

A comment within a block of data.

DataKeyLevel 

A key describing the data.

DataFileLevel 

A general description of the data file (the first block of meta data).

Constructor & Destructor Documentation

DataFile ( void  )
DataFile ( const istream &  is)

References DataFile::open().

DataFile ( const string &  file)

References DataFile::open().

~DataFile ( void  )

References DataFile::close().

Member Function Documentation

bool open ( const istream &  is)

Open stream is for reading.

Returns
true on success.

Referenced by DataFile::DataFile().

bool open ( const string &  file)

Open file file for reading.

Returns
true on success.
void close ( void  )

Close file and clear all data buffers.

References StrQueue::clear(), TableData::clear(), and TableKey::clear().

Referenced by DataFile::~DataFile().

int readEmptyLines ( void  )

Read in successive empty line.

Returns
number of read in empty lines. Zero if there wasn't any empty line.

References DataFile::emptyLine(), and DataFile::good().

Referenced by DataFile::readBlock(), DataFile::readDataLine(), and DataFile::readMetaData().

bool readBlock ( void  )

Read a single block of meta data and the following empty lines.

Returns
true on success, i.e. a block of meta data was at the current position in the file.

References StrQueue::add(), DataFile::DataFileLevel, DataFile::DataKeyLevel, StrQueue::empty(), DataFile::good(), DataFile::key(), DataFile::metaLine(), and DataFile::readEmptyLines().

Referenced by DataFile::readMetaData().

int readMetaData ( void  )

Read all blocks of meta data until the data block is reached.

Returns
the number of read in meta data blocks.

References DataFile::good(), DataFile::metaLine(), DataFile::readBlock(), DataFile::readEmptyLines(), and DataFile::resetMetaDataCount().

Referenced by DataFile::read().

bool initData ( void  )

Init member variables for a new block of data. Use this function before using readDataLine().

References TableData::clear(), DataFile::DataCommentLevel, DataFile::dataLine(), and DataFile::good().

Referenced by DataFile::readData().

bool readDataLine ( int  stopempty)

Read lines until the next data line. Comment lines are stored as Data Comments. Empty lines are skipped. If stopempty or more empty lines are encountered false is returned. Use this function together with initData() in the following way:

DataFile sf( "test.dat" );
while ( sf.readMetaData() ) {
// ... process meta data ...
sf.initData();
do {
// ... process data line ...
cout << sf.line() << endl; // just print it out
} while ( sf.readDataLine( 1 ) );
// ... process data block ...
cout << "read " << sf.dataLines() << " lines of data" << endl;
}
sf.close();

References DataFile::addNewComment(), DataFile::DataCommentLevel, DataFile::dataLine(), DataFile::emptyLine(), DataFile::good(), DataFile::metaLine(), and DataFile::readEmptyLines().

Referenced by DataFile::readData().

void scanDataLine ( void  )
int readData ( int  stopempty,
ScanDataFunc  rdf = &DataFile::scanDataLine 
)

Read in a block of data, until stopempty empty lines are encountered.

Returns
the number of data lines that have been read. Uses the function rdf for processing the data.

References DataFile::DataCommentLevel, DataFile::initData(), and DataFile::readDataLine().

Referenced by DataFile::read().

int read ( int  stopempty = 1,
ScanDataFunc  rdf = &DataFile::scanDataLine 
)

Read all metadata and the following data, until stopempty empty lines are encountered.

Returns
the number of data lines that have been read.

References DataFile::readData(), and DataFile::readMetaData().

bool getline ( void  )

Read a single line. The content of the line is accesible by line().

References DataFile::good().

bool emptyLine ( void  ) const

True if the current line is an empty line.

References Str::empty().

Referenced by DataFile::readDataLine(), and DataFile::readEmptyLines().

bool metaLine ( void  ) const

True if the current line contains meta data, i.e. a line that starts with the comment character.

See Also
comment(), setComment()

References Str::first(), and Str::substr().

Referenced by DataFile::readBlock(), DataFile::readDataLine(), and DataFile::readMetaData().

bool dataLine ( void  ) const

True if the current line contains data, i.e. a line that is not empty and does not start with the comment character.

See Also
emptyLine(), metaLine()

References Str::first(), and Str::substr().

Referenced by DataFile::initData(), and DataFile::readDataLine().

int levels ( void  ) const

The number of meta data blocks in the buffer.

int newLevels ( void  ) const

The number of of new meta data blocks.

const StrQueue & metaData ( int  level) const

Returns a const reference to the metaData of level level. If the requested level does not exist, an empty StrQueue is returned.

References StrQueue::clear().

Referenced by DataFile::dataComments(), DataFile::dataFile(), DataFile::dataKey(), and DataFile::metaDataOptions().

StrQueue & metaData ( int  level)

Returns a reference to the metaData of level level. If the requested level does not exist, an empty StrQueue is returned.

References StrQueue::clear().

const Options & metaDataOptions ( int  level) const

Returns a const reference to the metaData of level level converted to Options. If the requested level does not exist, an empty Options is returned.

References DataFile::metaData().

Referenced by DataFile::dataCommentsOptions(), DataFile::dataFileOptions(), and DataFile::dataKeyOptions().

Options & metaDataOptions ( int  level)

Returns a reference to the metaData of level level converted to Options. If the requested level does not exist, an empty Options is returned.

References DataFile::metaData().

const StrQueue & dataFile ( void  ) const

Return a const reference to the special "File" meta data block.

References DataFile::DataFileLevel, and DataFile::metaData().

const Options & dataFileOptions ( void  ) const

Return a const reference to the special "File" meta data block converted to Options.

References DataFile::DataFileLevel, and DataFile::metaDataOptions().

const StrQueue & dataKey ( void  ) const

Return a const reference to the special "Key" meta data block.

References DataFile::DataKeyLevel, and DataFile::metaData().

Referenced by DataFile::key().

const Options & dataKeyOptions ( void  ) const

Return a const reference to the special "Key" meta data block converted to Options.

References DataFile::DataKeyLevel, and DataFile::metaDataOptions().

const StrQueue & dataComments ( void  ) const

Return a const reference to the meta data which were read within a data block.

References DataFile::DataCommentLevel, and DataFile::metaData().

const Options & dataCommentsOptions ( void  ) const

Return a const reference to the meta data which were read within a data block converted to Options.

References DataFile::DataCommentLevel, and DataFile::metaDataOptions().

bool newMetaData ( int  level) const

True if new meta data of level level where read in since the last call of read().

Referenced by DataFile::newDataComments(), DataFile::newDataFile(), and DataFile::newDataKey().

bool newDataFile ( void  ) const

True if new special "file" meta data where read in since the last call of read(). Should be true after the first call to read() only.

References DataFile::DataFileLevel, and DataFile::newMetaData().

bool newDataKey ( void  ) const

True if new special "key" meta data where read in since the last call of read().

References DataFile::DataKeyLevel, and DataFile::newMetaData().

bool newDataComments ( void  ) const

True if new meta data within the data block where read in since the last call of read().

References DataFile::DataCommentLevel, and DataFile::newMetaData().

int metaDataIndex ( int  level) const

Each block of data and meta data is numbered in the order they are read in from the file. This function returns the number of the current block of meta data of level level. If the requested meta data do not exist, -1 is returned.

See Also
dataFileIndex(), dataKeyIndex(), dataCommentIndex()

Referenced by DataFile::dataCommentIndex(), DataFile::dataFileIndex(), and DataFile::dataKeyIndex().

int dataFileIndex ( void  ) const

Each block of data and meta data is numbered in the order they are read in from the file. This function returns the number of the special "file" meta data. The return value should be zero since the "file" meta data are always the first meta data, if these meta data are present, and -1 otherwise.

See Also
metaDataIndex()

References DataFile::DataFileLevel, and DataFile::metaDataIndex().

int dataKeyIndex ( void  ) const

Each block of data and meta data is numbered in the order they are read in from the file. This function returns the number of the special "key" meta data.

See Also
metaDataIndex()

References DataFile::DataKeyLevel, and DataFile::metaDataIndex().

int dataCommentIndex ( void  ) const

Each block of data and meta data is numbered in the order they are read in from the file. This function returns the number of the special "data comment" meta data.

See Also
metaDataIndex()

References DataFile::DataCommentLevel, and DataFile::metaDataIndex().

int emptyLines ( int  level) const

Returns the number of empty line that followed the block of meta data of level level.

int metaDataCount ( int  level) const

The number of meta data blocks of level level read in after the last call of resetMetaDataCount().

int metaDataTotalCount ( int  level) const

The total number of meta data blocks of level level.

void resetMetaDataCount ( void  )

Reset the count for all meta data levels.

References DataFile::DataCommentLevel, and DataFile::DataKeyLevel.

Referenced by DataFile::readMetaData().

void add ( int  level,
const string &  line 
)

Add a line line to the meta data of level level.

Referenced by DataFile::addComment(), DataFile::addFile(), and DataFile::addNewComment().

void addFile ( const string &  line)

Add a line line to the special "file" meta data.

References DataFile::add(), and DataFile::DataFileLevel.

void addComment ( const string &  line)

Add a line line to the special "data comments" meta data.

References DataFile::add(), and DataFile::DataCommentLevel.

void addNewComment ( const string &  line)

Add a line line to the special "data comments" meta data, and mark them as new.

References DataFile::add(), and DataFile::DataCommentLevel.

Referenced by DataFile::readDataLine().

void add ( int  level,
const StrQueue sq 
)

Add several lines of text sq to the meta data of level level.

void addFile ( const StrQueue sq)

Add several lines of text sq to the special "file" meta data.

References DataFile::add(), and DataFile::DataFileLevel.

void addComment ( const StrQueue sq)

Add several lines of text sq to the special "data comments" meta data.

References DataFile::add(), and DataFile::DataCommentLevel.

void insert ( int  level,
const string &  line 
)

Insert a line line at the beginning of the meta data of level level.

Referenced by DataFile::insertComment(), and DataFile::insertFile().

void insertFile ( const string &  line)

Insert a line line at the beginning of the special "file" meta data.

References DataFile::DataFileLevel, and DataFile::insert().

void insertComment ( const string &  line)

Insert a line line at the beginning of the special "data comments" meta data.

References DataFile::DataCommentLevel, and DataFile::insert().

void insert ( int  level,
const StrQueue sq 
)

Insert several lines of text sq at the beginning of the meta data of level level.

void insertFile ( const StrQueue sq)

Insert several lines of text sq at the beginning of the special "file" meta data.

References DataFile::DataFileLevel, and DataFile::insert().

void insertComment ( const StrQueue sq)

Insert several lines of text sq at the beginning of the special "data comments" meta data.

References DataFile::DataCommentLevel, and DataFile::insert().

string line ( void  ) const

The current line.

const string & line ( void  )

The current line.

void splitLine ( StrQueue items,
const string  separators = Str::WhiteSpace 
) const

The current line split up in its data items.

References StrQueue::add(), StrQueue::clear(), Str::mid(), and Str::nextWord().

int lineNum ( void  ) const

The number of read in lines.

int dataLines ( void  ) const

The number of data lines read in by the last call of readData().

int emptyLines ( void  ) const

The number of empty lines following the last read in block of data.

const TableKey & key ( void  ) const

The current table key.

References TableKey::clear(), DataFile::dataKey(), and TableKey::loadKey().

Referenced by DataFile::column(), and DataFile::readBlock().

int column ( const string &  pattern) const

Returns the column index whose identifier string in the key() matches pattern. The first column is 0.

References TableKey::column(), and DataFile::key().

TableData& data ( void  )
inline
const TableData& data ( void  ) const
inline
double data ( int  col,
int  row 
) const
inline
double& data ( int  col,
int  row 
)
inline
double data ( const string &  pattern,
int  row 
) const
inline
double& data ( const string &  pattern,
int  row 
)
inline
double operator() ( int  col,
int  row 
) const
inline
double operator() ( const string &  pattern,
int  row 
) const
inline
ArrayD& col ( int  col)
inline
ArrayD& col ( const string &  pattern)
inline
bool newData ( void  ) const
bool good ( void  ) const
bool eof ( void  ) const

True if the end of the file is reached.

bool fail ( void  ) const

True if an error other than an End-Of-File occured.

bool bad ( void  ) const

True if the state of the file is bad, i.e. an unrecoverable error has occured.

string comment ( void  ) const

The string indicating a comment.

Referenced by DataFile::setComment().

void setComment ( const string &  comment)

Set the string for indicating comments to comment.

References DataFile::comment().


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