Diana Software
QASCII.hh
Go to the documentation of this file.
1 
12 #ifndef __QASCII_HH_
13 #define __QASCII_HH_
14 
15 #include <string>
16 #include <vector>
17 #include "QVector.hh"
18 #include "QTime.hh"
19 
20 
21 
22 class QASCII {
23  public:
27  QASCII();
28 
33  QASCII(const QASCII& orig);
34 
39  QASCII(std::string filename);
40 
44  virtual ~QASCII();
45 
49  bool Exists();
50 
56  int NumberOfLines(bool ExcludeComments=true);
57 
62  Diana::QVector* ReadQVector();
63 
70  Diana::QVector* ReadQVector(int ColumnNumber, int startline=0, int endline=-1);
71 
78  int WriteQVector(Diana::QVector outputVector, bool append=false);
79 
88  int WriteQVectors(std::vector<Diana::QVector> outputVector, bool append=false);
89 
96  bool WriteString(std::string outputString, bool append=false);
97 
104  bool WriteLine(std::string line, bool append=true);
105 
111  bool Comment(std::string comment);
112 
118  std::string ReadComment(int commentNumber=0);
119 
125  std::string ReadString(int startline = 0, int endline = -1);
126 
131  std::vector<double> ReadVector();
132 
139  std::vector<double> ReadVector(int ColumnNumber, int startline=0, int endline=-1);
140 
147  int WriteVector(std::vector<double> outputVector, bool append=false);
148  int WriteVector(std::vector<int> outputVector, bool append=false);
149 
158  int WriteVectors(std::vector<std::vector<double> > outputVector, bool append=false);
159 
166  bool WriteQTime(Diana::QTime* qt, bool append=true);
167 
173  Diana::QTime* ReadQTime(int startline=0);
174 
175 
179  void DeleteFile(){ remove(fFilename.c_str()); }
180 
187  int FindLine(std::string pattern, int startline=0);
188 
189 
190 
191  private:
193  std::string fFilename;
194 
195 };
196 
197 
198 
199 
200 #endif
Class for reading and writing ascii text files.
Definition: QASCII.hh:22
std::vector< double > ReadVector()
Reads a text file into a vector. Text file should contain a list of numbers.
Definition: QASCII.cc:294
int WriteVector(std::vector< int > outputVector, bool append=false)
int NumberOfLines(bool ExcludeComments=true)
Returns the number of lines in the file, excluding comments by default.
Definition: QASCII.cc:48
QASCII(std::string filename)
normal constructor
bool Exists()
Returns true if the file exists and can be opened.
Definition: QASCII.cc:38
bool WriteLine(std::string line, bool append=true)
Writes a string to a file, terminated with newline.
Definition: QASCII.cc:209
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...
Definition: QASCII.cc:159
std::string ReadString(int startline=0, int endline=-1)
Reads entire file or subset of file into a string.
Definition: QASCII.cc:260
bool WriteQTime(Diana::QTime *qt, bool append=true)
Writes an object of type QTime.
Definition: QASCII.cc:469
bool Comment(std::string comment)
Writes a comment to a file; begins with '#', terminates with newline.
Definition: QASCII.cc:221
QASCII()
default constructor
Definition: QASCII.cc:19
std::string fFilename
Name of the file on disk.
Definition: QASCII.hh:193
virtual ~QASCII()
destructor
Definition: QASCII.cc:36
bool WriteString(std::string outputString, bool append=false)
Writes a string to a file.
Definition: QASCII.cc:197
int WriteQVector(Diana::QVector outputVector, bool append=false)
Writes data from a QVector to a file.
Definition: QASCII.cc:138
int FindLine(std::string pattern, int startline=0)
Finds a line matching the string pattern.
Definition: QASCII.cc:441
Diana::QVector * ReadQVector()
Reads a text file into a QVector. Text file should contain a list of numbers.
Definition: QASCII.cc:64
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...
Definition: QASCII.cc:402
std::string ReadComment(int commentNumber=0)
Reads the nth comment from a file. Comments are lines beginning with '#'.
Definition: QASCII.cc:232
void DeleteFile()
Deletes file from disk.
Definition: QASCII.hh:179
Diana::QTime * ReadQTime(int startline=0)
Reads an object of type QTime.
Definition: QASCII.cc:488
int WriteVector(std::vector< double > outputVector, bool append=false)
Writes data from a vector to a file.