]> git.lyx.org Git - lyx.git/blob - src/support/Timeout.h
Update Win installer for new dictionary links. Untested.
[lyx.git] / src / support / Timeout.h
1 // -*- C++ -*-
2 /**
3  * \file Timeout.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef TIMEOUT_H
13 #define TIMEOUT_H
14
15 #include "support/signals.h"
16
17
18 namespace lyx {
19
20 /**
21  * This class executes the callback when the timeout expires.
22  */
23 class Timeout {
24 public:
25         /// the timeout type
26         enum Type {
27                 ONETIME, //< one-shot timer
28                 CONTINUOUS //< repeating
29         };
30         /// Note that the c-tor is implemented in the GUI-specific frontends
31         Timeout(unsigned int msec, Type = ONETIME);
32         ///
33         ~Timeout();
34         /// Is the timer running?
35         bool running() const;
36         /// start the timer
37         void start();
38         /// stop the timer
39         void stop();
40         /// restart the timer
41         void restart();
42         /// signal emitted on timer expiry
43         signal<void()> timeout;
44         /// emit the signal
45         void emit();
46         /// set the timer type
47         Timeout & setType(Type t);
48         /// set the timeout value
49         Timeout & setTimeout(unsigned int msec);
50
51 private:
52         /// noncopyable
53         Timeout(Timeout const &);
54         void operator=(Timeout const &);
55         ///
56         class Impl;
57         ///
58         Impl * const pimpl_;
59         /// one-shot or repeating
60         Type type;
61         /// timeout value in milliseconds
62         unsigned int timeout_ms;
63 };
64
65 // Small Timer class useful for debugging and performance investigation.
66 class Timer
67 {
68 public:
69         ///
70         Timer();
71         ///
72         ~Timer();
73         ///
74         void restart();
75         ///
76         int elapsed() const;
77         ///
78         std::string dateStr(char separator = 0) const;
79         ///
80         std::string timeStr(char separator = 0) const;
81         ///
82         std::string toStr() const;
83         ///
84         static std::string currentToStr();
85 private:
86         struct Private;
87         Private * d;
88 };
89
90 } // namespace lyx
91
92 #endif