Tramway SDK v0.1.1
Public Types | Public Member Functions | Public Attributes | List of all members
tram::File Struct Reference

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
 
FileReaderreader = nullptr
 
FileWriterwriter = nullptr
 
FileReaderParserreader_parser = nullptr
 
FileWriterParserwriter_parser = nullptr
 

Detailed Description

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.

See also
https://racenis.github.io/tram-sdk/documentation/framework/file.html

Member Enumeration Documentation

◆ AccessMode

enum tram::File::AccessMode : uint32_t
Enumerator
READ 
WRITE 
PAUSE_LINE 
TEXT 
BINARY 

Constructor & Destructor Documentation

◆ File()

tram::File::File ( char const *  path,
uint32_t  mode 
)

Opens a file.

Parameters
pathPath to the file. If no prefix is set, this path will be interpreted as being relative to the project/executable working directory.
modeMode is a bitmask consisting of flags that can be found in the AccessMode enum.

◆ ~File()

tram::File::~File ( )

Member Function Documentation

◆ is_continue()

bool tram::File::is_continue ( )

Returns true if file parser has not reached end.

◆ is_open()

bool tram::File::is_open ( )

Returns true if file was opened.

◆ read_float32()

float tram::File::read_float32 ( )

◆ read_float64()

double tram::File::read_float64 ( )

◆ read_int16()

int16_t tram::File::read_int16 ( )

◆ read_int32()

int32_t tram::File::read_int32 ( )

◆ read_int64()

int64_t tram::File::read_int64 ( )

◆ read_int8()

int8_t tram::File::read_int8 ( )

◆ read_line()

std::string_view tram::File::read_line ( )

Parses off the remaining line.

◆ read_name()

name_t tram::File::read_name ( )

◆ read_string()

std::string_view tram::File::read_string ( )

◆ read_token()

std::string_view tram::File::read_token ( )

◆ read_uint16()

uint16_t tram::File::read_uint16 ( )

◆ read_uint32()

uint32_t tram::File::read_uint32 ( )

◆ read_uint64()

uint64_t tram::File::read_uint64 ( )

◆ read_uint8()

uint8_t tram::File::read_uint8 ( )

◆ reset_flags()

void tram::File::reset_flags ( )

Resets the error flag.

◆ skip_linebreak()

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.

◆ was_error()

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.

◆ write_float32()

void tram::File::write_float32 ( float  value)

◆ write_float64()

void tram::File::write_float64 ( double  value)

◆ write_int16()

void tram::File::write_int16 ( int16_t  value)

◆ write_int32()

void tram::File::write_int32 ( int32_t  value)

◆ write_int64()

void tram::File::write_int64 ( int64_t  value)

◆ write_int8()

void tram::File::write_int8 ( int8_t  value)

◆ write_name()

void tram::File::write_name ( name_t  value)

◆ write_newline()

void tram::File::write_newline ( )

Writes a newline to the file.

The newline is just the \n character.

◆ write_string()

void tram::File::write_string ( const char *  value)

◆ write_uint16()

void tram::File::write_uint16 ( uint16_t  value)

◆ write_uint32()

void tram::File::write_uint32 ( uint32_t  value)

◆ write_uint64()

void tram::File::write_uint64 ( uint64_t  value)

◆ write_uint8()

void tram::File::write_uint8 ( uint8_t  value)

Member Data Documentation

◆ buffer

char* tram::File::buffer = nullptr

◆ buffer_cursor

char* tram::File::buffer_cursor = nullptr

◆ buffer_end

char* tram::File::buffer_end = nullptr

◆ mode

uint32_t tram::File::mode

◆ path

std::string tram::File::path

◆ pause_next

bool tram::File::pause_next

◆ reader

FileReader* tram::File::reader = nullptr

◆ reader_parser

FileReaderParser* tram::File::reader_parser = nullptr

◆ writer

FileWriter* tram::File::writer = nullptr

◆ writer_parser

FileWriterParser* tram::File::writer_parser = nullptr

The documentation for this struct was generated from the following files: