|
Isis 3.0 Object Programmers' Reference |
Home |
#include <TextFile.h>
Inheritance diagram for Isis::TextFile:


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.
For internal use only.
Definition at line 47 of file TextFile.h.
Public Member Functions | |
| TextFile () | |
| Constructs an empty TextFile object. | |
| TextFile (const std::string &filename, const char *openmode="input", const char *extension="") | |
| Constructs a TextFile object and opens the specified file (including path). | |
| TextFile (const char *filename, const char *openmode, std::vector< std::string > &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. | |
| TextFile (const std::string &filename, const char *openmode, std::vector< std::string > &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. | |
| TextFile (const char *filename, const char *openmode, std::string *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. | |
| TextFile (const std::string &filename, const char *openmode, std::string *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. | |
| ~TextFile () | |
| Closes file (if still open). Destroys the TextFile object. | |
| void | Open (const std::string &filename, const char *openmode="input", const char *extension="") |
| Opens a text file. | |
| 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. | |
| void | Close () |
| Closes file. Called automatically by TextFile destructor. | |
| void | GetFile (std::vector< std::string > &lines, const int &maxLinesToRead=0, const bool skipComments=true) |
| void | GetFile (std::string *lines, const int &maxLinesToRead, const bool skipComments=true) |
| void | PutFile (std::vector< std::string > &lines, const int &maxLinesToWrite=0) |
| void | PutFile (const std::string *lines, const int &maxLinesToWrite) |
| bool | GetLine (std::string &line, const bool skipComments=true) |
| Gets next line from file. | |
| bool | GetLineNoFilter (std::string &line) |
| Gets next NON-COMMENT line from file. | |
| bool | GetLine (const bool skipComments=true) |
| Gets next line from file. | |
| bool | GetLineNoFilter () |
| Gets next NON-COMMENT line from file. | |
| void | PutLine (const std::string &line) |
| Writes string to file and appends a 'newline' string. | |
| void | PutLine (const char *line="") |
| Writes char string to file and appends a 'newline' string. | |
| void | PutLineComment (const std::string &line) |
| Writes string to file, prepends a 'comment' string and appends a 'newline' string. | |
| void | PutLineComment (const char *line="") |
| Writes char string to file, prepends a 'comment' string and appends a 'newline' string. | |
| std::string | GetComment () |
| std::string | GetNewLine () |
| void | SetComment (const char *commentString="#") |
| Sets the 'comment' string. | |
| void | SetNewLine (const char *newLineString="\n") |
| Sets the 'newline' string. | |
| int | LineCount (const int &maxLinesToRead=0) |
| Counts number of lines in file. | |
| std::streamsize | Size () |
| Counts number of bytes in file. | |
Protected Member Functions | |
| bool | p_GetLine (std::string &line, bool chkComment) |
| Gets next line from file. | |
Protected Attributes | |
| std::fstream | p_stream |
| File stream handle. | |
| int | p_openmode |
| openmode of file: Input, Output, Overwrite, Append | |
| std::string | p_filename |
| Filename of the opened file. | |
| std::string | p_commentString |
| 'comment' string used by GetLine and PutLineComment | |
| std::string | p_newLineString |
| 'newline' string used by PutLine and PutLineComment | |
| Isis::TextFile::TextFile | ( | ) |
Constructs an empty TextFile object.
Definition at line 34 of file TextFile.cpp.
Referenced by TextFile().
| Isis::TextFile::TextFile | ( | const std::string & | 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 53 of file TextFile.cpp.
References Open(), SetComment(), and SetNewLine().
| Isis::TextFile::TextFile | ( | const char * | filename, | |
| const char * | openmode, | |||
| std::vector< std::string > & | 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 121 of file TextFile.cpp.
References TextFile().
| Isis::TextFile::TextFile | ( | const std::string & | filename, | |
| const char * | openmode, | |||
| std::vector< std::string > & | 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 84 of file TextFile.cpp.
References GetFile(), Open(), p_openmode, PutFile(), SetComment(), and SetNewLine().
| Isis::TextFile::TextFile | ( | const char * | filename, | |
| const char * | openmode, | |||
| std::string * | 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 191 of file TextFile.cpp.
References TextFile().
| Isis::TextFile::TextFile | ( | const std::string & | filename, | |
| const char * | openmode, | |||
| std::string * | 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 153 of file TextFile.cpp.
References GetFile(), Open(), p_openmode, PutFile(), SetComment(), and SetNewLine().
| Isis::TextFile::~TextFile | ( | ) |
Closes file (if still open). Destroys the TextFile object.
Definition at line 200 of file TextFile.cpp.
References Close().
| void Isis::TextFile::Close | ( | ) |
Closes file. Called automatically by TextFile destructor.
Definition at line 319 of file TextFile.cpp.
References p_stream.
Referenced by Isis::Pipeline::Run(), Isis::CisscalFile::~CisscalFile(), and ~TextFile().
| 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 409 of file TextFile.cpp.
References line, and p_GetLine().
| bool Isis::TextFile::GetLine | ( | std::string & | 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 396 of file TextFile.cpp.
References p_GetLine().
Referenced by GetFile(), and Isis::UserInterface::LoadBatchList().
| 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 432 of file TextFile.cpp.
References line, and p_GetLine().
| bool Isis::TextFile::GetLineNoFilter | ( | std::string & | 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 422 of file TextFile.cpp.
References p_GetLine().
| 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 591 of file TextFile.cpp.
References OpenChk(), and p_stream.
Referenced by Isis::UserInterface::LoadBatchList().
| void Isis::TextFile::Open | ( | const std::string & | 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. InputOpens file for Input: Read Only OutputOpens file for Output: Read / Write - Truncates if file exists. AppendOpens file for Append: Read / Write - Appends if file exists.Defaults to "input" | |
| 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 224 of file TextFile.cpp.
References _FILEINFO_, Isis::Filename::AddExtension(), Isis::Filename::Expanded(), in, Isis::iException::Message(), p_filename, p_openmode, and p_stream.
Referenced by Isis::UserInterface::LoadBatchList(), and TextFile().
| bool Isis::TextFile::p_GetLine | ( | std::string & | line, | |
| bool | chkComment | |||
| ) | [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 448 of file TextFile.cpp.
References _FILEINFO_, Isis::iException::Message(), OpenChk(), p_commentString, p_filename, and p_stream.
Referenced by GetLine(), and GetLineNoFilter().
| 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 504 of file TextFile.cpp.
References _FILEINFO_, Isis::iException::Message(), OpenChk(), p_filename, p_newLineString, p_openmode, and p_stream.
| void Isis::TextFile::PutLine | ( | const std::string & | 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 490 of file TextFile.cpp.
Referenced by PutFile(), PutLineComment(), and Isis::Pipeline::Run().
| 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 543 of file TextFile.cpp.
References p_commentString, and PutLine().
| void Isis::TextFile::PutLineComment | ( | const std::string & | 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 533 of file TextFile.cpp.
References p_commentString, and PutLine().
| void Isis::TextFile::Rewind | ( | ) |
| 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 561 of file TextFile.cpp.
References p_commentString.
Referenced by TextFile().
| 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 577 of file TextFile.cpp.
References p_newLineString.
Referenced by TextFile().
| streamsize Isis::TextFile::Size | ( | ) |
std::string Isis::TextFile::p_commentString [protected] |
'comment' string used by GetLine and PutLineComment
Definition at line 54 of file TextFile.h.
Referenced by GetComment(), p_GetLine(), PutLineComment(), and SetComment().
std::string Isis::TextFile::p_filename [protected] |
Filename of the opened file.
Definition at line 53 of file TextFile.h.
Referenced by Open(), OpenChk(), Isis::CisscalFile::p_GetLine(), p_GetLine(), and PutLine().
std::string Isis::TextFile::p_newLineString [protected] |
'newline' string used by PutLine and PutLineComment
Definition at line 56 of file TextFile.h.
Referenced by GetNewLine(), PutLine(), and SetNewLine().
int Isis::TextFile::p_openmode [protected] |
openmode of file: Input, Output, Overwrite, Append
Definition at line 51 of file TextFile.h.
Referenced by Open(), PutLine(), and TextFile().
std::fstream Isis::TextFile::p_stream [protected] |
File stream handle.
Definition at line 50 of file TextFile.h.
Referenced by Close(), LineCount(), Open(), OpenChk(), Isis::CisscalFile::p_GetLine(), p_GetLine(), PutLine(), Rewind(), and Size().