]> git.tdb.fi Git - libs/core.git/blob - source/fs/filemonitor.cpp
Remove the broken IO::Filtered class
[libs/core.git] / source / fs / filemonitor.cpp
1 #include <msp/core/algorithm.h>
2 #include "filemonitor.h"
3 #include "filemonitor_platform.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace FS {
9
10 FileMonitor::FileMonitor():
11         priv(new Private(*this))
12 { }
13
14 FileMonitor::~FileMonitor()
15 {
16         delete priv;
17 }
18
19 void FileMonitor::use_event_dispatcher(IO::EventDispatcher &ed)
20 {
21         if(event_disp)
22                 throw logic_error("event_disp!=nullptr");
23
24         event_disp = &ed;
25         platform_use_event_dispatcher();
26 }
27
28 void FileMonitor::add_file(const FS::Path &path)
29 {
30         MonitoredFile file;
31         file.path = path;
32         prepare_file(file);
33         files.push_back(file);
34 }
35
36 void FileMonitor::remove_file(const FS::Path &path)
37 {
38         auto i = find_member(files, path, &MonitoredFile::path);
39         if(i!=files.end())
40         {
41                 cleanup_file(*i);
42                 if(&*i!=&files.back())
43                         *i = files.back();
44                 files.pop_back();
45         }
46 }
47
48 } // namespace FS
49 } // namespace Msp