1 | // |
---|---|
2 | // Stopwatch.cpp |
3 | // |
4 | // Library: Foundation |
5 | // Package: DateTime |
6 | // Module: Stopwatch |
7 | // |
8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Stopwatch.h" |
16 | |
17 | |
18 | namespace Poco { |
19 | |
20 | |
21 | Stopwatch::Stopwatch(): _elapsed(0), _running(false) |
22 | { |
23 | } |
24 | |
25 | |
26 | Stopwatch::~Stopwatch() |
27 | { |
28 | } |
29 | |
30 | |
31 | Clock::ClockDiff Stopwatch::elapsed() const |
32 | { |
33 | if (_running) |
34 | { |
35 | Clock current; |
36 | return _elapsed + (current - _start); |
37 | } |
38 | else |
39 | { |
40 | return _elapsed; |
41 | } |
42 | } |
43 | |
44 | |
45 | void Stopwatch::reset() |
46 | { |
47 | _elapsed = 0; |
48 | _running = false; |
49 | } |
50 | |
51 | |
52 | void Stopwatch::restart() |
53 | { |
54 | _elapsed = 0; |
55 | _start.update(); |
56 | _running = true; |
57 | } |
58 | |
59 | |
60 | } // namespace Poco |
61 |