SDL_StorageInterface(3type)

πŸ’– SDL_StorageInterface β€” a whole vibe πŸ’–

okay so bestie, welcome to SDL_StorageInterface(3type) from the SDL3 datatypes gang 🌸 this is the page where you find out how to build your own storage backend. no cap.


✨ NAME ✨

SDL_StorageInterface β€” the function interface for SDL_Storage. it's giving "here's the blueprint, now go build a whole storage system" πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_storage.h>

typedef struct SDL_StorageInterface
{
    /* The version of this interface */
    Uint32 version;

    /* Called when the storage is closed */
    bool (SDLCALL *close)(void *userdata);

    /* Optional, returns whether the storage is currently ready for access */
    bool (SDLCALL *ready)(void *userdata);

    /* Enumerate a directory, optional for write-only storage */
    bool (SDLCALL *enumerate)(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata);

    /* Get path information, optional for write-only storage */
    bool (SDLCALL *info)(void *userdata, const char *path, SDL_PathInfo *info);

    /* Read a file from storage, optional for write-only storage */
    bool (SDLCALL *read_file)(void *userdata, const char *path, void *destination, Uint64 length);

    /* Write a file to storage, optional for read-only storage */
    bool (SDLCALL *write_file)(void *userdata, const char *path, const void *source, Uint64 length);

    /* Create a directory, optional for read-only storage */
    bool (SDLCALL *mkdir)(void *userdata, const char *path);

    /* Remove a file or empty directory, optional for read-only storage */
    bool (SDLCALL *remove)(void *userdata, const char *path);

    /* Rename a path, optional for read-only storage */
    bool (SDLCALL *rename)(void *userdata, const char *oldpath, const char *newpath);

    /* Copy a file, optional for read-only storage */
    bool (SDLCALL *copy)(void *userdata, const char *oldpath, const char *newpath);

    /* Get the space remaining, optional for read-only storage */
    Uint64 (SDLCALL *space_remaining)(void *userdata);
} SDL_StorageInterface;

like. look at all those function pointers. it's a whole roster 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, bestie: if your app wants to supply a custom implementation of SDL_Storage, you fill in all the functions in this struct β€” every single one, no skipping β€” and then you pass it to SDL_OpenStorage to create your very own custom SDL_Storage object. main character energy, fr fr ✨

and lowkey? you usually do not need to do this. SDL already provides standard implementations for a lot of things you might expect to do with an SDL_Storage. so before you go writing 11 function pointers by hand, maybe check if somebody already did it for you πŸ‘€

this structure should be initialized using SDL_INIT_INTERFACE(). do that. please. it's the law πŸ’…


🌈 AVAILABILITY 🌈

this struct has been available since SDL 3.2.0. she's not new new, but she's not ancient either πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘


that's the whole page, bestie, you ate πŸ’– no notes.

sign-off time: this came to you from Simple Directmedia Layer, version SDL 3.4.18, and it's the SDL_StorageInterface(3type) page. go forth and implement responsibly πŸ§šπŸ’œ

πŸ“¦ where this page comes from