Project Alice
Loading...
Searching...
No Matches
simple_fs_types_nix.hpp
Go to the documentation of this file.
1#pragma once
3#include "unordered_dense.h"
4
5// this file should contain the four class definitions of the types
6// required for simple fs: file_system, directory, unopened_file, and file
7// all in the namespace simple_fs, all classes
8
9namespace simple_fs {
11 std::vector<native_string> ordered_roots;
12 std::vector<native_string> ignored_paths;
13
14 void operator=(file_system const& other) = delete;
15 void operator=(file_system&& other) = delete;
16
17public:
18 friend std::optional<file> open_file(directory const& dir, native_string_view file_name);
19 friend void reset(file_system& fs);
20 friend void add_root(file_system& fs, native_string_view root_path);
21 // will be added relative to the location that the executable file exists in
22 friend void add_relative_root(file_system& fs, native_string_view root_path);
23 friend directory get_root(file_system const& fs);
24 friend native_string extract_state(file_system const& fs);
25 friend void restore_state(file_system& fs, native_string_view data);
26 friend std::vector<directory> list_subdirectories(directory const& dir);
27 friend std::vector<unopened_file> list_files(directory const& dir, native_char const* extension);
28 friend std::optional<unopened_file> peek_file(directory const& dir, native_string_view file_name);
29 friend void add_ignore_path(file_system& fs, native_string_view replaced_path);
30 friend std::vector<native_string> list_roots(file_system const& fs);
31 friend bool is_ignored_path(file_system const& fs, native_string_view path);
32};
33
34class directory {
35 file_system const* parent_system = nullptr;
36 native_string relative_path;
37
38public:
39 directory(file_system const* parent_system, native_string_view relative_path)
40 : parent_system(parent_system), relative_path(relative_path) { }
41
42 friend directory get_root(file_system const& fs);
43 friend std::optional<file> open_file(directory const& dir, native_string_view file_name);
44 friend std::vector<unopened_file> list_files(directory const& dir, native_char const* extension);
45 friend std::vector<directory> list_subdirectories(directory const& dir);
46 friend std::optional<file> open_file(directory const& dir, native_string_view file_name);
47 friend std::optional<unopened_file> peek_file(directory const& dir, native_string_view file_name);
48 friend void write_file(directory const& dir, native_string_view file_name, char const* file_data, uint32_t file_size);
49 friend directory open_directory(directory const& dir, native_string_view directory_name);
50 friend native_string get_full_name(directory const& dir);
51};
52
54 native_string absolute_path;
55 native_string file_name;
56
57public:
59 : absolute_path(absolute_path), file_name(file_name) { }
60
61 friend std::optional<file> open_file(unopened_file const& f);
62 friend std::vector<unopened_file> list_files(directory const& dir, native_char const* extension);
65};
66
67class file {
68 int file_descriptor = -1;
69#if defined(_GNU_SOURCE) || defined(_DEFAULT_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE)
70 void* mapping_handle = nullptr;
71#else
72 void* file_buffer = nullptr;
73#endif
74
75 native_string absolute_path;
76 file_contents content;
77
78 file(native_string const& full_path);
79 file(int file_descriptor, native_string const& full_path);
80
81public:
82 file(file const& other) = delete;
83 file(file&& other) noexcept;
84 void operator=(file const& other) = delete;
85 void operator=(file&& other) noexcept;
86 ~file();
87
88 friend std::optional<file> open_file(directory const& dir, native_string_view file_name);
89 friend std::optional<file> open_file(unopened_file const& f);
90 friend class std::optional<file>;
91 friend file_contents view_contents(file const& f);
92 friend native_string get_full_name(file const& f);
93};
94} // namespace simple_fs
friend std::vector< directory > list_subdirectories(directory const &dir)
friend std::optional< unopened_file > peek_file(directory const &dir, native_string_view file_name)
friend native_string get_full_name(directory const &dir)
directory(file_system const *parent_system, native_string_view relative_path)
friend std::optional< file > open_file(directory const &dir, native_string_view file_name)
friend void write_file(directory const &dir, native_string_view file_name, char const *file_data, uint32_t file_size)
friend directory open_directory(directory const &dir, native_string_view directory_name)
friend std::vector< unopened_file > list_files(directory const &dir, native_char const *extension)
friend directory get_root(file_system const &fs)
friend std::vector< directory > list_subdirectories(directory const &dir)
friend std::optional< unopened_file > peek_file(directory const &dir, native_string_view file_name)
friend void add_root(file_system &fs, native_string_view root_path)
friend bool is_ignored_path(file_system const &fs, native_string_view path)
friend void reset(file_system &fs)
friend native_string extract_state(file_system const &fs)
friend std::optional< file > open_file(directory const &dir, native_string_view file_name)
friend void add_relative_root(file_system &fs, native_string_view root_path)
friend void restore_state(file_system &fs, native_string_view data)
friend void add_ignore_path(file_system &fs, native_string_view replaced_path)
friend std::vector< unopened_file > list_files(directory const &dir, native_char const *extension)
friend directory get_root(file_system const &fs)
friend std::vector< native_string > list_roots(file_system const &fs)
friend file_contents view_contents(file const &f)
friend native_string get_full_name(file const &f)
file(file const &other)=delete
friend std::optional< file > open_file(directory const &dir, native_string_view file_name)
void operator=(file const &other)=delete
unopened_file(native_string_view absolute_path, native_string_view file_name)
friend native_string get_full_name(unopened_file const &f)
friend native_string get_file_name(unopened_file const &f)
friend std::vector< unopened_file > list_files(directory const &dir, native_char const *extension)
friend std::optional< file > open_file(unopened_file const &f)
char native_char
std::string_view native_string_view
std::string native_string
uint uint32_t