Isis Developer Reference
TextFile.h
Go to the documentation of this file.
1#ifndef TextFile_h
2#define TextFile_h
8/* SPDX-License-Identifier: CC0-1.0 */
9#include <fstream>
10#include <vector>
11
12#include <QString>
13
14namespace Isis {
38 class TextFile {
39
40 protected:
41 std::fstream p_stream;
44 QString p_filename;
50 bool p_GetLine(QString &line, bool chkComment);
51
52 public:
53 // Constructors and destructors
54 TextFile();
55
56 // implied open file
57 TextFile(const QString &filename, const char *openmode = "input",
58 const char *extension = "");
59
60 // implied getFile/putFile
61 TextFile(const char *filename, const char *openmode,
62 std::vector<QString> &lines,
63 const int &maxLinesToReadWrite = 0,
64 const bool skipComments = true);
65 TextFile(const QString &filename,
66 const char *openmode, std::vector<QString> &lines,
67 const int &maxLinesToReadWrite = 0,
68 const bool skipComments = true);
69 TextFile(const char *filename,
70 const char *openmode, QString *lines,
71 const int &maxLinesToReadWrite, const bool skipComments = true);
72 TextFile(const QString &filename,
73 const char *openmode, QString *lines,
74 const int &maxLinesToReadWrite, const bool skipComments = true);
75
76 ~TextFile();
77
78 void Open(const QString &filename, const char *openmode = "input",
79 const char *extension = "");
80 void Open(const char *filename, const char *openmode = "input",
81 const char *extension = "");
82
83 bool OpenChk(bool bailIfNotOpen = false);
84
85 void Rewind();
86 void Close();
87
88 void GetFile(std::vector<QString> &lines,
89 const int &maxLinesToRead = 0,
90 const bool skipComments = true);
91 void GetFile(QString *lines, const int &maxLinesToRead,
92 const bool skipComments = true);
93
94 void PutFile(std::vector<QString> &lines,
95 const int &maxLinesToWrite = 0);
96 void PutFile(const QString *lines, const int &maxLinesToWrite);
97
98 bool GetLine(QString &line, const bool skipComments = true);
99 bool GetLineNoFilter(QString &line);
100
101 bool GetLine(const bool skipComments = true);
102 bool GetLineNoFilter();
103
104 void PutLine(const QString &line);
105 void PutLine(const char *line = "");
106
107 void PutLineComment(const QString &line);
108 void PutLineComment(const char *line = "");
109
110 QString GetComment();
111 QString GetNewLine();
112
113 void SetComment(const char *commentString = "#");
114 void SetNewLine(const char *newLineString = "\n");
115
116 int LineCount(const int &maxLinesToRead = 0);
117 std::streamsize Size();
118 };
119};
120
121#endif
Provides access to sequential ASCII stream I/O.
Definition TextFile.h:38
QString GetComment()
Definition TextFile.cpp:564
bool GetLine(QString &line, const bool skipComments=true)
Gets next line from file.
Definition TextFile.cpp:411
TextFile()
Constructs an empty TextFile object.
Definition TextFile.cpp:22
void GetFile(std::vector< QString > &lines, const int &maxLinesToRead=0, const bool skipComments=true)
Definition TextFile.cpp:334
void Open(const QString &filename, const char *openmode="input", const char *extension="")
Opens a text file.
Definition TextFile.cpp:217
QString p_newLineString
'newline' string used by PutLine and PutLineComment
Definition TextFile.h:47
void SetComment(const char *commentString="#")
Sets the 'comment' string.
Definition TextFile.cpp:577
QString p_commentString
'comment' string used by GetLine and PutLineComment
Definition TextFile.h:45
std::fstream p_stream
File stream handle.
Definition TextFile.h:41
int LineCount(const int &maxLinesToRead=0)
Counts number of lines in file.
Definition TextFile.cpp:607
bool OpenChk(bool bailIfNotOpen=false)
Definition TextFile.cpp:301
int p_openmode
openmode of file: Input, Output, Overwrite, Append
Definition TextFile.h:42
void PutLine(const QString &line)
Writes string to file and appends a 'newline' string.
Definition TextFile.cpp:508
std::streamsize Size()
Counts number of bytes in file.
Definition TextFile.cpp:652
bool GetLineNoFilter()
Gets next NON-COMMENT line from file.
Definition TextFile.cpp:447
~TextFile()
Closes file (if still open). Destroys the TextFile object.
Definition TextFile.cpp:186
void PutFile(std::vector< QString > &lines, const int &maxLinesToWrite=0)
Definition TextFile.cpp:370
void Open(const char *filename, const char *openmode="input", const char *extension="")
void Close()
Closes file. Called automatically by TextFile destructor.
Definition TextFile.cpp:326
void Rewind()
Sets Read / Write pointer to begining of opened file.
Definition TextFile.cpp:317
QString GetNewLine()
Definition TextFile.cpp:582
QString p_filename
FileName of the opened file.
Definition TextFile.h:44
bool p_GetLine(QString &line, bool chkComment)
Gets next line from file.
Definition TextFile.cpp:463
void PutLineComment(const QString &line)
Writes string to file, prepends a 'comment' string and appends a 'newline' string.
Definition TextFile.cpp:549
void SetNewLine(const char *newLineString="\n")
Sets the 'newline' string.
Definition TextFile.cpp:593
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16