]> git.lyx.org Git - lyx.git/blob - src/support/FileMonitor.h
some de-boostification
[lyx.git] / src / support / FileMonitor.h
1 // -*- C++ -*-
2 /**
3  * \file FileMonitor.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * FileMonitor monitors a file and informs a listener when that file has
12  * changed.
13  */
14
15 #ifndef FILEMONITOR_H
16 #define FILEMONITOR_H
17
18 #include <boost/signal.hpp>
19
20 namespace lyx {
21 namespace support {
22
23 class FileName;
24
25 class FileMonitor
26 {
27 public:
28         /** Once monitoring begins, the file will be monitored every
29          *  interval ms.
30          */
31         FileMonitor(FileName const & file_with_path, int interval);
32
33         /// Destructor
34         ~FileMonitor();
35
36         ///
37         void reset(FileName const & file_with_path) const;
38
39         ///
40         FileName const & filename() const;
41
42         /// Begin monitoring the file
43         void start() const;
44         ///
45         void stop() const;
46         ///
47         bool monitoring() const;
48
49         /** The checksum is recomputed whenever the file is modified.
50          *  If the file is not being monitored, then the checksum will be
51          *  recomputed each time this function is called.
52          */
53         unsigned long checksum() const;
54
55         /// Connect and you'll be informed when the file has changed.
56         typedef boost::signal<void()> FileChangedSig;
57         typedef FileChangedSig::slot_type slot_type;
58         ///
59         boost::signals::connection connect(slot_type const &) const;
60
61 private:
62         /// noncopyable
63         FileMonitor(FileMonitor const &);
64         void operator=(FileMonitor const &);
65
66         /// Use the Pimpl idiom to hide the internals.
67         class Impl;
68         /// The pointer never changes although *pimpl_'s contents may.
69         Impl * const pimpl_;
70 };
71
72 } // namespace support
73 } // namespace lyx
74
75 #endif // FILEMONITOR_H