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