Files and paths
Read text and binary files, check that a path exists, find the project folder.
Compute 2
size_t file_get_size(std::string const& filename)Size of a file in bytes; the file must exist (error otherwise).
std::string project_path_find(
std::string const& executable_path,
std::string const& directory_to_find = "shaders/"
)Relative path to the project root that contains directory_to_find (shaders/ by default), searched from the current and executable directories; exits the program if not found.
I/O 9
read_from_file
2 overloadstemplate <typename T>
void read_from_file(std::string const& filename, T& data)sourceReads data from a file with read_from_stream; the file must exist (error otherwise).
template <typename T>
void read_from_file(std::string const& filename, std::vector<std::vector<T>>& data)sourceReads a file line by line, appending one inner vector of values per line.
std::vector<char> read_from_file_binary(std::string const& filename)Reads the whole file as a vector of bytes, stopping with an error if the file cannot be accessed or is empty.
read_from_stream
3 overloadstemplate <typename T>
std::istream& read_from_stream(std::istream& stream, T& data)sourceReads one value from the stream with operator>>.
template <typename T, int N>
std::istream& read_from_stream(std::istream& stream, std::array<T,N>& data)sourceReads the N elements of a std::array from the stream, stopping early if the stream fails.
template <typename T>
std::istream& read_from_stream(std::istream& stream, std::vector<T>& data)sourceReads values until the end of the stream and appends them to the vector.
template <typename T>
std::istream& read_from_stream_per_line(std::istream& stream, std::vector<T>& data)Reads the stream line by line, parsing each line into one element appended to the vector.
template <typename T>
std::istream& read_line_from_stream(std::istream& stream, T& data)Reads one line of the stream and parses it into data.
std::string read_text_file(std::string const& filename)Entire content of a text file as a string; the file must exist (error otherwise).
Access 2
bool check_file_exist(std::string const& filename)Returns true if the file can be opened for reading, false otherwise.
bool check_path_exist(std::string const& pathname)Returns true if a file or directory exists at the given path, false otherwise.
Other 1
void assert_file_exist(std::string const& filename)Raises an error, with hints on the working directory, if the file cannot be opened.