1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CANVAS_ELAPSEDTIME_HXX
21 #define INCLUDED_CANVAS_ELAPSEDTIME_HXX
23 #include <canvas/canvastoolsdllapi.h>
30 /** Calculate elapsed time.
32 This class provides several time-measurement and
33 -management functions. In its simplest use-case, it
34 measures the time from its creation.
36 class CANVASTOOLS_DLLPUBLIC ElapsedTime
39 /** Create a new ElapsedTime object
41 The moment of construction starts the time
42 measurement. That means, a subsequent getElapsedTime()
43 call will return the time difference between object
44 creation and getElapsedTime() call.
48 /** Creates a new ElapsedTime object based on another
51 The moment of construction starts the time
52 measurement. That means, a subsequent getElapsedTime()
53 call will return the time difference between object
54 creation and getElapsedTime() call. All time values
55 are not taken from the system's time base, but from
58 ElapsedTime( std::shared_ptr
<ElapsedTime
> const & pTimeBase
);
62 The instance of the reset() call starts the time
63 measurement from scratch. That means, a subsequent
64 getElapsedTime() call will return the time difference
65 between reset() and getElapsedTime() call.
69 /** Query the elapsed time
71 This method returns the elapsed time in seconds
72 between either the construction of this object, or the
73 last reset() call, if any (but see the time modulation
74 methods below, for means to modify the otherwise
75 continuous flow of time).
77 @return the elapsed time in seconds.
79 double getElapsedTime() const;
81 /** Pauses the running timer.
83 This method stops the time, as returned by this
84 object, until continueTimer() is called. During this
85 period, getElapsedTime() will always return the same
86 time value (i.e. the instant when pauseTimer() was
91 /** Continues the paused timer.
93 This method re-enables the time flow, that is, time
94 starts running again for clients calling
95 getElapsedTime(). The (subtle) difference to the
96 holdTimer/releaseTimer() methods below is, that there
97 is no perceived time 'jump' between the pauseTimer()
98 call and the continueTimer() call, i.e. the time
99 starts over with the same value it has stopped on
102 void continueTimer();
104 /** Adjusts the timer, hold and pause times.
106 This method modifies the time as returned by this
107 object by the specified amount. This affects the time
108 as returned by getElapsedTime(), regardless of the
109 mode (e.g. paused, or on hold).
112 This value will be added to the current time, i.e. the
113 next call to getElapsedTime() (when performed
114 immediately) will be adjusted by fOffset.
116 void adjustTimer( double fOffset
);
118 /** Holds the current time.
120 This call makes the timer hold the current time
121 (e.g. getElapsedTime() will return the time when
122 holdTimer() was called), while the underlying time is
123 running on. When releaseTimer() is called, the time
124 will 'jump' to the then-current, underlying time. This
125 is equivalent to pressing the "interim time" button on
126 a stop watch, which shows this stopped time, while the
127 clock keeps running internally.
131 /** Releases a held timer.
133 After this call, the timer again returns the running
134 time on getElapsedTime().
139 static double getSystemTime();
140 double getCurrentTime() const;
141 double getElapsedTimeImpl() const; // does not set m_fLastQueriedTime
143 const std::shared_ptr
<ElapsedTime
> m_pTimeBase
;
145 /// To validate adjustTimer() calls with bLimitToLastQueriedTime=true
146 mutable double m_fLastQueriedTime
;
148 /// Start time, from which the difference to the time base is returned
151 /// Instant, when last pause or hold started, relative to m_fStartTime
152 double m_fFrozenTime
;
154 /// True, when in pause mode
157 /// True, when in hold mode
164 #endif /* INCLUDED_CANVAS_ELAPSEDTIME_HXX */
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */