Public Member Functions | Protected Attributes

DGVFile Class Reference

This class handles reading and writing of files with comments using Qt. More...

#include <DGVFile.h>

List of all members.

Public Member Functions

 DGVFile ()
 Constructor.
 DGVFile (QString name, QString mode)
virtual ~DGVFile ()
bool open (QString name, QString mode)
 Open file with filename. Mode is either "r" for read, "w" for write or "a" for append.
void close ()
 Close the current file.
void writeLine (QString data)
 Write the line given by "data" to the current file.
void writeIntegerArrayAsLine (Array< long, 1 > &data)
 Write the line given by the array "data" to the current file.
void writeDoubleArrayAsLine (Array< double, 1 > &data)
 Write the line given by the array "data" to the current file.
void writeComment (QString comment)
 Write the comment to the current file.
QString readNextString ()
 Read the next element as a string from the current file. NOT IMPLEMENTED!
long readNextInteger ()
 Read the next element as an integer from the current file. NOT IMPLEMENTED!
double readNextDouble ()
 Read the next element as an double from the current file. NOT IMPLEMENTED!
QStringList readLine ()
 Read the next line as a string list from the current file. Same as readNextLine().
QStringList readNextLine ()
 Read the next line as a string list from the current file.
void readNextLineAsIntegers (Array< long, 1 > &values)
 Read the next line as a integer list from the current file. Array is automatically resized to correct size.
void readNextLineAsDoubles (Array< double, 1 > &values)
 Read the next line as a double list from the current file. Array is automatically resized to correct size.
void setSeparator (QString symbol)
 Set the separator of the data in the current file.
void setCommentSymbol (QString symbol)
 Set the comment symbol of the data in the current file.
void ignoreComments (bool ignore)
 Ignore comments in the current file. Default is true.
bool atEnd ()
 Return true if the end of the current file is reached.
void setVerboseMode (bool verbose)
 Read as much of the file as possible. Useful in comment ignore mode if file has empty entries.

Protected Attributes

QString commentSymbol
QString separator
bool comments
bool openedIn
bool openedOut
bool openedAppend
bool verboseMode
QString fileName
QString fileMode
QFile file
QTextStream * in
QTextStream * out
QTextStream * append

Detailed Description

This class handles reading and writing of files with comments using Qt.

Author:
Shekhar S. Chandra, 2008-2009

It is mainly used to read/write CSV and Diophantine (to setup a system using DGVLatticeVTK and DGVDiophantineVTK classes) files.

Mode needs to be set for the operation that needs to be done. Mode is either "r" for read, "w" for write or "a" for append.

Definition at line 40 of file DGVFile.h.


Constructor & Destructor Documentation

DGVFile::DGVFile (  ) 

Constructor.

Constructor with filename and mode pass in. Mode is either "r" for read, "w" for write or "a" for append.

Equivalent to calling open().

Definition at line 24 of file DGVFile.cpp.

DGVFile::DGVFile ( QString  name,
QString  mode 
)

Definition at line 35 of file DGVFile.cpp.

DGVFile::~DGVFile (  )  [virtual]

Definition at line 48 of file DGVFile.cpp.


Member Function Documentation

bool DGVFile::atEnd (  ) 

Return true if the end of the current file is reached.

Definition at line 252 of file DGVFile.cpp.

void DGVFile::close (  ) 

Close the current file.

Definition at line 101 of file DGVFile.cpp.

DGVFile::ignoreComments ( bool  ignore  )  [inline]

Ignore comments in the current file. Default is true.

Definition at line 149 of file DGVFile.h.

bool DGVFile::open ( QString  name,
QString  mode 
)

Open file with filename. Mode is either "r" for read, "w" for write or "a" for append.

Definition at line 53 of file DGVFile.cpp.

DGVFile::readLine (  )  [inline]

Read the next line as a string list from the current file. Same as readNextLine().

Definition at line 115 of file DGVFile.h.

DGVFile::readNextDouble (  ) 

Read the next element as an double from the current file. NOT IMPLEMENTED!

Todo:
Implement read double member
DGVFile::readNextInteger (  ) 

Read the next element as an integer from the current file. NOT IMPLEMENTED!

Todo:
Implement read int member
QStringList DGVFile::readNextLine (  ) 

Read the next line as a string list from the current file.

Check for comments Ignore if present and told to ignore

Remove comment (everything after comment symbol

Definition at line 196 of file DGVFile.cpp.

void DGVFile::readNextLineAsDoubles ( Array< double, 1 > &  values  ) 

Read the next line as a double list from the current file. Array is automatically resized to correct size.

Definition at line 241 of file DGVFile.cpp.

void DGVFile::readNextLineAsIntegers ( Array< long, 1 > &  values  ) 

Read the next line as a integer list from the current file. Array is automatically resized to correct size.

Definition at line 230 of file DGVFile.cpp.

DGVFile::readNextString (  ) 

Read the next element as a string from the current file. NOT IMPLEMENTED!

Todo:
Implement read string member
DGVFile::setCommentSymbol ( QString  symbol  )  [inline]

Set the comment symbol of the data in the current file.

Definition at line 143 of file DGVFile.h.

DGVFile::setSeparator ( QString  symbol  )  [inline]

Set the separator of the data in the current file.

Definition at line 137 of file DGVFile.h.

DGVFile::setVerboseMode ( bool  verbose  )  [inline]

Read as much of the file as possible. Useful in comment ignore mode if file has empty entries.

Definition at line 161 of file DGVFile.h.

void DGVFile::writeComment ( QString  comment  )  [inline]

Write the comment to the current file.

Definition at line 152 of file DGVFile.cpp.

void DGVFile::writeDoubleArrayAsLine ( Array< double, 1 > &  data  ) 

Write the line given by the array "data" to the current file.

Definition at line 142 of file DGVFile.cpp.

void DGVFile::writeIntegerArrayAsLine ( Array< long, 1 > &  data  ) 

Write the line given by the array "data" to the current file.

Definition at line 132 of file DGVFile.cpp.

void DGVFile::writeLine ( QString  data  ) 

Write the line given by "data" to the current file.

Definition at line 119 of file DGVFile.cpp.


Member Data Documentation

QTextStream* DGVFile::append [protected]

Definition at line 178 of file DGVFile.h.

bool DGVFile::comments [protected]

Definition at line 167 of file DGVFile.h.

QString DGVFile::commentSymbol [protected]

Definition at line 165 of file DGVFile.h.

QFile DGVFile::file [protected]

Definition at line 175 of file DGVFile.h.

QString DGVFile::fileMode [protected]

Definition at line 173 of file DGVFile.h.

QString DGVFile::fileName [protected]

Definition at line 172 of file DGVFile.h.

QTextStream* DGVFile::in [protected]

Definition at line 176 of file DGVFile.h.

bool DGVFile::openedAppend [protected]

Definition at line 170 of file DGVFile.h.

bool DGVFile::openedIn [protected]

Definition at line 168 of file DGVFile.h.

bool DGVFile::openedOut [protected]

Definition at line 169 of file DGVFile.h.

QTextStream* DGVFile::out [protected]

Definition at line 177 of file DGVFile.h.

QString DGVFile::separator [protected]

Definition at line 166 of file DGVFile.h.

bool DGVFile::verboseMode [protected]

Definition at line 171 of file DGVFile.h.


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