-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWatcher.h
More file actions
45 lines (34 loc) · 876 Bytes
/
Watcher.h
File metadata and controls
45 lines (34 loc) · 876 Bytes
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
#pragma once
#include <functional>
#include <iostream>
#include <thread>
#include <chrono>
#include <filesystem>
#include <vector>
using namespace std;
class FolderWatcher {
public:
struct FileChangeInfo {
enum ChangeType { ADDED, DELETED, MODIFIED };
std::string fileName;
ChangeType changeType;
};
using Observer = std::function<void(const FileChangeInfo&)>;
void subscribe(const Observer& observer);
void startWatching(const std::string& folderPath);
void notifyObservers(const FileChangeInfo& changeInfo);
void setFolderPath(const string& path) {
folderPath = path;
}
const string& getFolderPath() const {
return folderPath;
}
private:
std::vector<Observer> observers;
FileChangeInfo lastChange;
string folderPath;
};
class Observer {
public:
void update();
};