SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
Collection of functions to open, use and close streams. More...
Functions | |
SLIOStream * | open (std::string path, SLIOStreamKind kind, SLIOStreamMode mode) |
Opens a file stream for I/O operations. More... | |
void | close (SLIOStream *stream) |
Closes and deletes a stream. More... | |
bool | exists (std::string path, SLIOStreamKind kind) |
Checks whether a given file exists. More... | |
SLIOBuffer | readIntoBuffer (std::string path, SLIOStreamKind kind) |
Reads an entire file into memory. More... | |
std::string | readIntoString (std::string path, SLIOStreamKind kind) |
Reads an entire file into a string. More... | |
void | writeString (std::string path, SLIOStreamKind kind, const std::string &string) |
Writes a string to a file. More... | |
Collection of functions to open, use and close streams.
void SLFileStorage::close | ( | SLIOStream * | stream | ) |
Closes and deletes a stream.
First flushes the stream to make sure that all data is written and then deletes it. Implementations of SLIOStream will then close their backing streams in the destructor.
stream | Stream to close |
Definition at line 106 of file SLFileStorage.cpp.
bool SLFileStorage::exists | ( | std::string | path, |
SLIOStreamKind | kind | ||
) |
Checks whether a given file exists.
Checks whether a file exists at the given path and if it is of the given kind. When running in a web browser, the function may need to communicate with a server to check whether the file exists, which is quite slow.
path | Path to file |
kind | Kind of file |
Definition at line 121 of file SLFileStorage.cpp.
SLIOStream * SLFileStorage::open | ( | std::string | path, |
SLIOStreamKind | kind, | ||
SLIOStreamMode | mode | ||
) |
Opens a file stream for I/O operations.
Opens a file stream and prepares it for reading or writing. After usage, the stream should be closed by calling SLFileStorage::close. The function uses the kind and the mode to determine which kind of stream it should create. For example, in a web browser, configuration files are written to local storage.
path | Path to file |
kind | Kind of file |
mode | Mode to open the stream in |
Definition at line 50 of file SLFileStorage.cpp.
SLIOBuffer SLFileStorage::readIntoBuffer | ( | std::string | path, |
SLIOStreamKind | kind | ||
) |
Reads an entire file into memory.
Opens a stream from the path provided in read mode, allocates a buffer for its content, reads the content into the buffer and closes the stream. The buffer is owned by the caller and must be deallocated with a call to SLFileStorage::deleteBuffer after usage.
path | Path to the file to read |
kind | Kind of the file to read |
Definition at line 148 of file SLFileStorage.cpp.
std::string SLFileStorage::readIntoString | ( | std::string | path, |
SLIOStreamKind | kind | ||
) |
Reads an entire file into a string.
Opens a stream from the path provided in read mode, allocates a strings for its content, reads the content into the string and closes the stream. Line endings are NOT converted to LF, which means that on Windows, the string may contain CRLF line endings.
path | Path to the file to read |
kind | Kind of the file to read |
Definition at line 169 of file SLFileStorage.cpp.
void SLFileStorage::writeString | ( | std::string | path, |
SLIOStreamKind | kind, | ||
const std::string & | string | ||
) |
Writes a string to a file.
Opens a stream to the path provided in write mode, writes the string to the file and closes the stream. Line endings are NOT converted to LF, which means that on Windows, the file may contain LF line endings after writing instead of CRLF line endings.
path | The path to the file to write to |
kind | The kind of the file to write to |
string | The string to write to the file |
Definition at line 191 of file SLFileStorage.cpp.