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 directory open_directory(directory const& dir, native_string_view directory_name);
60 friend native_string get_full_name(directory const& f);
61};
62
63class unopened_file {
64 native_string file_name;
65 native_string absolute_path;
66
67public:
69 : file_name(file_name), absolute_path(absolute_path) { }
70
71 friend std::optional<file> open_file(unopened_file const& f);
72 friend std::vector<unopened_file> list_files(directory const& dir, native_char const* extension);
75};
76
77class file {
78 HANDLE file_handle = INVALID_HANDLE_VALUE;
79 HANDLE mapping_handle = nullptr;
80
81 native_string absolute_path;
82 file_contents content;
83
84 file(native_string const& full_path);
85 file(HANDLE file_handle, native_string const& full_path);
86
87public:
88 file(file const& other) = delete;
89 file(file&& other) noexcept;
90 void operator=(file const& other) = delete;
91 void operator=(file&& other) noexcept;
93
94 friend std::optional<file> open_file(directory const& dir, native_string_view file_name);
95 friend std::optional<file> open_file(unopened_file const& f);
96 friend class std::optional<file>;
97 friend file_contents view_contents(file const& f);
98 friend native_string get_full_name(file const& f);
99};
100} // 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::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