USGS

Isis 3.0 Object Programmers' Reference

Home

TextFile.h

Go to the documentation of this file.
00001 #ifndef TextFile_h
00002 #define TextFile_h
00003 
00025 #include <fstream>
00026 #include <vector>
00027 
00028 #include <QString>
00029 
00030 namespace Isis {
00054   class TextFile {
00055 
00056     protected:
00057       std::fstream p_stream;           
00058       int     p_openmode;              
00060       QString  p_filename;         
00061       QString  p_commentString;    
00063       QString  p_newLineString;    
00066       bool p_GetLine(QString &line, bool chkComment);
00067 
00068     public:
00069       // Constructors and destructors
00070       TextFile();
00071 
00072       // implied open file
00073       TextFile(const QString &filename, const char *openmode = "input",
00074                const char *extension = "");
00075 
00076       // implied getFile/putFile
00077       TextFile(const   char *filename, const char *openmode,
00078                std::vector<QString> &lines,
00079                const int &maxLinesToReadWrite = 0,
00080                const bool skipComments = true);
00081       TextFile(const QString &filename,
00082                const char *openmode, std::vector<QString> &lines,
00083                const int &maxLinesToReadWrite = 0,
00084                const bool skipComments = true);
00085       TextFile(const   char *filename,
00086                const char *openmode, QString *lines,
00087                const int &maxLinesToReadWrite, const bool skipComments = true);
00088       TextFile(const QString &filename,
00089                const char *openmode, QString *lines,
00090                const int &maxLinesToReadWrite, const bool skipComments = true);
00091 
00092       ~TextFile();
00093 
00094       void Open(const QString &filename, const char *openmode = "input",
00095                 const char *extension = "");
00096       void Open(const char *filename, const char *openmode = "input",
00097                 const char *extension = "");
00098 
00099       bool OpenChk(bool bailIfNotOpen = false);
00100 
00101       void Rewind();
00102       void Close();
00103 
00104       void GetFile(std::vector<QString> &lines, 
00105                    const int &maxLinesToRead = 0, 
00106                    const bool skipComments = true);
00107       void GetFile(QString *lines, const int &maxLinesToRead, 
00108                    const bool skipComments = true);
00109 
00110       void PutFile(std::vector<QString> &lines, 
00111                    const int &maxLinesToWrite = 0);
00112       void PutFile(const QString *lines, const int &maxLinesToWrite);
00113 
00114       bool GetLine(QString &line, const bool skipComments = true);
00115       bool GetLineNoFilter(QString &line);
00116 
00117       bool GetLine(const bool skipComments = true);
00118       bool GetLineNoFilter();
00119 
00120       void PutLine(const QString &line);
00121       void PutLine(const char *line = "");
00122 
00123       void PutLineComment(const QString &line);
00124       void PutLineComment(const char *line = "");
00125 
00126       QString GetComment();
00127       QString GetNewLine();
00128 
00129       void SetComment(const char *commentString = "#");
00130       void SetNewLine(const char *newLineString = "\n");
00131 
00132       int LineCount(const int &maxLinesToRead = 0);
00133       std::streamsize Size();
00134   };
00135 };
00136 
00137 #endif