|
SDL3pp
A slim C++ wrapper for SDL3
|
The storage API is a high-level API designed to abstract away the portability issues that come up when using something lower-level (in SDL's case, this sits on top of the [Filesystem](CategoryFilesystem) and [IOStream](CategoryIOStream) subsystems). More...
Classes | |
| struct | SDL::StorageBase |
| Base class to Storage. More... | |
| struct | SDL::Storage |
| An abstract interface for filesystem access. More... | |
Typedefs | |
| using | SDL::StorageRaw = SDL_Storage* |
| Alias to raw representation for Storage. | |
| using | SDL::StorageRef = ResourceRefT<StorageBase> |
| Reference for Storage. | |
| using | SDL::StorageInterface = SDL_StorageInterface |
| Function interface for Storage. | |
Functions | |
| Storage | SDL::OpenTitleStorage (StringParam override, PropertiesRef props) |
| Opens up a read-only container for the application's filesystem. | |
| Storage | SDL::OpenUserStorage (StringParam org, StringParam app, PropertiesRef props) |
| Opens up a container for a user's unique read/write filesystem. | |
| Storage | SDL::OpenFileStorage (StringParam path) |
| Opens up a container for local filesystem storage. | |
| Storage | SDL::OpenStorage (const StorageInterface &iface, void *userdata) |
| Opens up a container using a client-provided storage interface. | |
| bool | SDL::CloseStorage (StorageRaw storage) |
| Closes and frees a storage container. | |
| bool | SDL::StorageReady (StorageRef storage) |
| Checks if the storage container is ready to use. | |
| std::optional< Uint64 > | SDL::GetStorageFileSize (StorageRef storage, StringParam path) |
| Query the size of a file within a storage container. | |
| bool | SDL::ReadStorageFile (StorageRef storage, StringParam path, TargetBytes destination) |
| Synchronously read a file from a storage container into a client-provided buffer. | |
| std::string | SDL::ReadStorageFile (StorageRef storage, StringParam path) |
| Synchronously read a file from a storage container into a client-provided buffer. | |
| template<class T> | |
| std::vector< T > | SDL::ReadStorageFileAs (StorageRef storage, StringParam path) |
| Synchronously read a file from a storage container into a client-provided buffer. | |
| void | SDL::WriteStorageFile (StorageRef storage, StringParam path, SourceBytes source) |
| Synchronously write a file from client memory into a storage container. | |
| void | SDL::CreateStorageDirectory (StorageRef storage, StringParam path) |
| Create a directory in a writable storage container. | |
| void | SDL::EnumerateStorageDirectory (StorageRef storage, StringParam path, EnumerateDirectoryCallback callback, void *userdata) |
| Enumerate a directory in a storage container through a callback function. | |
| void | SDL::EnumerateStorageDirectory (StorageRef storage, StringParam path, EnumerateDirectoryCB callback) |
| Enumerate a directory in a storage container through a callback function. | |
| std::vector< Path > | SDL::EnumerateStorageDirectory (StorageRef storage, StringParam path) |
| Enumerate a directory in a storage container through a callback function. | |
| void | SDL::RemoveStoragePath (StorageRef storage, StringParam path) |
| Remove a file or an empty directory in a writable storage container. | |
| void | SDL::RenameStoragePath (StorageRef storage, StringParam oldpath, StringParam newpath) |
| Rename a file or directory in a writable storage container. | |
| void | SDL::CopyStorageFile (StorageRef storage, StringParam oldpath, StringParam newpath) |
| Copy a file in a writable storage container. | |
| PathInfo | SDL::GetStoragePathInfo (StorageRef storage, StringParam path) |
| Get information about a filesystem path in a storage container. | |
| Uint64 | SDL::GetStorageSpaceRemaining (StorageRef storage) |
| Queries the remaining space in a storage container. | |
| OwnArray< char * > | SDL::GlobStorageDirectory (StorageRef storage, StringParam path, StringParam pattern, GlobFlags flags) |
| Enumerate a directory tree, filtered by pattern, and return a list. | |
| SDL::Storage::Storage (StringParam override, PropertiesRef props) | |
| Opens up a read-only container for the application's filesystem. | |
| SDL::Storage::Storage (StringParam org, StringParam app, PropertiesRef props) | |
| Opens up a container for a user's unique read/write filesystem. | |
| SDL::Storage::Storage (StringParam path) | |
| Opens up a container for local filesystem storage. | |
| SDL::Storage::Storage (const StorageInterface &iface, void *userdata) | |
| Opens up a container using a client-provided storage interface. | |
| bool | SDL::StorageBase::Close () |
| Closes and frees a storage container. | |
| bool | SDL::StorageBase::Ready () |
| Checks if the storage container is ready to use. | |
| std::optional< Uint64 > | SDL::StorageBase::GetFileSize (StringParam path) |
| Query the size of a file within a storage container. | |
| bool | SDL::StorageBase::ReadFile (StringParam path, TargetBytes destination) |
| Synchronously read a file from a storage container into a client-provided buffer. | |
| std::string | SDL::StorageBase::ReadFile (StringParam path) |
| Synchronously read a file from a storage container into a client-provided buffer. | |
| template<class T> | |
| std::vector< T > | SDL::StorageBase::ReadFileAs (StringParam path) |
| Synchronously read a file from a storage container into a client-provided buffer. | |
| void | SDL::StorageBase::WriteFile (StringParam path, SourceBytes source) |
| Synchronously write a file from client memory into a storage container. | |
| void | SDL::StorageBase::CreateDirectory (StringParam path) |
| Create a directory in a writable storage container. | |
| void | SDL::StorageBase::EnumerateDirectory (StringParam path, EnumerateDirectoryCallback callback, void *userdata) |
| Enumerate a directory in a storage container through a callback function. | |
| std::vector< Path > | SDL::StorageBase::EnumerateDirectory (StringParam path) |
| Enumerate a directory in a storage container through a callback function. | |
| void | SDL::StorageBase::EnumerateDirectory (StringParam path, EnumerateDirectoryCB callback) |
| Enumerate a directory in a storage container through a callback function. | |
| void | SDL::StorageBase::RemovePath (StringParam path) |
| Remove a file or an empty directory in a writable storage container. | |
| void | SDL::StorageBase::RenamePath (StringParam oldpath, StringParam newpath) |
| Rename a file or directory in a writable storage container. | |
| void | SDL::StorageBase::CopyFile (StringParam oldpath, StringParam newpath) |
| Copy a file in a writable storage container. | |
| PathInfo | SDL::StorageBase::GetPathInfo (StringParam path) |
| Get information about a filesystem path in a storage container. | |
| Uint64 | SDL::StorageBase::GetSpaceRemaining () |
| Queries the remaining space in a storage container. | |
| OwnArray< char * > | SDL::StorageBase::GlobDirectory (StringParam path, StringParam pattern, GlobFlags flags) |
| Enumerate a directory tree, filtered by pattern, and return a list. | |
The storage API is a high-level API designed to abstract away the portability issues that come up when using something lower-level (in SDL's case, this sits on top of the [Filesystem](CategoryFilesystem) and [IOStream](CategoryIOStream) subsystems).
It is significantly more restrictive than a typical filesystem API, for a number of reasons:
Consider the following example:
Going over the bullet points again:
Due to these assumptions, the filesystem code is not portable and will fail under these common scenarios:
When using Storage, these types of problems are virtually impossible to trip over:
Note the improvements that Storage makes:
The result is an application that is significantly more robust against the increasing demands of platforms and their filesystems!
A publicly available example of an Storage backend is the Steam Cloud backend - you can initialize Steamworks when starting the program, and then SDL will recognize that Steamworks is initialized and automatically use ISteamRemoteStorage when the application opens user storage. More importantly, when you open storage it knows to begin a "batch" of filesystem operations, and when you close storage it knows to end and flush the batch. This is used by Steam to support Dynamic Cloud Sync ; users can save data on one PC, put the device to sleep, and then continue playing on another PC (and vice versa) with the save data fully synchronized across all devices, allowing for a seamless experience without having to do full restarts of the program.
All paths in the Storage API use Unix-style path separators ('/'). Using a different path separator will not work, even if the underlying platform would otherwise accept it. This is to keep code using the Storage API portable between platforms and Storage implementations and simplify app code.
Paths with relative directories ("." and "..") are forbidden by the Storage API.
All valid UTF-8 strings (discounting the nullptr terminator character and the '/' path separator) are usable for filenames, however, an underlying Storage implementation may not support particularly strange sequences and refuse to create files with those names, etc.
| using SDL::StorageInterface = SDL_StorageInterface |
Function interface for Storage.
Apps that want to supply a custom implementation of Storage will fill in all the functions in this struct, and then pass it to OpenStorage to create a custom Storage object.
It is not usually necessary to do this; SDL provides standard implementations for many things you might expect to do with an Storage.
This structure should be initialized using InitInterface()
| using SDL::StorageRef = ResourceRefT<StorageBase> |
Reference for Storage.
This does not take ownership!
|
inline |
Closes and frees a storage container.
|
inline |
Closes and frees a storage container.
| storage | a storage container to close. |
|
inline |
Copy a file in a writable storage container.
| oldpath | the old path. |
| newpath | the new path. |
| Error | on failure. |
|
inline |
Copy a file in a writable storage container.
| storage | a storage container. |
| oldpath | the old path. |
| newpath | the new path. |
| Error | on failure. |
|
inline |
Create a directory in a writable storage container.
| path | the path of the directory to create. |
| Error | on failure. |
|
inline |
Create a directory in a writable storage container.
| storage | a storage container. |
| path | the path of the directory to create. |
| Error | on failure. |
|
inline |
Enumerate a directory in a storage container through a callback function.
This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.
This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.
If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.
| path | the path of the directory to enumerate, or nullptr for the root. |
| Error | on failure. |
|
inline |
Enumerate a directory in a storage container through a callback function.
This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.
This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.
If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.
| path | the path of the directory to enumerate, or nullptr for the root. |
| callback | a function that is called for each entry in the directory. |
| userdata | a pointer that is passed to callback. |
| Error | on failure. |
|
inline |
Enumerate a directory in a storage container through a callback function.
This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.
This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.
If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.
| path | the path of the directory to enumerate, or nullptr for the root. |
| callback | a function that is called for each entry in the directory. |
| Error | on failure. |
|
inline |
Enumerate a directory in a storage container through a callback function.
This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.
This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.
If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.
| storage | a storage container. |
| path | the path of the directory to enumerate, or nullptr for the root. |
| Error | on failure. |
|
inline |
Enumerate a directory in a storage container through a callback function.
This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.
This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.
If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.
| storage | a storage container. |
| path | the path of the directory to enumerate, or nullptr for the root. |
| callback | a function that is called for each entry in the directory. |
| userdata | a pointer that is passed to callback. |
| Error | on failure. |
|
inline |
Enumerate a directory in a storage container through a callback function.
This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.
This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.
If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.
| storage | a storage container. |
| path | the path of the directory to enumerate, or nullptr for the root. |
| callback | a function that is called for each entry in the directory. |
| Error | on failure. |
|
inline |
Query the size of a file within a storage container.
| path | the relative path of the file to query. |
|
inline |
Get information about a filesystem path in a storage container.
| path | the path to query. |
|
inline |
Queries the remaining space in a storage container.
|
inline |
Query the size of a file within a storage container.
| storage | a storage container to query. |
| path | the relative path of the file to query. |
|
inline |
Get information about a filesystem path in a storage container.
| storage | a storage container. |
| path | the path to query. |
|
inline |
Queries the remaining space in a storage container.
| storage | a storage container to query. |
|
inline |
Enumerate a directory tree, filtered by pattern, and return a list.
Files are filtered out if they don't match the string in pattern, which may contain wildcard characters * (match everything) and ? (match one character). If pattern is nullptr, no filtering is done and all results are returned. Subdirectories are permitted, and are specified with a path separator of '/'. Wildcard characters * and ? never match a path separator.
flags may be set to GLOB_CASEINSENSITIVE to make the pattern matching case-insensitive.
The returned array is always nullptr-terminated, for your iterating convenience, but if count is non-nullptr, on return it will contain the number of items in the array, not counting the nullptr terminator.
If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.
| path | the path of the directory to enumerate, or nullptr for the root. |
| pattern | the pattern that files in the directory must match. Can be nullptr. |
| flags | SDL_GLOB_* bitflags that affect this search. |
| Error | on failure. |
|
inline |
Enumerate a directory tree, filtered by pattern, and return a list.
Files are filtered out if they don't match the string in pattern, which may contain wildcard characters * (match everything) and ? (match one character). If pattern is nullptr, no filtering is done and all results are returned. Subdirectories are permitted, and are specified with a path separator of '/'. Wildcard characters * and ? never match a path separator.
flags may be set to GLOB_CASEINSENSITIVE to make the pattern matching case-insensitive.
The returned array is always nullptr-terminated, for your iterating convenience, but if count is non-nullptr, on return it will contain the number of items in the array, not counting the nullptr terminator.
If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.
| storage | a storage container. |
| path | the path of the directory to enumerate, or nullptr for the root. |
| pattern | the pattern that files in the directory must match. Can be nullptr. |
| flags | SDL_GLOB_* bitflags that affect this search. |
| Error | on failure. |
|
inline |
Opens up a container for local filesystem storage.
This is provided for development and tools. Portable applications should use OpenTitleStorage() for access to game data and OpenUserStorage() for access to user data.
| path | the base path prepended to all storage paths, or nullptr for no base path. |
| Error | on failure. |
|
inline |
Opens up a container using a client-provided storage interface.
Applications do not need to use this function unless they are providing their own Storage implementation. If you just need an Storage, you should use the built-in implementations in SDL, like OpenTitleStorage() or OpenUserStorage().
This function makes a copy of iface and the caller does not need to keep it around after this call.
| iface | the interface that implements this storage, initialized using InitInterface(). |
| userdata | the pointer that will be passed to the interface functions. |
| Error | on failure. |
|
inline |
Opens up a read-only container for the application's filesystem.
By default, OpenTitleStorage uses the generic storage implementation. When the path override is not provided, the generic implementation will use the output of GetBasePath as the base path.
| override | a path to override the backend's default title root. |
| props | a property list that may contain backend-specific information. |
| Error | on failure. |
|
inline |
Opens up a container for a user's unique read/write filesystem.
While title storage can generally be kept open throughout runtime, user storage should only be opened when the client is ready to read/write files. This allows the backend to properly batch file operations and flush them when the container has been closed; ensuring safe and optimal save I/O.
| org | the name of your organization. |
| app | the name of your application. |
| props | a property list that may contain backend-specific information. |
| Error | on failure. |
|
inline |
Synchronously read a file from a storage container into a client-provided buffer.
The value of length must match the length of the file exactly; call GetStorageFileSize() to get this value. This behavior may be relaxed in a future release.
| path | the relative path of the file to read. |
|
inline |
Synchronously read a file from a storage container into a client-provided buffer.
The value of length must match the length of the file exactly; call GetStorageFileSize() to get this value. This behavior may be relaxed in a future release.
| path | the relative path of the file to read. |
| destination | a client-provided buffer to read the file into. |
|
inline |
Synchronously read a file from a storage container into a client-provided buffer.
The value of length must match the length of the file exactly; call Storage.GetFileSize() to get this value. This behavior may be relaxed in a future release.
| path | the relative path of the file to read. |
|
inline |
Synchronously read a file from a storage container into a client-provided buffer.
| storage | a storage container to read from. |
| path | the relative path of the file to read. |
| Error | on failure. |
|
inline |
Synchronously read a file from a storage container into a client-provided buffer.
The value of destination.size() must match the length of the file exactly; call GetStorageFileSize() to get this value. This behavior may be relaxed in a future release.
| storage | a storage container to read from. |
| path | the relative path of the file to read. |
| destination | a client-provided buffer to read the file into. |
|
inline |
Synchronously read a file from a storage container into a client-provided buffer.
| storage | a storage container to read from. |
| path | the relative path of the file to read. |
| Error | on failure. |
|
inline |
Checks if the storage container is ready to use.
This function should be called in regular intervals until it returns true - however, it is not recommended to spinwait on this call, as the backend may depend on a synchronous message loop. You might instead poll this in your game's main loop while processing events and drawing a loading screen.
|
inline |
Remove a file or an empty directory in a writable storage container.
| path | the path to remove from the filesystem. |
| Error | on failure. |
|
inline |
Remove a file or an empty directory in a writable storage container.
| storage | a storage container. |
| path | the path to remove from the filesystem. |
| Error | on failure. |
|
inline |
Rename a file or directory in a writable storage container.
| oldpath | the old path. |
| newpath | the new path. |
| Error | on failure. |
|
inline |
Rename a file or directory in a writable storage container.
| storage | a storage container. |
| oldpath | the old path. |
| newpath | the new path. |
| Error | on failure. |
|
inline |
Opens up a container using a client-provided storage interface.
Applications do not need to use this function unless they are providing their own Storage implementation. If you just need an Storage, you should use the built-in implementations in SDL, like OpenTitleStorage() or OpenUserStorage().
This function makes a copy of iface and the caller does not need to keep it around after this call.
| iface | the interface that implements this storage, initialized using InitInterface(). |
| userdata | the pointer that will be passed to the interface functions. |
| Error | on failure. |
|
inline |
Opens up a container for a user's unique read/write filesystem.
While title storage can generally be kept open throughout runtime, user storage should only be opened when the client is ready to read/write files. This allows the backend to properly batch file operations and flush them when the container has been closed; ensuring safe and optimal save I/O.
| org | the name of your organization. |
| app | the name of your application. |
| props | a property list that may contain backend-specific information. |
| Error | on failure. |
|
inline |
Opens up a read-only container for the application's filesystem.
By default, OpenTitleStorage uses the generic storage implementation. When the path override is not provided, the generic implementation will use the output of GetBasePath as the base path.
| override | a path to override the backend's default title root. |
| props | a property list that may contain backend-specific information. |
| Error | on failure. |
|
inline |
Opens up a container for local filesystem storage.
This is provided for development and tools. Portable applications should use OpenTitleStorage() for access to game data and OpenUserStorage() for access to user data.
| path | the base path prepended to all storage paths, or nullptr for no base path. |
| Error | on failure. |
|
inline |
Checks if the storage container is ready to use.
This function should be called in regular intervals until it returns true - however, it is not recommended to spinwait on this call, as the backend may depend on a synchronous message loop. You might instead poll this in your game's main loop while processing events and drawing a loading screen.
| storage | a storage container to query. |
|
inline |
Synchronously write a file from client memory into a storage container.
| path | the relative path of the file to write. |
| source | a client-provided buffer to write from. |
| Error | on failure. |
|
inline |
Synchronously write a file from client memory into a storage container.
| storage | a storage container to write to. |
| path | the relative path of the file to write. |
| source | a client-provided buffer to write from. |
| Error | on failure. |