opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
virtual_filesystem.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <functional>
8#include <optional>
9#include <string>
10#include <utility>
11
12namespace osc { class ResourcePath; }
13
14namespace osc
15{
16 // An abstract base class for an object that can access `ResourceStream`s
17 // from an implementation-defined data source (e.g. filesystem, database,
18 // zip file). Commonly called a VFS (Virtual File System) in operating
19 // systems and game engines.
21 protected:
22 VirtualFilesystem() = default;
27 public:
29
30 // Returns true if `resource_path` can be resolved by this `VirtualFilesystem`.
32
33 // Returns a freshly-opened input stream to the data referenced by `resource_path`.
34 //
35 // - Throws if `resource_path` cannot be resolved by this `VirtualFilesystem`.
36 // - Throws if `resource_path` refers to a directory.
38
39 // Returns the entire contents of the input stream referenced by `resource_path` slurped
40 // into a `std::string`.
41 //
42 // - Throws if `resource_path` cannot be resolved by this `VirtualFilesystem`.
43 // - Throws if `resource_path` refers to a directory.
44 std::string slurp(const ResourcePath& resource_path);
45
46 // Returns a generator that yields entries of a directory referenced by
47 // `resource_path` (does not recursively visit subdirectories).
48 //
49 // - The iteration order is implementation-defined.
50 // - Each entry is visited only once.
51 // - Throws if `resource_path` cannot be resolved by this `VirtualFilesystem`.
52 // - Throws if `resource_path` is not a directory.
57
58 private:
59 // Implementors must return `true` if `resource_path` can be resolved by this `VirtualFilesystem`
60 // (i.e. a subsequent call to `impl_open`/`impl_iterate_directory` would succeed). Otherwise,
61 // `false` must be returned.
63
64 // Implementors must return an opened `ResourceStream` that points to the first byte of the
65 // resource referenced by `resource_path`. Otherwise, the impelementation must throw an exception.
67
68 // Implementors must return a generator that yields entries of a directory referenced by
69 // `resource_path`, or throw an exception (see `iterate_directory` docstring for expected
70 // behavior).
72 };
73}
Definition resource_path.h:12
Definition resource_stream.h:11
Definition virtual_filesystem.h:20
virtual ResourceStream impl_open(const ResourcePath &resource_path)=0
virtual cpp23::generator< ResourceDirectoryEntry > impl_iterate_directory(ResourcePath resource_path)=0
bool resource_exists(const ResourcePath &resource_path)
Definition virtual_filesystem.h:31
VirtualFilesystem(const VirtualFilesystem &)=default
VirtualFilesystem(VirtualFilesystem &&) noexcept=default
std::string slurp(const ResourcePath &resource_path)
virtual bool impl_resource_exists(const ResourcePath &resource_path)=0
ResourceStream open(const ResourcePath &resource_path)
Definition virtual_filesystem.h:37
cpp23::generator< ResourceDirectoryEntry > iterate_directory(ResourcePath resource_path)
Definition virtual_filesystem.h:53
Definition generator.h:32
Definition custom_decoration_generator.h:5
constexpr U to(T &&value)
Definition conversion.h:56