STORMM Source Documentation
|
Structure for translating a text file into a compact, rapidly parsable vector of characters in CPU RAM. The struct contains two nested struct definitions, for a Reader and a Writer. Private objects of these structs can then be accessed with eponymous data() getter functions, returning the appropriate kind of access depending on the const-ness of the TextFile object itself. More...
#include <textfile.h>
Public Member Functions | |
~TextFile ()=default | |
Default destructor. | |
std::string | getFileName () const |
Get the name of the original file. | |
int | getLineCount () const |
Get the line count of a text file after converting it to a character vector in memory. | |
int | getLineLimits (int index) const |
Get one of the line limits of a text file converted to a character vector in memory. | |
int | getLineLength (int index) const |
Get the length of a line. A bounds check will be applied to the line index number. | |
int | getLongestLineLength () const |
Get the length of the longest line in the file. | |
size_t | getTextSize () const |
Get the number of text characters in the object's buffer (this will not count implicit carriage returns between lines). | |
char | getChar (int index) const |
Get one character of a text file after converting it to a character vector in memory. | |
std::string | getLineAsString (int line_index) const |
Get a line from the file as a string. | |
const char * | getTextPointer (int index) const |
Get a char pointer to a specific index in the object. | |
const char * | getLinePointer (int line_index) const |
Get a char pointer to a specific line in the object. | |
const TextFileReader | data () const |
Get an abstract of a text file's CPU-RAM representation, for ease of use. | |
std::string | extractString (int line_number, int start_pos=0, int string_length=-1) const |
Extract a string based on a line number, starting position, and length. | |
char4 | extractChar4 (int line_number, int start_pos, int string_length) const |
Extract a char4 tuple based on a line number, starting position, and length. | |
std::string | toString (TextEnds line_endings=TextEnds::NEWLINE) const |
Convert all content to a string, with the option of making line endings carriage returns or simple spaces (fused line endings, which could create combined words out of the last word on one line and the first word on another, are not accepted). | |
TextFile () | |
Constructor for taking an ascii file or a very long, formatted string and transforming it into a std::vector of characters with line limits recorded. | |
TextFile (const std::string &file_name, TextOrigin source=TextOrigin::DISK, const std::string &content=std::string(""), const std::string &caller=std::string("")) | |
TextFile (const char *content, const size_t length, const std::string &caller=std::string("")) | |
TextFile (const TextFile &original)=default | |
The default copy and move constructors as well as assignment operators are acceptable. | |
TextFile (TextFile &&original)=default | |
TextFile & | operator= (const TextFile &other)=default |
TextFile & | operator= (TextFile &&other)=default |
void | write (std::ofstream *foutp) const |
Write the contents of the object to disk. | |
void | write (const std::string &new_filename, PrintSituation expectation=PrintSituation::OPEN_NEW) const |
void | write (PrintSituation expectation=PrintSituation::OPEN_NEW) const |
Structure for translating a text file into a compact, rapidly parsable vector of characters in CPU RAM. The struct contains two nested struct definitions, for a Reader and a Writer. Private objects of these structs can then be accessed with eponymous data() getter functions, returning the appropriate kind of access depending on the const-ness of the TextFile object itself.
stormm::parse::TextFile::TextFile | ( | ) |
Constructor for taking an ascii file or a very long, formatted string and transforming it into a std::vector of characters with line limits recorded.
Overloaded:
file_name | Name of the input file |
source | Origin of the text–disk or RAM |
content | Content for the TextFile, and perhaps later an ASCII text file, to hold |
caller | (Optional) name of the calling function |
char4 stormm::parse::TextFile::extractChar4 | ( | int | line_number, |
int | start_pos, | ||
int | string_length ) const |
Extract a char4 tuple based on a line number, starting position, and length.
line_number | The line number where the text shall be found |
start_pos | Starting position on the line to begin reading (defaults to the start of the line) |
string_length | Length of the string to extract. The default value of 4 will try to read four characters, but shorter values will leave blank space at the end of the tuple. |
std::string stormm::parse::TextFile::extractString | ( | int | line_number, |
int | start_pos = 0, | ||
int | string_length = -1 ) const |
Extract a string based on a line number, starting position, and length.
line_number | The line number where the text shall be found |
start_pos | Starting position on the line to begin reading (defaults to the start of the line) |
string_length | Length of the string to extract. A value of -1 indicates that reading shall continue until the end of the line. |
char stormm::parse::TextFile::getChar | ( | int | index | ) | const |
Get one character of a text file after converting it to a character vector in memory.
index | The character index, as ascertained by line limits and some offset |
std::string stormm::parse::TextFile::getLineAsString | ( | int | line_index | ) | const |
Get a line from the file as a string.
line_index | The line of interest, indexing starting from zero |
int stormm::parse::TextFile::getLineLength | ( | int | index | ) | const |
Get the length of a line. A bounds check will be applied to the line index number.
index | The line index. The array of limits contains one more indices than the text file has lines, to allow the end of the last line to be determined. |
int stormm::parse::TextFile::getLineLimits | ( | int | index | ) | const |
Get one of the line limits of a text file converted to a character vector in memory.
index | The line index. The array of limits contains one more indices than the text file has lines, to allow the end of the last line to be determined. |
const char * stormm::parse::TextFile::getLinePointer | ( | int | line_index | ) | const |
Get a char pointer to a specific line in the object.
line_index | The line of interest, indexing starting from zero |
const char * stormm::parse::TextFile::getTextPointer | ( | int | index | ) | const |
Get a char pointer to a specific index in the object.
index | The character index, as ascertained by line limits and some offset |
std::string stormm::parse::TextFile::toString | ( | TextEnds | line_endings = TextEnds::NEWLINE | ) | const |
Convert all content to a string, with the option of making line endings carriage returns or simple spaces (fused line endings, which could create combined words out of the last word on one line and the first word on another, are not accepted).
line_endings | Specify whether to insert newlines or white space between lines |
void stormm::parse::TextFile::write | ( | std::ofstream * | foutp | ) | const |
Write the contents of the object to disk.
Overloaded:
foutp | Open output stream |
new_filename | Name of a distinct file to write |
expectation | Expected state of the output file |