SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::Storage Class Reference

An abstract interface for filesystem access. More...

Inheritance diagram for SDL::Storage:
Inheritance graph
[legend]

Public Member Functions

constexpr Storage ()=default
 Default ctor.
 
constexpr Storage (const StorageRaw resource)
 Constructs from StorageParam. More...
 
constexpr Storage (const Storage &other)=delete
 Copy constructor.
 
constexpr Storage (Storage &&other)
 Move constructor.
 
constexpr Storage (const StorageRef &other)=delete
 
constexpr Storage (StorageRef &&other)=delete
 
 Storage (StringParam override, PropertiesParam props)
 Opens up a read-only container for the application's filesystem. More...
 
 Storage (StringParam org, StringParam app, PropertiesParam props)
 Opens up a container for a user's unique read/write filesystem. More...
 
 Storage (StringParam path)
 Opens up a container for local filesystem storage. More...
 
 Storage (const StorageInterface &iface, void *userdata)
 Opens up a container using a client-provided storage interface. More...
 
 ~Storage ()
 Destructor.
 
Storageoperator= (Storage other)
 Assignment operator.
 
constexpr StorageRaw get () const
 Retrieves underlying StorageRaw.
 
constexpr StorageRaw release ()
 Retrieves underlying StorageRaw and clear this.
 
constexpr auto operator<=> (const Storage &other) const =default
 Comparison.
 
constexpr bool operator== (std::nullptr_t _) const
 Comparison.
 
constexpr operator bool () const
 Converts to bool.
 
constexpr operator StorageParam () const
 Converts to StorageParam.
 
bool Close ()
 Closes and frees a storage container. More...
 
bool Ready ()
 Checks if the storage container is ready to use. More...
 
std::optional< Uint64GetFileSize (StringParam path)
 Query the size of a file within a storage container. More...
 
bool ReadFile (StringParam path, TargetBytes destination)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 
std::string ReadFile (StringParam path)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 
void WriteFile (StringParam path, SourceBytes source)
 Synchronously write a file from client memory into a storage container. More...
 
void CreateDirectory (StringParam path)
 Create a directory in a writable storage container. More...
 
void EnumerateDirectory (StringParam path, EnumerateDirectoryCallback callback, void *userdata)
 Enumerate a directory in a storage container through a callback function. More...
 
std::vector< PathEnumerateDirectory (StringParam path)
 Enumerate a directory in a storage container through a callback function. More...
 
void EnumerateDirectory (StringParam path, EnumerateDirectoryCB callback)
 Enumerate a directory in a storage container through a callback function. More...
 
void RemovePath (StringParam path)
 Remove a file or an empty directory in a writable storage container. More...
 
void RenamePath (StringParam oldpath, StringParam newpath)
 Rename a file or directory in a writable storage container. More...
 
void CopyFile (StringParam oldpath, StringParam newpath)
 Copy a file in a writable storage container. More...
 
PathInfo GetPathInfo (StringParam path)
 Get information about a filesystem path in a storage container. More...
 
Uint64 GetSpaceRemaining ()
 Queries the remaining space in a storage container. More...
 
OwnArray< char * > GlobDirectory (StringParam path, StringParam pattern, GlobFlags flags)
 Enumerate a directory tree, filtered by pattern, and return a list. More...
 
template<class T >
std::vector< T > ReadFileAs (StringParam path)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 

Detailed Description

This is an opaque datatype. One can create this object using standard SDL functions like Storage.Storage, etc, or create an object with a custom implementation using Storage.Storage.

Since
This struct is available since SDL 3.2.0.
Category:
Resource

Constructor & Destructor Documentation

◆ Storage() [1/5]

constexpr SDL::Storage::Storage ( const StorageRaw  resource)
inlineexplicitconstexpr
Parameters
resourcea StorageRaw to be wrapped.

This assumes the ownership, call release() if you need to take back.

◆ Storage() [2/5]

SDL::Storage::Storage ( StringParam  override,
PropertiesParam  props 
)
inline
Parameters
overridea path to override the backend's default title root.
propsa property list that may contain backend-specific information.
Postcondition
a title storage container on success.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Close
Storage.GetFileSize
Storage.Storage
Storage.ReadFile

◆ Storage() [3/5]

SDL::Storage::Storage ( StringParam  org,
StringParam  app,
PropertiesParam  props 
)
inline

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.

Parameters
orgthe name of your organization.
appthe name of your application.
propsa property list that may contain backend-specific information.
Postcondition
a user storage container on success.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Close
Storage.GetFileSize
Storage.GetSpaceRemaining
Storage.Storage
Storage.ReadFile
Storage.Ready
Storage.WriteFile

◆ Storage() [4/5]

SDL::Storage::Storage ( StringParam  path)
inline

This is provided for development and tools. Portable applications should use Storage.Storage() for access to game data and Storage.Storage() for access to user data.

Parameters
paththe base path prepended to all storage paths, or nullptr for no base path.
Postcondition
a filesystem storage container on success.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Close
Storage.GetFileSize
Storage.GetSpaceRemaining
Storage.Storage
Storage.Storage
Storage.ReadFile
Storage.WriteFile

◆ Storage() [5/5]

SDL::Storage::Storage ( const StorageInterface iface,
void *  userdata 
)
inline

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 Storage.Storage() or Storage.Storage().

This function makes a copy of iface and the caller does not need to keep it around after this call.

Parameters
ifacethe interface that implements this storage, initialized using SDL_INIT_INTERFACE().
userdatathe pointer that will be passed to the interface functions.
Postcondition
a storage container on success.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Close
Storage.GetFileSize
Storage.GetSpaceRemaining
SDL_INIT_INTERFACE
Storage.ReadFile
Storage.Ready
Storage.WriteFile

The documentation for this class was generated from the following file: