]> git.tdb.fi Git - libs/core.git/blob - source/fs/filemonitor.cpp
Use C++11 features with containers
[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         event_disp(0)
13 { }
14
15 FileMonitor::~FileMonitor()
16 {
17         delete priv;
18 }
19
20 void FileMonitor::use_event_dispatcher(IO::EventDispatcher &ed)
21 {
22         if(event_disp)
23                 throw logic_error("event_disp!=0");
24
25         event_disp = &ed;
26         platform_use_event_dispatcher();
27 }
28
29 void FileMonitor::add_file(const FS::Path &path)
30 {
31         MonitoredFile file;
32         file.path = path;
33         file.modified = false;
34         prepare_file(file);
35         files.push_back(file);
36 }
37
38 void FileMonitor::remove_file(const FS::Path &path)
39 {
40         auto i = find_member(files, path, &MonitoredFile::path);
41         if(i!=files.end())
42         {
43                 cleanup_file(*i);
44                 if(&*i!=&files.back())
45                         *i = files.back();
46                 files.pop_back();
47         }
48 }
49
50 } // namespace FS
51 } // namespace Msp