1#ifndef SDL3PP_STORAGE_H_
2#define SDL3PP_STORAGE_H_
4#include <SDL3/SDL_storage.h>
5#include "SDL3pp_filesystem.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
398 bool Ready()
const {
return SDL_StorageReady(
get()); }
414 if (Uint64 length; SDL_GetStorageFileSize(
get(), path, &length)) {
441 if (!sz || *sz == 0)
return {};
442 std::string buffer(*sz, 0);
443 if (
ReadFile(std::move(path), buffer))
return buffer;
468 return SDL_ReadStorageFile(
494 if (!sz || *sz == 0)
return {};
495 std::vector<T> buffer(*sz /
sizeof(T) + (*sz %
sizeof(T) ? 1 : 0), 0);
496 if (
ReadFile(std::move(path), {buffer.data(), *sz}))
return buffer;
545 r.emplace_back(fname);
580 [](
void* userdata,
const char* dirname,
const char* fname) {
582 return cb(dirname, fname);
617 CheckError(SDL_EnumerateStorageDirectory(
get(), path, callback, userdata));
680 if (
PathInfo info; SDL_GetStoragePathInfo(
get(), path, &info)) {
698 return SDL_GetStorageSpaceRemaining(
get());
740 CheckError(SDL_GlobStorageDirectory(
get(), path, pattern, flags, &count));
802 bool reset(SDL_Storage* newResource = {})
804 return SDL_CloseStorage(
release(newResource));
837 constexpr explicit Storage(SDL_Storage* resource = {})
842 constexpr Storage(
const Storage& other) =
delete;
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr SDL_Storage * release(SDL_Storage * newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr SDL_Storage * get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
constexpr const char * c_str() const
Converts to a null terminated C string.
Definition SDL3pp_strings.h:124
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
std::function< EnumerationResult(const char *dirname, const char *fname)> EnumerateDirectoryCB
Callback for directory enumeration.
Definition SDL3pp_filesystem.h:475
constexpr EnumerationResult ENUM_CONTINUE
Value that requests that enumeration continue.
Definition SDL3pp_filesystem.h:412
SDL_EnumerateDirectoryCallback EnumerateDirectoryCallback
Callback for directory enumeration.
Definition SDL3pp_filesystem.h:449
Uint32 GlobFlags
Flags for path matching.
Definition SDL3pp_filesystem.h:380
SDL_StorageInterface StorageInterface
Function interface for StorageBase.
Definition SDL3pp_storage.h:261
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
Information about a path on the filesystem.
Definition SDL3pp_filesystem.h:346
Wrap properties id.
Definition SDL3pp_properties.h:203
Source byte stream.
Definition SDL3pp_strings.h:239
size_t size_bytes
The size in bytes.
Definition SDL3pp_strings.h:241
const void * data
The data copied from.
Definition SDL3pp_strings.h:240
An abstract interface for filesystem access.
Definition SDL3pp_storage.h:278
std::optional< Uint64 > GetFileSize(StringParam path) const
Query the size of a file within a storage container.
Definition SDL3pp_storage.h:412
PathInfo GetPathInfo(StringParam path) const
Get information about a filesystem path in a storage container.
Definition SDL3pp_storage.h:678
StorageBase(const StorageInterface &iface, void *userdata)
Opens up a container using a client-provided storage interface.
Definition SDL3pp_storage.h:381
void EnumerateDirectory(StringParam path, EnumerateDirectoryCallback callback, void *userdata)
Enumerate a directory in a storage container through a callback function.
Definition SDL3pp_storage.h:613
StorageBase(StringParam path)
Opens up a container for local filesystem storage.
Definition SDL3pp_storage.h:350
Uint64 GetSpaceRemaining() const
Queries the remaining space in a storage container.
Definition SDL3pp_storage.h:696
void WriteFile(StringParam path, SourceBytes source)
Synchronously write a file from client memory into a storage container.
Definition SDL3pp_storage.h:513
bool Ready() const
Checks if the storage container is ready to use.
Definition SDL3pp_storage.h:398
std::vector< Path > EnumerateDirectory(StringParam path)
Enumerate a directory.
Definition SDL3pp_storage.h:541
StorageBase(StringParam org, StringParam app, PropertiesBase &props)
Opens up a container for a user's unique read/write filesystem.
Definition SDL3pp_storage.h:324
void CopyFile(StringParam oldpath, StringParam newpath)
Copy a file in a writable storage container.
Definition SDL3pp_storage.h:662
bool ReadFile(StringParam path, TargetBytes destination) const
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:466
std::string ReadFile(StringParam path) const
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:438
void RemovePath(StringParam path)
Remove a file or an empty directory in a writable storage container.
Definition SDL3pp_storage.h:630
void RenamePath(StringParam oldpath, StringParam newpath)
Rename a file or directory in a writable storage container.
Definition SDL3pp_storage.h:646
void CreateDirectory(StringParam path)
Create a directory in a writable storage container.
Definition SDL3pp_storage.h:528
StorageBase(StringParam override, PropertiesBase &props)
Opens up a read-only container for the application's filesystem.
Definition SDL3pp_storage.h:296
OwnArray< char * > GlobDirectory(StringParam path, StringParam pattern, GlobFlags flags)
Enumerate a directory tree, filtered by pattern, and return a list.
Definition SDL3pp_storage.h:734
std::vector< T > ReadFileAs(StringParam path) const
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:491
void EnumerateDirectory(StringParam path, EnumerateDirectoryCB callback)
Enumerate a directory in a storage container through a callback function.
Definition SDL3pp_storage.h:576
Handle to a non owned storage.
Definition SDL3pp_storage.h:754
constexpr StorageRef(StorageRef &&other)
Move constructor.
Definition SDL3pp_storage.h:768
StorageRef & operator=(StorageRef other)
Assignment operator.
Definition SDL3pp_storage.h:781
constexpr StorageRef(const StorageRef &other)
Copy constructor.
Definition SDL3pp_storage.h:760
bool Close()
Closes and frees a storage container.
Definition SDL3pp_storage.h:819
constexpr ~StorageRef()=default
Default constructor.
bool reset(SDL_Storage *newResource={})
Closes and frees a storage container.
Definition SDL3pp_storage.h:802
Handle to an owned storage.
Definition SDL3pp_storage.h:831
constexpr Storage(SDL_Storage *resource={})
Constructs from the underlying resource.
Definition SDL3pp_storage.h:837
constexpr Storage(Storage &&other)=default
Move constructor.
Storage & operator=(Storage other)
Assignment operator.
Definition SDL3pp_storage.h:857
~Storage()
Frees up resource when object goes out of scope.
Definition SDL3pp_storage.h:852
Target byte stream.
Definition SDL3pp_strings.h:305
size_t size_bytes
The size in bytes.
Definition SDL3pp_strings.h:307
void * data
The address to have data copied to it.
Definition SDL3pp_strings.h:306