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 <sal/types.h>
24 #include <canvas/canvastoolsdllapi.h>
31 /** Calculate elapsed time.
33 This class provides several time-measurement and
34 -management functions. In its simplest use-case, it
35 measures the time from its creation.
37 class CANVASTOOLS_DLLPUBLIC ElapsedTime
40 /** Create a new ElapsedTime object
42 The moment of construction starts the time
43 measurement. That means, a subsequent getElapsedTime()
44 call will return the time difference between object
45 creation and getElapsedTime() call.
49 /** Creates a new ElapsedTime object based on another
52 The moment of construction starts the time
53 measurement. That means, a subsequent getElapsedTime()
54 call will return the time difference between object
55 creation and getElapsedTime() call. All time values
56 are not taken from the system's time base, but from
59 ElapsedTime( std::shared_ptr
<ElapsedTime
> const & pTimeBase
);
63 The instance of the reset() call starts the time
64 measurement from scratch. That means, a subsequent
65 getElapsedTime() call will return the time difference
66 between reset() and getElapsedTime() call.
70 /** Query the elapsed time
72 This method returns the elapsed time in seconds
73 between either the construction of this object, or the
74 last reset() call, if any (but see the time modulation
75 methods below, for means to modify the otherwise
76 continuous flow of time).
78 @return the elapsed time in seconds.
80 double getElapsedTime() const;
82 /** Pauses the running timer.
84 This method stops the time, as returned by this
85 object, until continueTimer() is called. During this
86 period, getElapsedTime() will always return the same
87 time value (i.e. the instant when pauseTimer() was
92 /** Continues the paused timer.
94 This method re-enables the time flow, that is, time
95 starts running again for clients calling
96 getElapsedTime(). The (subtle) difference to the
97 holdTimer/releaseTimer() methods below is, that there
98 is no perceived time 'jump' between the pauseTimer()
99 call and the continueTimer() call, i.e. the time
100 starts over with the same value it has stopped on
103 void continueTimer();
105 /** Adjusts the timer, hold and pause times.
107 This method modifies the time as returned by this
108 object by the specified amount. This affects the time
109 as returned by getElapsedTime(), regardless of the
110 mode (e.g. paused, or on hold).
113 This value will be added to the current time, i.e. the
114 next call to getElapsedTime() (when performed
115 immediately) will be adjusted by fOffset.
117 void adjustTimer( double fOffset
);
119 /** Holds the current time.
121 This call makes the timer hold the current time
122 (e.g. getElapsedTime() will return the time when
123 holdTimer() was called), while the underlying time is
124 running on. When releaseTimer() is called, the time
125 will 'jump' to the then-current, underlying time. This
126 is equivalent to pressing the "interim time" button on
127 a stop watch, which shows this stopped time, while the
128 clock keeps running internally.
132 /** Releases a held timer.
134 After this call, the timer again returns the running
135 time on getElapsedTime().
140 static double getSystemTime();
141 double getCurrentTime() const;
142 double getElapsedTimeImpl() const; // does not set m_fLastQueriedTime
144 const std::shared_ptr
<ElapsedTime
> m_pTimeBase
;
146 /// To validate adjustTimer() calls with bLimitToLastQueriedTime=true
147 mutable double m_fLastQueriedTime
;
149 /// Start time, from which the difference to the time base is returned
152 /// Instant, when last pause or hold started, relative to m_fStartTime
153 double m_fFrozenTime
;
155 /// True, when in pause mode
158 /// True, when in hold mode
165 #endif /* INCLUDED_CANVAS_ELAPSEDTIME_HXX */
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */