Isis 3 Programmer Reference
|
Provides access to sequential ASCII stream I/O. More...
#include <TextFile.h>
Public Member Functions | |
TextFile () | |
Constructs an empty TextFile object. More... | |
TextFile (const QString &filename, const char *openmode="input", const char *extension="") | |
Constructs a TextFile object and opens the specified file (including path). More... | |
TextFile (const char *filename, const char *openmode, std::vector< QString > &lines, const int &maxLinesToReadWrite=0, const bool skipComments=true) | |
Constructs a TextFile object and opens the specified file (including path), reads or writes file, leaves file open for further use of the rest of the methods. More... | |
TextFile (const QString &filename, const char *openmode, std::vector< QString > &lines, const int &maxLinesToReadWrite=0, const bool skipComments=true) | |
Constructs a TextFile object and opens the specified file (including path), reads or writes file, leaves file open for further use of the rest of the methods. More... | |
TextFile (const char *filename, const char *openmode, QString *lines, const int &maxLinesToReadWrite, const bool skipComments=true) | |
Constructs a TextFile object and opens the specified file (including path), reads or writes file, leaves file open for further use of the rest of the methods. More... | |
TextFile (const QString &filename, const char *openmode, QString *lines, const int &maxLinesToReadWrite, const bool skipComments=true) | |
Constructs a TextFile object and opens the specified file (including path), reads or writes file, leaves file open for further use of the rest of the methods. More... | |
~TextFile () | |
Closes file (if still open). Destroys the TextFile object. More... | |
void | Open (const QString &filename, const char *openmode="input", const char *extension="") |
Opens a text file. More... | |
void | Open (const char *filename, const char *openmode="input", const char *extension="") |
bool | OpenChk (bool bailIfNotOpen=false) |
void | Rewind () |
Sets Read / Write pointer to begining of opened file. More... | |
void | Close () |
Closes file. Called automatically by TextFile destructor. More... | |
void | GetFile (std::vector< QString > &lines, const int &maxLinesToRead=0, const bool skipComments=true) |
void | GetFile (QString *lines, const int &maxLinesToRead, const bool skipComments=true) |
void | PutFile (std::vector< QString > &lines, const int &maxLinesToWrite=0) |
void | PutFile (const QString *lines, const int &maxLinesToWrite) |
bool | GetLine (QString &line, const bool skipComments=true) |
Gets next line from file. More... | |
bool | GetLineNoFilter (QString &line) |
Gets next NON-COMMENT line from file. More... | |
bool | GetLine (const bool skipComments=true) |
Gets next line from file. More... | |
bool | GetLineNoFilter () |
Gets next NON-COMMENT line from file. More... | |
void | PutLine (const QString &line) |
Writes string to file and appends a 'newline' string. More... | |
void | PutLine (const char *line="") |
Writes char string to file and appends a 'newline' string. More... | |
void | PutLineComment (const QString &line) |
Writes string to file, prepends a 'comment' string and appends a 'newline' string. More... | |
void | PutLineComment (const char *line="") |
Writes char string to file, prepends a 'comment' string and appends a 'newline' string. More... | |
QString | GetComment () |
QString | GetNewLine () |
void | SetComment (const char *commentString="#") |
Sets the 'comment' string. More... | |
void | SetNewLine (const char *newLineString="\) |
Sets the 'newline' string. More... | |
int | LineCount (const int &maxLinesToRead=0) |
Counts number of lines in file. More... | |
std::streamsize | Size () |
Counts number of bytes in file. More... | |
Protected Member Functions | |
bool | p_GetLine (QString &line, bool chkComment) |
Gets next line from file. More... | |
Protected Attributes | |
std::fstream | p_stream |
File stream handle. More... | |
int | p_openmode |
openmode of file: Input, Output, Overwrite, Append More... | |
QString | p_filename |
FileName of the opened file. More... | |
QString | p_commentString |
'comment' string used by GetLine and PutLineComment More... | |
QString | p_newLineString |
'newline' string used by PutLine and PutLineComment More... | |
Provides access to sequential ASCII stream I/O.
Provides access to sequential ASCII stream I/O. Checks for errors in opening, reading, and writing ASCII files. Can check for 'comment lines' while reading a text file.
2005-02-16 Elizabeth Ribelin - Modified file to support Doxygen documentation
2010-03-30 Mackenzie Boyd - Modified open method append option to create the file if it doesn't exist, changed file existence check to use FileName class.
2011-08-08 Jeannie Backer - Modified unitTest to use $temporary variable instead of /tmp directory
Definition at line 54 of file TextFile.h.
Isis::TextFile::TextFile | ( | ) |
Constructs an empty TextFile object.
Definition at line 38 of file TextFile.cpp.
Isis::TextFile::TextFile | ( | const QString & | filename, |
const char * | openmode = "input" , |
||
const char * | extension = "" |
||
) |
Constructs a TextFile object and opens the specified file (including path).
filename | FileName (including path) to be opened by TextFile object. |
openmode | Open Mode of file opened by TextFile object. InputOpens file for Input: Read Only, Fails if file does not exist OutputOpens file for Output: Read / Write - Creates file, Fails if file exists. OverwriteOpens file for Output: Read / Write - Creates file, Truncates if file exists. AppendOpens file for Append: Read / Write- Creates file, Appends if file exists. Defaults to "input" |
extension | Extension to be added to filename (added only if not already on filename). Defaults to "" |
Definition at line 57 of file TextFile.cpp.
Isis::TextFile::TextFile | ( | const char * | filename, |
const char * | openmode, | ||
std::vector< QString > & | lines, | ||
const int & | maxLinesToReadWrite = 0 , |
||
const bool | skipComments = true |
||
) |
Constructs a TextFile object and opens the specified file (including path), reads or writes file, leaves file open for further use of the rest of the methods.
filename | FileName (including path) to be opened by TextFile object. |
openmode | Open Mode of file opened by TextFile object. InputOpens file for Input: Read Only, Fails if file does not exist OutputOpens file for Output: Read / Write - Creates file, Fails if file exists. OverwriteOpens file for Output: Read / Write - Creates file, Truncates if file exists. AppendOpens file for Append: Read / Write - Creates file, Appends if file exists. Defaults to "input" |
lines | |
maxLinesToReadWrite | Limits the maximum lines read or written; 0=read entire file or write entire vectorDefaults to 0 |
skipComments | Controls whether comments lines are filtered; true=filter, false=return any line read from fileDefaults to true |
Definition at line 125 of file TextFile.cpp.
Isis::TextFile::TextFile | ( | const QString & | filename, |
const char * | openmode, | ||
std::vector< QString > & | lines, | ||
const int & | maxLinesToReadWrite = 0 , |
||
const bool | skipComments = true |
||
) |
Constructs a TextFile object and opens the specified file (including path), reads or writes file, leaves file open for further use of the rest of the methods.
filename | FileName (including path) to be opened by TextFile object. |
openmode | Open Mode of file opened by TextFile object. InputOpens file for Input: Read Only, Fails if file does not exist OutputOpens file for Output: Read / Write - Creates file, Fails if file exists. OverwriteOpens file for Output: Read / Write - Creates file, Truncates if file exists. AppendOpens file for Append: Read / Write - Creates file, Appends if file exists. Defaults to "input" |
lines | IString Vector to fill if reading or put to file if writing |
maxLinesToReadWrite | Limits the maximum lines read or written; 0=read entire file or write entire vectorDefaults to 0 |
skipComments | Controls whether comments lines are filtered; true=filter, false=return any line read from fileDefaults to true |
Definition at line 88 of file TextFile.cpp.
Isis::TextFile::TextFile | ( | const char * | filename, |
const char * | openmode, | ||
QString * | lines, | ||
const int & | maxLinesToReadWrite, | ||
const bool | skipComments = true |
||
) |
Constructs a TextFile object and opens the specified file (including path), reads or writes file, leaves file open for further use of the rest of the methods.
filename | FileName (including path) to be opened by TextFile object. |
openmode | Open Mode of file opened by TextFile object. InputOpens file for Input: Read Only, Fails if file does not exist OutputOpens file for Output: Read / Write - Creates file, Fails if file exists. OverwriteOpens file for Output: Read / Write - Creates file, Truncates if file exists. AppendOpens file for Append: Read / Write - Creates file, Appends if file exists. Defaults to "input" |
lines | |
maxLinesToReadWrite | Limits the maximum lines read or written; 0=read entire file or write entire vectorDefaults to 0 |
skipComments | Controls whether comments lines are filtered; true=filter, false=return any line read from fileDefaults to true |
Definition at line 194 of file TextFile.cpp.
Isis::TextFile::TextFile | ( | const QString & | filename, |
const char * | openmode, | ||
QString * | lines, | ||
const int & | maxLinesToReadWrite, | ||
const bool | skipComments = true |
||
) |
Constructs a TextFile object and opens the specified file (including path), reads or writes file, leaves file open for further use of the rest of the methods.
filename | FileName (including path) to be opened by TextFile object. |
openmode | Open Mode of file opened by TextFile object. InputOpens file for Input: Read Only, Fails if file does not exist OutputOpens file for Output: Read / Write - Creates file, Fails if file exists. OverwriteOpens file for Output: Read / Write - Creates file, Truncates if file exists. AppendOpens file for Append: Read / Write - Creates file, Appends if file exists. Defaults to "input" |
lines | |
maxLinesToReadWrite | Limits the maximum lines read or written; 0=read entire file or write entire vectorDefaults to 0 |
skipComments | Controls whether comments lines are filtered; true=filter, false=return any line read from fileDefaults to true |
Definition at line 156 of file TextFile.cpp.
Isis::TextFile::~TextFile | ( | ) |
Closes file (if still open). Destroys the TextFile object.
Definition at line 202 of file TextFile.cpp.
void Isis::TextFile::Close | ( | ) |
Closes file. Called automatically by TextFile destructor.
Definition at line 342 of file TextFile.cpp.
Referenced by Isis::Pipeline::Run(), and Isis::CisscalFile::~CisscalFile().
bool Isis::TextFile::GetLine | ( | QString & | line, |
const bool | skipComments = true |
||
) |
Gets next line from file.
Returns True if read a line, False if End Of File.
line | Line read from file, with newline removed. |
skipComments | Controls whether comments lines are filtered; true=filter, false=return any line read from fileDefaults to true |
Definition at line 427 of file TextFile.cpp.
Referenced by Isis::Environment::isisVersion(), Isis::UserInterface::loadBatchList(), Isis::ImportPdsTable::loadTable(), and Isis::MosaicMainWindow::openList().
bool Isis::TextFile::GetLine | ( | const bool | skipComments = true | ) |
Gets next line from file.
Returns True if read a line, False if End Of File.
skipComments | Controls whether comments lines are filtered; true=filter, false=return any line read from fileDefaults to true |
Definition at line 440 of file TextFile.cpp.
bool Isis::TextFile::GetLineNoFilter | ( | QString & | line | ) |
Gets next NON-COMMENT line from file.
Returns True if read a line, False if End Of File. See SetComment method.
line | Line read from file, with newline removed. |
Definition at line 453 of file TextFile.cpp.
bool Isis::TextFile::GetLineNoFilter | ( | ) |
Gets next NON-COMMENT line from file.
Returns True if read a line, False if End Of File. See SetComment method.
Definition at line 463 of file TextFile.cpp.
int Isis::TextFile::LineCount | ( | const int & | maxLinesToRead = 0 | ) |
Counts number of lines in file.
maxLinesToRead | Limits lines counted - intended for large files. 0=count all lines. n=count up to and including n lines; if file longer than n lines, returns n+1. Defaults to 0 |
Definition at line 623 of file TextFile.cpp.
Referenced by Isis::UserInterface::loadBatchList().
void Isis::TextFile::Open | ( | const QString & | filename, |
const char * | openmode = "input" , |
||
const char * | extension = "" |
||
) |
Opens a text file.
filename | FileName (including path) to be opened. |
openmode | Open Mode of file to be opened. There are four options, "input", "output", "overwrite", and "append". "input" opens with in fstream option, "output" opens with in, out, and trunc fstream options and verifies the file does not exist, "overwrite" opens with in, out, and trunc fstream options, and "append" opens with in, out, and ate(at end) fstream options, "append" will open with in and out options if the file does not exist. |
extension | Extension to be added to filename (added only if not already on filename). Defaults to "" |
Isis::IException::Programmer | |
Isis::IException::Io | - output file already exists |
Isis::IException::Io | - unable to open file |
Definition at line 233 of file TextFile.cpp.
References _FILEINFO_, Isis::FileName::addExtension(), Isis::IString::DownCase(), Isis::FileName::expanded(), Isis::FileName::fileExists(), and Isis::FileName::toString().
Referenced by Isis::UserInterface::loadBatchList().
|
protected |
Gets next line from file.
Returns True if read a line, False if End Of File.
line | Line read from file, with newline removed. |
chkComment | True=Skip Comment Lines, False=Return All Lines. |
Isis::IException::Io | - error reading text file |
Definition at line 479 of file TextFile.cpp.
References _FILEINFO_.
void Isis::TextFile::PutLine | ( | const QString & | line | ) |
Writes string to file and appends a 'newline' string.
See SetNewLine method.
line | IString to be written to file. Defaults to "" |
Definition at line 524 of file TextFile.cpp.
Referenced by Isis::Pipeline::Run(), and Isis::ImageFileListWidget::saveList().
void Isis::TextFile::PutLine | ( | const char * | line = "" | ) |
Writes char string to file and appends a 'newline' string.
See SetNewLine method.
line | Char string to be written to file.Defaults to "" |
Isis::IException::Io | - error writing text to file |
Isis::IException::Programmer | - input is read only text file, cannot write to file |
Definition at line 538 of file TextFile.cpp.
References _FILEINFO_.
void Isis::TextFile::PutLineComment | ( | const QString & | line | ) |
Writes string to file, prepends a 'comment' string and appends a 'newline' string.
See SetComment method and SetNewLine method.
line | IString to be written to file.Defaults to "" |
Definition at line 565 of file TextFile.cpp.
void Isis::TextFile::PutLineComment | ( | const char * | line = "" | ) |
Writes char string to file, prepends a 'comment' string and appends a 'newline' string.
See SetComment method and SetNewLine method.
line | Char string to be written to file.Defaults to "" |
Definition at line 575 of file TextFile.cpp.
void Isis::TextFile::Rewind | ( | ) |
Sets Read / Write pointer to begining of opened file.
Definition at line 333 of file TextFile.cpp.
void Isis::TextFile::SetComment | ( | const char * | commentString = "#" | ) |
Sets the 'comment' string.
Default = '#' See ReadFilter method. Skips lines that begin with this string. See PutLineComment method. Prepends 'comment' string to output line.
commentString | The string of characters to be used for 'comment' lines. Defaults to "#" |
Definition at line 593 of file TextFile.cpp.
void Isis::TextFile::SetNewLine | ( | const char * | newLineString = "\n" | ) |
Sets the 'newline' string.
Default = '
'. See PutLine and PutLineComment methods. Appends 'newline' string to output line.
newLineString | The string of characters to be used for 'comment' lines. Defaults to "\n" |
Definition at line 609 of file TextFile.cpp.
streamsize Isis::TextFile::Size | ( | ) |
|
protected |
'comment' string used by GetLine and PutLineComment
Definition at line 61 of file TextFile.h.
|
protected |
FileName of the opened file.
Definition at line 60 of file TextFile.h.
Referenced by Isis::CisscalFile::p_GetLine().
|
protected |
'newline' string used by PutLine and PutLineComment
Definition at line 63 of file TextFile.h.
|
protected |
openmode of file: Input, Output, Overwrite, Append
Definition at line 58 of file TextFile.h.
|
protected |
File stream handle.
Definition at line 57 of file TextFile.h.
Referenced by Isis::CisscalFile::p_GetLine().