]> git.lyx.org Git - lyx.git/blob - src/support/Timeout.h
Account for old versions of Pygments
[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         signals2::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         friend class Impl;
59         ///
60         Impl * const pimpl_;
61         /// one-shot or repeating
62         Type type;
63         /// timeout value in milliseconds
64         unsigned int timeout_ms;
65 };
66
67 // Small Timer class useful for debugging and performance investigation.
68 class Timer
69 {
70 public:
71         ///
72         Timer();
73         ///
74         ~Timer();
75         ///
76         void restart();
77         ///
78         int elapsed() const;
79         ///
80         std::string dateStr(char separator = 0) const;
81         ///
82         std::string timeStr(char separator = 0) const;
83         ///
84         std::string toStr() const;
85         ///
86         static std::string currentToStr();
87 private:
88         struct Private;
89         Private * d;
90 };
91
92 } // namespace lyx
93
94 #endif