-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.hpp
80 lines (65 loc) · 1.71 KB
/
file.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include "event.hpp"
class file
{
private:
enum class state
{
invalid,
closed,
open_read,
open_write,
};
struct private_data;
public:
enum class event_type
{
added,
removed,
modified,
renamed,
unknown,
};
class file_watch_hook
{
private:
struct pdata;
public:
file_watch_hook(pdata&&);
file_watch_hook& operator=(file_watch_hook&&);
file_watch_hook(file_watch_hook&&);
file_watch_hook() = delete;
file_watch_hook(const file_watch_hook&) = delete;
file_watch_hook& operator=(const file_watch_hook&) = delete;
~file_watch_hook();
private:
std::unique_ptr<pdata> _p;
};
public:
file(std::string path);
file(const file&) = delete;
file& operator=(const file&) = delete;
file(file&& o) = default;
file& operator=(file&& o) = default;
~file();
void open(std::string_view mode) const;
void close() const;
size_t size() const;
bool exists() const;
void watch();
size_t read(char* buffer, size_t length) const;
std::string read_all() const;
event<void(event_type)> changed_externally;
static file_watch_hook
watch(std::string_view path,
std::function<void(std::string_view, event_type)> functor);
static event<void(std::string_view)> generic_file_change;
static std::string read_all(std::string_view path);
static bool exists(std::string_view path);
static std::tuple<std::string, std::string, std::string>
parse_path(std::string_view path);
private:
std::string read_all_open() const;
private:
std::unique_ptr<private_data> _pdata;
};