sandbox
Loading...
Searching...
No Matches
filesystem_module.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_FILESYSTEM_FILESYSTEM_MODULE_HPP_
3#define LIBSBX_FILESYSTEM_FILESYSTEM_MODULE_HPP_
4
5#include <memory>
6#include <string>
7#include <vector>
8#include <filesystem>
9
10#include <libsbx/core/module.hpp>
11#include <libsbx/core/engine.hpp>
12
13#include <libsbx/filesystem/alias.hpp>
14#include <libsbx/filesystem/virtual_filesystem.hpp>
15#include <libsbx/filesystem/filesystem_base.hpp>
16#include <libsbx/filesystem/file_base.hpp>
17
18namespace sbx::filesystem {
19
20class filesystem_module : public core::module<filesystem_module> {
21 inline static const auto is_registered = register_module(stage::pre);
22
23public:
24
26
27 ~filesystem_module() override;
28
29 auto update() -> void override;
30
31 template<typename Type, typename... Args>
32 requires (std::is_base_of_v<filesystem_base, Type>)
33 auto create_filesystem(const alias& alias, Args&&... args) -> std::shared_ptr<Type> {
34 return _filesystem->create_filesystem<Type>(alias, std::forward<Args>(args)...);
35 }
36
37 template<typename Type, typename... Args>
38 auto create_filesystem(std::string&& alias, Args&&... args) -> std::shared_ptr<Type> {
39 return _filesystem->create_filesystem<Type>(std::move(alias), std::forward<Args>(args)...);
40 }
41
42 auto open_file(const std::string& path, const file_base::mode mode) -> file_ptr {
43 return _filesystem->open_file(path, mode);
44 }
45
46 auto create_file(const std::string& path) -> file_ptr {
47 return _filesystem->create_file(path);
48 }
49
50 auto exists(const std::string& path) const -> bool {
51 return _filesystem->exists(path);
52 }
53
54 auto all_files() const -> std::vector<std::string> {
55 return _filesystem->all_files();
56 }
57
58 auto unregister_alias(const alias& alias) -> void {
59 _filesystem->unregister_alias(alias);
60 }
61
62 auto is_alias_registered(const alias& alias) const -> bool {
63 return _filesystem->is_alias_registered(alias);
64 }
65
66 auto native_path_of(const std::string& virtual_path) const -> std::filesystem::path {
67 return _filesystem->native_path_of(virtual_path);
68 }
69
70 auto native_path_of(const std::filesystem::path& virtual_path) const -> std::filesystem::path {
71 return _filesystem->native_path_of(virtual_path);
72 }
73
74private:
75
76 std::unique_ptr<virtual_filesystem> _filesystem;
77
78}; // class filesystem_module
79
80} // namespace sbx::filesystem
81
82#endif // LIBSBX_FILESYSTEM_FILESYSTEM_MODULE_HPP_
Definition: module.hpp:92
Definition: alias.hpp:13
Definition: filesystem_module.hpp:20