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. | |
| QTime * | ReadQTime (int startline=0) |
| Reads an object of type QTime. | |
| bool | WriteQRunData (QRunData *qrd, bool append=false) |
| Writes an object of type QRunData. | |
| QRunData * | ReadQRunData (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. | |
| QASCII::QASCII | ( | std::string | filename | ) |
normal constructor
| filename | name of file to be opened |
| int QASCII::NumberOfLines | ( | bool | ExcludeComments = true |
) |
Returns the number of lines in the file, excluding comments by default.
| ExcludeComments | if true, comments are excluded from count, else they are counted as lines |
| QVector * QASCII::ReadQVector | ( | int | ColumnNumber, | |
| int | startline = 0, |
|||
| int | endline = -1 | |||
| ) |
Reads text data from a particular column into QVector.
| ColumnNumber | Which column to read from. Numbering starts at 0. | |
| startline | line to start from | |
| endline | line to end at |
| int QASCII::WriteQVector | ( | QVector | outputVector, | |
| bool | append = false | |||
| ) |
| 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!
| outputVector | vector of QVectors to write | |
| append | append if true, overwrite if false (default) |
| bool QASCII::WriteString | ( | std::string | outputString, | |
| bool | append = false | |||
| ) |
Writes a string to a file.
| outputString | String to write | |
| append | append if true, overwrite if false (default) |
| bool QASCII::WriteLine | ( | std::string | line, | |
| bool | append = true | |||
| ) |
Writes a string to a file, terminated with newline.
| outputString | String to write | |
| append | append if true (default), overwrite if false |
| bool QASCII::Comment | ( | std::string | comment | ) |
Writes a comment to a file; begins with '#', terminates with newline.
| comment | Comment string to write |
| string QASCII::ReadComment | ( | int | commentNumber = 0 |
) |
Reads the nth comment from a file. Comments are lines beginning with '#'.
| commentNumber | Number of comment to read (numbering starts from 0) |
| string QASCII::ReadString | ( | int | startline = 0, |
|
| int | endline = -1 | |||
| ) |
Reads entire file or subset of file into a string.
| startline | line to start from |
| vector< double > QASCII::ReadVector | ( | int | ColumnNumber, | |
| int | startline = 0, |
|||
| int | endline = -1 | |||
| ) |
Reads text data from a particular column into a vector.
| ColumnNumber | Which column to read from. Numbering starts from 0. | |
| startline | Line to start from | |
| endline | Line to end at |
| int QASCII::WriteVector | ( | std::vector< double > | outputVector, | |
| bool | append = false | |||
| ) |
Writes data from a vector to a file.
| outputVector | vector to write | |
| append | append if true, overwrite if false (default) |
| 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!
| outputVector | vector of vectors to write | |
| append | append if true, overwrite if false (default) |
| bool QASCII::WriteQTime | ( | QTime * | qt, | |
| bool | append = true | |||
| ) |
| QTime * QASCII::ReadQTime | ( | int | startline = 0 |
) |
| 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.
| pattern | Pattern to match | |
| startline | Number of line to start from |
1.5.1