2#ifndef STORMM_TEXTFILE_H
3#define STORMM_TEXTFILE_H
8#include "DataTypes/stormm_vector_types.h"
9#include "FileManagement/file_enumerators.h"
10#include "Reporting/reporting_enumerators.h"
11#include "parsing_enumerators.h"
16using diskutil::PrintSituation;
17using review::TextEnds;
23 TextFileReader(
int line_count_in,
const int* line_lengths_in,
const size_t* line_limits_in,
24 const char* text_in,
const std::string file_name_in);
34 const int* line_lengths;
35 const size_t* line_limits;
37 const std::string file_name;
63 TextFile(
const std::string &file_name, TextOrigin source = TextOrigin::DISK,
64 const std::string &content = std::string(
""),
65 const std::string &caller = std::string(
""));
67 TextFile(
const char* content,
const size_t length,
const std::string &caller = std::string(
""));
136 std::string
extractString(
int line_number,
int start_pos = 0,
int string_length = -1)
const;
153 std::string
toString(TextEnds line_endings = TextEnds::NEWLINE)
const;
168 void write(std::ofstream *foutp)
const;
169 void write(
const std::string &new_filename,
170 PrintSituation expectation = PrintSituation::OPEN_NEW)
const;
171 void write(PrintSituation expectation = PrintSituation::OPEN_NEW)
const;
177 std::string orig_file;
183 std::vector<int> line_lengths;
186 std::vector<size_t> line_limits;
189 std::vector<char> text;
196 void validateLineIndex(
int index,
const char* caller)
const;
206 std::string setFileName(
const std::string &file_name, TextOrigin source,
207 const std::string &content);
220 void linesFromString(
const char* text_in,
const size_t n_char);
221 void linesFromString(
const std::string &text_in);
232 int checkAvailableLength(
int line_number,
int start_pos = 0,
int string_length = -1)
const;
TextFile()
Constructor for taking an ascii file or a very long, formatted string and transforming it into a std:...
Definition textfile.cpp:22
std::string getLineAsString(int line_index) const
Get a line from the file as a string.
Definition textfile.cpp:160
char getChar(int index) const
Get one character of a text file after converting it to a character vector in memory.
Definition textfile.cpp:155
std::string getFileName() const
Get the name of the original file.
Definition textfile.cpp:106
int getLineCount() const
Get the line count of a text file after converting it to a character vector in memory.
Definition textfile.cpp:121
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.
Definition textfile.cpp:190
const char * getLinePointer(int line_index) const
Get a char pointer to a specific line in the object.
Definition textfile.cpp:178
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.
Definition textfile.cpp:203
~TextFile()=default
Default destructor.
int getLineLength(int index) const
Get the length of a line. A bounds check will be applied to the line index number.
Definition textfile.cpp:135
void write(std::ofstream *foutp) const
Write the contents of the object to disk.
Definition textfile.cpp:319
int getLineLimits(int index) const
Get one of the line limits of a text file converted to a character vector in memory.
Definition textfile.cpp:126
const char * getTextPointer(int index) const
Get a char pointer to a specific index in the object.
Definition textfile.cpp:173
TextFile(const TextFile &original)=default
The default copy and move constructors as well as assignment operators are acceptable.
const TextFileReader data() const
Get an abstract of a text file's CPU-RAM representation, for ease of use.
Definition textfile.cpp:184
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 sp...
Definition textfile.cpp:285
int getLongestLineLength() const
Get the length of the longest line in the file.
Definition textfile.cpp:141
size_t getTextSize() const
Get the number of text characters in the object's buffer (this will not count implicit carriage retur...
Definition textfile.cpp:150
TextFile()
Constructor for taking an ascii file or a very long, formatted string and transforming it into a std:...
Definition textfile.cpp:22
Definition stormm_vector_types.h:141
TextFileReader(int line_count_in, const int *line_lengths_in, const size_t *line_limits_in, const char *text_in, const std::string file_name_in)
The constructor takes length constants and constant pointers.
Definition textfile.cpp:14
Abstract for the TextFile object, providing read-only access.
Definition textfile.h:20
TextFileReader(int line_count_in, const int *line_lengths_in, const size_t *line_limits_in, const char *text_in, const std::string file_name_in)
The constructor takes length constants and constant pointers.
Definition textfile.cpp:14
TextFileReader(const TextFileReader &original)=default
Take the default copy and move constructors. The assignment operators will get implicitly deleted as ...