Isis 3 Programmer Reference
TextFile.h
Go to the documentation of this file.
1 #ifndef TextFile_h
2 #define TextFile_h
3 
25 #include <fstream>
26 #include <vector>
27 
28 #include <QString>
29 
30 namespace Isis {
54  class TextFile {
55 
56  protected:
57  std::fstream p_stream;
58  int p_openmode;
60  QString p_filename;
61  QString p_commentString;
63  QString p_newLineString;
66  bool p_GetLine(QString &line, bool chkComment);
67 
68  public:
69  // Constructors and destructors
70  TextFile();
71 
72  // implied open file
73  TextFile(const QString &filename, const char *openmode = "input",
74  const char *extension = "");
75 
76  // implied getFile/putFile
77  TextFile(const char *filename, const char *openmode,
78  std::vector<QString> &lines,
79  const int &maxLinesToReadWrite = 0,
80  const bool skipComments = true);
81  TextFile(const QString &filename,
82  const char *openmode, std::vector<QString> &lines,
83  const int &maxLinesToReadWrite = 0,
84  const bool skipComments = true);
85  TextFile(const char *filename,
86  const char *openmode, QString *lines,
87  const int &maxLinesToReadWrite, const bool skipComments = true);
88  TextFile(const QString &filename,
89  const char *openmode, QString *lines,
90  const int &maxLinesToReadWrite, const bool skipComments = true);
91 
92  ~TextFile();
93 
94  void Open(const QString &filename, const char *openmode = "input",
95  const char *extension = "");
96  void Open(const char *filename, const char *openmode = "input",
97  const char *extension = "");
98 
99  bool OpenChk(bool bailIfNotOpen = false);
100 
101  void Rewind();
102  void Close();
103 
104  void GetFile(std::vector<QString> &lines,
105  const int &maxLinesToRead = 0,
106  const bool skipComments = true);
107  void GetFile(QString *lines, const int &maxLinesToRead,
108  const bool skipComments = true);
109 
110  void PutFile(std::vector<QString> &lines,
111  const int &maxLinesToWrite = 0);
112  void PutFile(const QString *lines, const int &maxLinesToWrite);
113 
114  bool GetLine(QString &line, const bool skipComments = true);
115  bool GetLineNoFilter(QString &line);
116 
117  bool GetLine(const bool skipComments = true);
118  bool GetLineNoFilter();
119 
120  void PutLine(const QString &line);
121  void PutLine(const char *line = "");
122 
123  void PutLineComment(const QString &line);
124  void PutLineComment(const char *line = "");
125 
126  QString GetComment();
127  QString GetNewLine();
128 
129  void SetComment(const char *commentString = "#");
130  void SetNewLine(const char *newLineString = "\n");
131 
132  int LineCount(const int &maxLinesToRead = 0);
133  std::streamsize Size();
134  };
135 };
136 
137 #endif
QString p_filename
FileName of the opened file.
Definition: TextFile.h:60
QString p_commentString
&#39;comment&#39; string used by GetLine and PutLineComment
Definition: TextFile.h:61
std::streamsize Size()
Counts number of bytes in file.
Definition: TextFile.cpp:668
void SetComment(const char *commentString="#")
Sets the &#39;comment&#39; string.
Definition: TextFile.cpp:593
void Open(const QString &filename, const char *openmode="input", const char *extension="")
Opens a text file.
Definition: TextFile.cpp:233
int p_openmode
openmode of file: Input, Output, Overwrite, Append
Definition: TextFile.h:58
void Rewind()
Sets Read / Write pointer to begining of opened file.
Definition: TextFile.cpp:333
void Close()
Closes file. Called automatically by TextFile destructor.
Definition: TextFile.cpp:342
TextFile()
Constructs an empty TextFile object.
Definition: TextFile.cpp:38
bool GetLineNoFilter()
Gets next NON-COMMENT line from file.
Definition: TextFile.cpp:463
void SetNewLine(const char *newLineString="\)
Sets the &#39;newline&#39; string.
Definition: TextFile.cpp:609
QString p_newLineString
&#39;newline&#39; string used by PutLine and PutLineComment
Definition: TextFile.h:63
int LineCount(const int &maxLinesToRead=0)
Counts number of lines in file.
Definition: TextFile.cpp:623
bool GetLine(QString &line, const bool skipComments=true)
Gets next line from file.
Definition: TextFile.cpp:427
Provides access to sequential ASCII stream I/O.
Definition: TextFile.h:54
~TextFile()
Closes file (if still open). Destroys the TextFile object.
Definition: TextFile.cpp:202
void PutLine(const QString &line)
Writes string to file and appends a &#39;newline&#39; string.
Definition: TextFile.cpp:524
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void PutLineComment(const QString &line)
Writes string to file, prepends a &#39;comment&#39; string and appends a &#39;newline&#39; string.
Definition: TextFile.cpp:565
bool p_GetLine(QString &line, bool chkComment)
Gets next line from file.
Definition: TextFile.cpp:479
std::fstream p_stream
File stream handle.
Definition: TextFile.h:57