Tramway SDK v0.1.1
|
Very fast file reader/writer. More...
#include <framework/file.h>
Public Types | |
enum | AccessMode : uint32_t { READ = 1 , WRITE = 2 , PAUSE_LINE = 4 , TEXT = 8 , BINARY = 16 } |
Public Member Functions | |
File (char const *path, uint32_t mode) | |
Opens a file. More... | |
~File () | |
bool | is_open () |
Returns true if file was opened. More... | |
bool | is_continue () |
Returns true if file parser has not reached end. More... | |
void | write_int8 (int8_t value) |
void | write_int16 (int16_t value) |
void | write_int32 (int32_t value) |
void | write_int64 (int64_t value) |
void | write_uint8 (uint8_t value) |
void | write_uint16 (uint16_t value) |
void | write_uint32 (uint32_t value) |
void | write_uint64 (uint64_t value) |
void | write_float32 (float value) |
void | write_float64 (double value) |
void | write_name (name_t value) |
void | write_string (const char *value) |
void | write_newline () |
Writes a newline to the file. More... | |
int8_t | read_int8 () |
int16_t | read_int16 () |
int32_t | read_int32 () |
int64_t | read_int64 () |
uint8_t | read_uint8 () |
uint16_t | read_uint16 () |
uint32_t | read_uint32 () |
uint64_t | read_uint64 () |
float | read_float32 () |
double | read_float64 () |
name_t | read_name () |
std::string_view | read_string () |
std::string_view | read_token () |
std::string_view | read_line () |
Parses off the remaining line. More... | |
void | skip_linebreak () |
Skips over a linebreak. More... | |
void | reset_flags () |
Resets the error flag. More... | |
bool | was_error () |
Checks if there has been an error. More... | |
Public Attributes | |
std::string | path |
uint32_t | mode |
bool | pause_next |
char * | buffer = nullptr |
char * | buffer_cursor = nullptr |
char * | buffer_end = nullptr |
FileReader * | reader = nullptr |
FileWriter * | writer = nullptr |
FileReaderParser * | reader_parser = nullptr |
FileWriterParser * | writer_parser = nullptr |
Very fast file reader/writer.
For reading a file, set the File::READ flag in the mode bitmask. The file, referenced by the path, will be immediately opened, if possible. After opening, it will be fully read into memory. After that you can use all of the read_xyz() methods.
To check if the file has ended and no more reading can be done, use the is_continue() method.
To check whether the file was opened, use the is_open() method.
For writing to a file, set the File::WRITE flag in the mode bitmask.
After that you can use the various write_xyz() methods.
All of the writing will take place in a large buffer, which after the File class is destructed will be written to disk.
enum tram::File::AccessMode : uint32_t |
tram::File::File | ( | char const * | path, |
uint32_t | mode | ||
) |
Opens a file.
path | Path to the file. If no prefix is set, this path will be interpreted as being relative to the project/executable working directory. |
mode | Mode is a bitmask consisting of flags that can be found in the AccessMode enum. |
tram::File::~File | ( | ) |
bool tram::File::is_continue | ( | ) |
Returns true if file parser has not reached end.
bool tram::File::is_open | ( | ) |
Returns true if file was opened.
float tram::File::read_float32 | ( | ) |
double tram::File::read_float64 | ( | ) |
int16_t tram::File::read_int16 | ( | ) |
int32_t tram::File::read_int32 | ( | ) |
int64_t tram::File::read_int64 | ( | ) |
int8_t tram::File::read_int8 | ( | ) |
std::string_view tram::File::read_line | ( | ) |
Parses off the remaining line.
name_t tram::File::read_name | ( | ) |
std::string_view tram::File::read_string | ( | ) |
std::string_view tram::File::read_token | ( | ) |
uint16_t tram::File::read_uint16 | ( | ) |
uint32_t tram::File::read_uint32 | ( | ) |
uint64_t tram::File::read_uint64 | ( | ) |
uint8_t tram::File::read_uint8 | ( | ) |
void tram::File::reset_flags | ( | ) |
Resets the error flag.
void tram::File::skip_linebreak | ( | ) |
Skips over a linebreak.
Probably only useful if the file has been opened for reading in the MODE_PAUSE_LINE
mode, since the parser will stop at any new line and the only way to continue parsing is to use this method.
bool tram::File::was_error | ( | ) |
Checks if there has been an error.
The error flag does not get cleared on its own, so if an error ocurred anywhere, this method will report that. To determine whether a certain value has been parsed correctly, first use the reset_flags() method to reset the error flag, then use the read_xyz() method to read in the value and then use this method to determine whether there was an error in parsing that specific method.
void tram::File::write_float32 | ( | float | value | ) |
void tram::File::write_float64 | ( | double | value | ) |
void tram::File::write_int16 | ( | int16_t | value | ) |
void tram::File::write_int32 | ( | int32_t | value | ) |
void tram::File::write_int64 | ( | int64_t | value | ) |
void tram::File::write_int8 | ( | int8_t | value | ) |
void tram::File::write_name | ( | name_t | value | ) |
void tram::File::write_newline | ( | ) |
Writes a newline to the file.
The newline is just the \n
character.
void tram::File::write_string | ( | const char * | value | ) |
void tram::File::write_uint16 | ( | uint16_t | value | ) |
void tram::File::write_uint32 | ( | uint32_t | value | ) |
void tram::File::write_uint64 | ( | uint64_t | value | ) |
void tram::File::write_uint8 | ( | uint8_t | value | ) |
char* tram::File::buffer = nullptr |
char* tram::File::buffer_cursor = nullptr |
char* tram::File::buffer_end = nullptr |
uint32_t tram::File::mode |
std::string tram::File::path |
bool tram::File::pause_next |
FileReader* tram::File::reader = nullptr |
FileReaderParser* tram::File::reader_parser = nullptr |
FileWriter* tram::File::writer = nullptr |
FileWriterParser* tram::File::writer_parser = nullptr |