QASCII Class Reference

List of all members.


Detailed Description

Class for reading and writing ascii text files.

Author:
L. Kogler This class is intended to standardize the reading and writing of temporary data in text files. Currently supports reading and writing QVectors, vectors, and strings. Lines beginning with # are treated as comments.

Public Member Functions

 QASCII ()
 default constructor
 QASCII (const QASCII &orig)
 copy constructor
 QASCII (std::string filename)
 normal constructor
virtual ~QASCII ()
 destructor
bool Exists ()
 Returns true if the file exists and can be opened.
int NumberOfLines (bool ExcludeComments=true)
 Returns the number of lines in the file, excluding comments by default.
QVector * ReadQVector ()
 Reads a text file into a QVector. Text file should contain a list of numbers.
QVector * ReadQVector (int ColumnNumber, int startline=0, int endline=-1)
 Reads text data from a particular column into QVector.
int WriteQVector (QVector outputVector, bool append=false)
 Writes data from a QVector to a file.
int WriteQVectors (std::vector< QVector > outputVector, bool append=false)
 Writes a vector of QVectors, each QVector in a new column. Warning: QVectors of different lengths can be written to the same file, but they may be read back incorrectly!
bool WriteString (std::string outputString, bool append=false)
 Writes a string to a file.
bool WriteLine (std::string line, bool append=true)
 Writes a string to a file, terminated with newline.
bool Comment (std::string comment)
 Writes a comment to a file; begins with '#', terminates with newline.
std::string ReadComment (int commentNumber=0)
 Reads the nth comment from a file. Comments are lines beginning with '#'.
std::string ReadString (int startline=0, int endline=-1)
 Reads entire file or subset of file into a string.
std::vector< double > ReadVector ()
 Reads a text file into a vector. Text file should contain a list of numbers.
std::vector< double > ReadVector (int ColumnNumber, int startline=0, int endline=-1)
 Reads text data from a particular column into a vector.
int WriteVector (std::vector< double > outputVector, bool append=false)
 Writes data from a vector to a file.
int WriteVector (std::vector< int > outputVector, bool append=false)
int WriteVectors (std::vector< std::vector< double > > outputVector, bool append=false)
 Writes a vector of vectors, each vector in a new column. Warning: vectors of different lengths can be written to the same file, but they may be read back incorrectly!
bool WriteQTime (QTime *qt, bool append=true)
 Writes an object of type QTime.
QTimeReadQTime (int startline=0)
 Reads an object of type QTime.
bool WriteQRunData (QRunData *qrd, bool append=false)
 Writes an object of type QRunData.
QRunDataReadQRunData (int startline=0, int endline=-1)
 Reads an object of type QRunData.
void DeleteFile ()
 Deletes file from disk.
int FindLine (std::string pattern, int startline=0)
 Finds a line matching the string pattern.

Private Attributes

std::string fFilename
 Name of the file on disk.

Constructor & Destructor Documentation

QASCII::QASCII ( const QASCII orig  ) 

copy constructor

Parameters:
orig original QASCII

References fFilename.

QASCII::QASCII ( std::string  filename  ) 

normal constructor

Parameters:
filename name of file to be opened


Member Function Documentation

int QASCII::NumberOfLines ( bool  ExcludeComments = true  ) 

Returns the number of lines in the file, excluding comments by default.

Parameters:
ExcludeComments if true, comments are excluded from count, else they are counted as lines

References fFilename.

Referenced by ReadQRunData(), ReadQVector(), ReadString(), and ReadVector().

QVector * QASCII::ReadQVector ( int  ColumnNumber,
int  startline = 0,
int  endline = -1 
)

Reads text data from a particular column into QVector.

Parameters:
ColumnNumber Which column to read from. Numbering starts at 0.
startline line to start from
endline line to end at

References fFilename, and NumberOfLines().

int QASCII::WriteQVector ( QVector  outputVector,
bool  append = false 
)

Writes data from a QVector to a file.

Parameters:
outputVector QVector to write
append append if true, overwrite if false (default)
Returns:
Returns the number of elements written

References fFilename.

int QASCII::WriteQVectors ( std::vector< QVector >  outputVector,
bool  append = false 
)

Writes a vector of QVectors, each QVector in a new column. Warning: QVectors of different lengths can be written to the same file, but they may be read back incorrectly!

Parameters:
outputVector vector of QVectors to write
append append if true, overwrite if false (default)
Returns:
Returns the number of elements written

bool QASCII::WriteString ( std::string  outputString,
bool  append = false 
)

Writes a string to a file.

Parameters:
outputString String to write
append append if true, overwrite if false (default)
Returns:
Returns true if write operation failed

bool QASCII::WriteLine ( std::string  line,
bool  append = true 
)

Writes a string to a file, terminated with newline.

Parameters:
outputString String to write
append append if true (default), overwrite if false
Returns:
Returns true if write operation failed

bool QASCII::Comment ( std::string  comment  ) 

Writes a comment to a file; begins with '#', terminates with newline.

Parameters:
comment Comment string to write
Returns:
Returns true if write operation failed

string QASCII::ReadComment ( int  commentNumber = 0  ) 

Reads the nth comment from a file. Comments are lines beginning with '#'.

Parameters:
commentNumber Number of comment to read (numbering starts from 0)
Returns:
Returns the comment string, beginning after the "# "

References fFilename.

string QASCII::ReadString ( int  startline = 0,
int  endline = -1 
)

Reads entire file or subset of file into a string.

Parameters:
startline line to start from
Returns:
Returns pointer to string read

References fFilename, and NumberOfLines().

vector< double > QASCII::ReadVector ( int  ColumnNumber,
int  startline = 0,
int  endline = -1 
)

Reads text data from a particular column into a vector.

Parameters:
ColumnNumber Which column to read from. Numbering starts from 0.
startline Line to start from
endline Line to end at

References fFilename, and NumberOfLines().

int QASCII::WriteVector ( std::vector< double >  outputVector,
bool  append = false 
)

Writes data from a vector to a file.

Parameters:
outputVector vector to write
append append if true, overwrite if false (default)
Returns:
Returns the number of elements written

Referenced by WriteQRunData().

int QASCII::WriteVectors ( std::vector< std::vector< double > >  outputVector,
bool  append = false 
)

Writes a vector of vectors, each vector in a new column. Warning: vectors of different lengths can be written to the same file, but they may be read back incorrectly!

Parameters:
outputVector vector of vectors to write
append append if true, overwrite if false (default)
Returns:
Returns the number of elements written

bool QASCII::WriteQTime ( QTime qt,
bool  append = true 
)

Writes an object of type QTime.

Parameters:
qt QTime object to write
append append if true (default), overwrite if false
Returns:
Returns true if write operation failed

References fFilename, QTime::GetFromStartRunNs(), and QTime::GetStartRunUnix().

QTime * QASCII::ReadQTime ( int  startline = 0  ) 

Reads an object of type QTime.

Parameters:
startline Number of line to start from
Returns:
Returns pointer to QTime

References fFilename, QTime::SetFromStartRunNs(), and QTime::SetStartRunUnix().

bool QASCII::WriteQRunData ( QRunData qrd,
bool  append = false 
)

QRunData * QASCII::ReadQRunData ( int  startline = 0,
int  endline = -1 
)

int QASCII::FindLine ( std::string  pattern,
int  startline = 0 
)

Finds a line matching the string pattern.

Parameters:
pattern Pattern to match
startline Number of line to start from
Returns:
Line number of matching line


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

Generated on Tue Nov 16 10:50:04 2010 for CUORE Software by  doxygen 1.5.6