Diana Software
Public Member Functions | Private Attributes | List of all members
QASCII Class Reference

Class for reading and writing ascii text files. More...

Public Member Functions

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

Private Attributes

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

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.

Definition at line 22 of file QASCII.hh.

Constructor & Destructor Documentation

◆ QASCII() [1/3]

QASCII::QASCII ( )

default constructor

Definition at line 19 of file QASCII.cc.

◆ QASCII() [2/3]

QASCII::QASCII ( const QASCII orig)

copy constructor

Parameters
origoriginal QASCII

Definition at line 25 of file QASCII.cc.

References fFilename.

◆ QASCII() [3/3]

QASCII::QASCII ( std::string  filename)

normal constructor

Parameters
filenamename of file to be opened

◆ ~QASCII()

QASCII::~QASCII ( )
virtual

destructor

Definition at line 36 of file QASCII.cc.

Member Function Documentation

◆ Comment()

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

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

Parameters
commentComment string to write
Returns
Returns true if write operation failed

Definition at line 221 of file QASCII.cc.

Referenced by LASCIIGlobalWriter::SetBool(), LASCIIGlobalWriter::SetDouble(), LASCIIGlobalWriter::SetFloat(), LASCIIGlobalWriter::SetInt(), LASCIIGlobalWriter::SetQMatrix(), LASCIIGlobalWriter::SetQObject(), LASCIIGlobalWriter::SetQTime(), LASCIIGlobalWriter::SetQVector(), LASCIIGlobalWriter::SetQVectorC(), and LASCIIGlobalWriter::SetString().

◆ DeleteFile()

void QASCII::DeleteFile ( )
inline

Deletes file from disk.

Definition at line 179 of file QASCII.hh.

References fFilename.

◆ Exists()

bool QASCII::Exists ( )

Returns true if the file exists and can be opened.

Definition at line 38 of file QASCII.cc.

Referenced by LASCIIGlobalWriter::Open(), and LASCIIGlobalReader::Open().

◆ FindLine()

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

Finds a line matching the string pattern.

Parameters
patternPattern to match
startlineNumber of line to start from
Returns
Line number of matching line

Definition at line 441 of file QASCII.cc.

Referenced by LASCIIGlobalReader::GetBool(), LASCIIGlobalReader::GetDouble(), LASCIIGlobalReader::GetFloat(), LASCIIGlobalReader::GetInt(), LASCIIGlobalReader::GetQObject(), and LASCIIGlobalReader::GetString().

◆ NumberOfLines()

int QASCII::NumberOfLines ( bool  ExcludeComments = true)

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

Parameters
ExcludeCommentsif true, comments are excluded from count, else they are counted as lines

Definition at line 48 of file QASCII.cc.

◆ ReadComment()

string QASCII::ReadComment ( int  commentNumber = 0)

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

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

Definition at line 232 of file QASCII.cc.

◆ ReadQTime()

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

Reads an object of type QTime.

Parameters
startlineNumber of line to start from
Returns
Returns pointer to QTime

Definition at line 488 of file QASCII.cc.

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

Referenced by LASCIIGlobalReader::GetQObject().

◆ ReadQVector() [1/2]

QVector * QASCII::ReadQVector ( )

Reads a text file into a QVector. Text file should contain a list of numbers.

Definition at line 64 of file QASCII.cc.

References vec.

Referenced by LASCIIGlobalReader::GetQObject().

◆ ReadQVector() [2/2]

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

Reads text data from a particular column into QVector.

Parameters
ColumnNumberWhich column to read from. Numbering starts at 0.
startlineline to start from
endlineline to end at

Definition at line 92 of file QASCII.cc.

References vec.

◆ ReadString()

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

Reads entire file or subset of file into a string.

Parameters
startlineline to start from
Returns
Returns pointer to string read

Definition at line 260 of file QASCII.cc.

Referenced by LASCIIGlobalReader::GetBool(), LASCIIGlobalReader::GetDouble(), LASCIIGlobalReader::GetFloat(), LASCIIGlobalReader::GetInt(), LASCIIGlobalReader::GetQObject(), and LASCIIGlobalReader::GetString().

◆ ReadVector() [1/2]

vector< double > QASCII::ReadVector ( )

Reads a text file into a vector. Text file should contain a list of numbers.

Definition at line 294 of file QASCII.cc.

References vec.

◆ ReadVector() [2/2]

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

Reads text data from a particular column into a vector.

Parameters
ColumnNumberWhich column to read from. Numbering starts from 0.
startlineLine to start from
endlineLine to end at

Definition at line 319 of file QASCII.cc.

References vec.

◆ WriteLine()

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

Writes a string to a file, terminated with newline.

Parameters
outputStringString to write
appendappend if true (default), overwrite if false
Returns
Returns true if write operation failed

Definition at line 209 of file QASCII.cc.

Referenced by LASCIIGlobalWriter::SetBool(), LASCIIGlobalWriter::SetDouble(), LASCIIGlobalWriter::SetFloat(), LASCIIGlobalWriter::SetInt(), and LASCIIGlobalWriter::SetString().

◆ WriteQTime()

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

Writes an object of type QTime.

Parameters
qtQTime object to write
appendappend if true (default), overwrite if false
Returns
Returns true if write operation failed

Definition at line 469 of file QASCII.cc.

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

Referenced by LASCIIGlobalWriter::SetQTime().

◆ WriteQVector()

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

Writes data from a QVector to a file.

Parameters
outputVectorQVector to write
appendappend if true, overwrite if false (default)
Returns
Returns the number of elements written

Definition at line 138 of file QASCII.cc.

Referenced by LASCIIGlobalWriter::SetQVector().

◆ WriteQVectors()

int QASCII::WriteQVectors ( std::vector< Diana::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
outputVectorvector of QVectors to write
appendappend if true, overwrite if false (default)
Returns
Returns the number of elements written

Definition at line 159 of file QASCII.cc.

Referenced by LASCIIGlobalWriter::SetQMatrix(), and LASCIIGlobalWriter::SetQVectorC().

◆ WriteString()

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

Writes a string to a file.

Parameters
outputStringString to write
appendappend if true, overwrite if false (default)
Returns
Returns true if write operation failed

Definition at line 197 of file QASCII.cc.

Referenced by LASCIIGlobalWriter::Open(), and LASCIIGlobalWriter::SetQObject().

◆ WriteVector() [1/2]

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

Writes data from a vector to a file.

Parameters
outputVectorvector to write
appendappend if true, overwrite if false (default)
Returns
Returns the number of elements written

◆ WriteVector() [2/2]

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

◆ WriteVectors()

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
outputVectorvector of vectors to write
appendappend if true, overwrite if false (default)
Returns
Returns the number of elements written

Definition at line 402 of file QASCII.cc.

Member Data Documentation

◆ fFilename

std::string QASCII::fFilename
private

Name of the file on disk.

Definition at line 193 of file QASCII.hh.

Referenced by DeleteFile(), and QASCII().


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