Skip to content

Engine → Core → mount_table.h

vfs::mount_table

Syntax

class CONJURE_API mount_table final : public file_system

Inheritance Hierarchy

vfs::file_system → vfs::mount_table

Constructors

AccessSignatureDescription
publicmount_table();

Destructors

AccessSignatureDescription
public~mount_table() override;

Variables

AccessNameTypeDefaultDescription
privatemMountsstd::map<std::string, std::shared_ptr<file_system>, std::less<>>{}
privatemMutexmutable std::mutex{}

Functions

Public

create_directories

[[nodiscard]] result<void> create_directories(
    std::string_view uri) override;

enumerate

[[nodiscard]] result<void> enumerate(
    std::string_view directory,
    enumerate_flags flags,
    const enumerate_callback &callback) override;

exists

[[nodiscard]] bool exists(
    std::string_view uri) override;

find_mount

[[nodiscard]] file_system *find_mount(
    std::string_view scheme) const noexcept;

The backend bound to a scheme ("assets" or "assets://"), or nullptr. The pointer stays valid until the scheme is unmounted.

is_read_only

[[nodiscard]] bool is_read_only() const noexcept override;

True when at least one backend is mounted and all of them are read-only.

mount

[[nodiscard]] result<void> mount(
    std::string_view scheme,
    std::shared_ptr<file_system> backend);

Binds a scheme ("assets" or "assets://") to a backend. INVALID_ARGUMENT for a null backend, a malformed scheme or a mount table that already contains this one (directly or through other mount tables), ALREADY_EXISTS when the scheme is taken. One backend may be mounted under several schemes.

open_read

[[nodiscard]] result<std::unique_ptr<file>> open_read(
    std::string_view uri) override;

read_file

[[nodiscard]] result<std::vector<std::byte>> read_file(
    std::string_view uri) override;

read_text_file

[[nodiscard]] result<std::string> read_text_file(
    std::string_view uri) override;

remove

[[nodiscard]] result<void> remove(
    std::string_view uri) override;

remove_all

[[nodiscard]] result<void> remove_all(
    std::string_view uri) override;

rename

[[nodiscard]] result<void> rename(
    std::string_view from,
    std::string_view to) override;

When both URIs lead to the same backend, directly or through nested mount tables, it renames (so two schemes over one backend behave like one). Across backends a file is copied and the source removed; a directory is UNSUPPORTED. The base contract's codes still apply there, judged by the backends that store the two files and in the order of a backend's own rename: PERMISSION_DENIED for an escape or a read-only backend at either end, INVALID_ARGUMENT for the root of a backend at either end and for a name at to that is not portable, and only then the lookups: NOT_FOUND for a missing from, ALREADY_EXISTS for a directory at to, NOT_FOUND when the parent of to is missing. All of it is checked before anything is copied. The copy is written atomically. If the source cannot be removed afterwards, a copy that created a new file is removed again, but a file it replaced is not restored.

schemes

[[nodiscard]] std::vector<std::string> schemes() const;

Every mounted scheme in ascending order.

split

[[nodiscard]] static result<std::pair<std::string_view, std::string_view>> split(
    std::string_view uri);

Splits "scheme://path" into its two parts ("assets://a/b.png" -> {"assets", "a/b.png"}). INVALID_ARGUMENT when there is no "://" or the scheme is empty or contains characters other than letters, digits, '-', '_', '.' and '+'.

stat

[[nodiscard]] result<file_stat> stat(
    std::string_view uri) override;

unmount

[[nodiscard]] result<void> unmount(
    std::string_view scheme);

Removes a binding. NOT_FOUND when the scheme is not mounted.

write_file

[[nodiscard]] result<void> write_file(
    std::string_view uri,
    std::span<const std::byte> data) override;

write_file_atomic

[[nodiscard]] result<void> write_file_atomic(
    std::string_view uri,
    std::span<const std::byte> data) override;

Private

contains

[[nodiscard]] bool contains(
    const file_system &backend) const;

find_shared

[[nodiscard]] std::shared_ptr<file_system> find_shared(
    std::string_view scheme) const;

route

[[nodiscard]] result<route_target> route(
    std::string_view uri) const;

route_to_storage

[[nodiscard]] static result<route_target> route_to_storage(
    route_target target);

snapshot_backends

[[nodiscard]] std::vector<std::shared_ptr<file_system>> snapshot_backends() const;