txt::File Class Reference
A simple container representing a text file which enables iterating over the lines in the file. Various flags can be used to enable whitespace compression, blank link skipping, and comment removal. Flag names and descriptions are listed below.
One can easily create a large string representation of a file suitable for use with the boost regular expression library, with code similar to the following:
string targetString; File fin("test.dat",File::include_newlines); for ( File::iterator itr = fin.begin(); itr != fin.end(); ++itr ) targetString += *itr;
Note that comment removal and whitespace compression can be done cheaply with the file class, thus making the required regular expressions simpler and more efficient.
File Class Flag List
- skip_blank_lines: Skip blank lines (including their newline chararacter).
- compress_whitespace: Eliminate leading and trailing whitespace, and compress all other whitespace to one character. Helps simplify regular expressions which operate on the file.
- include_newlines: Include a newline char at end of each line, otherwise newlines are excluded.
- remove_comments: Eliminate line comments which are indicated with a line comment string as given with the addCommentString() member function.
Public Types
Public Methods
- File (const std::string &filename, int flags=0)
- setFlags (int flags)
- addCommentString (const std::string &commentString)
- getFlags () const
- getFilename () const
- begin () const
- end () const
Static Public Attributes
- skip_blank_lines = 1
- include_newlines = 1 << 1
- compress_whitespace = 1 << 2
- remove_comments = 1 << 3