bump product version to 4.1.6.2
[LibreOffice.git] / include / canvas / elapsedtime.hxx
blob8248e3408785fa3fba9bcc25081722987ef4226a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include "boost/shared_ptr.hpp"
26 #include <canvas/canvastoolsdllapi.h>
28 namespace canvas
30 namespace tools
32 /** Calculate elapsed time.
34 This class provides several time-measurement and
35 -management functions. In its simplest use-case, it
36 measures the time from its creation.
38 class CANVASTOOLS_DLLPUBLIC ElapsedTime
40 public:
41 /** Create a new ElapsedTime object
43 The moment of construction starts the time
44 measurement. That means, a subsequent getElapsedTime()
45 call will return the time difference between object
46 creation and getElapsedTime() call.
48 ElapsedTime();
50 /** Creates a new ElapsedTime object based on another
51 timer.
53 The moment of construction starts the time
54 measurement. That means, a subsequent getElapsedTime()
55 call will return the time difference between object
56 creation and getElapsedTime() call. All time values
57 are not taken from the system's time base, but from
58 the provided timer.
60 ElapsedTime( ::boost::shared_ptr<ElapsedTime> const & pTimeBase );
62 /** Reset the time
64 The instance of the reset() call starts the time
65 measurement from scratch. That means, a subsequent
66 getElapsedTime() call will return the time difference
67 between reset() and getElapsedTime() call.
69 void reset();
71 /** Query the elapsed time
73 This method returns the elapsed time in seconds
74 between either the construction of this object, or the
75 last reset() call, if any (but see the time modulation
76 methods below, for means to modify the otherwise
77 continuous flow of time).
79 @return the elapsed time in seconds.
81 double getElapsedTime() const;
83 /** Pauses the running timer.
85 This method stops the time, as returned by this
86 object, until continueTimer() is called. During this
87 period, getElapsedTime() will always return the same
88 time value (i.e. the instant when pauseTimer() was
89 called).
91 void pauseTimer();
93 /** Continues the paused timer.
95 This method re-enables the time flow, that is, time
96 starts running again for clients calling
97 getElapsedTime(). The (subtle) difference to the
98 holdTimer/releaseTimer() methods below is, that there
99 is no perceived time 'jump' between the pauseTimer()
100 call and the continueTimer() call, i.e. the time
101 starts over with the same value it has stopped on
102 pauseTimer().
104 void continueTimer();
106 /** Adjusts the timer, hold and pause times.
108 This method modifies the time as returned by this
109 object by the specified amount. This affects the time
110 as returned by getElapsedTime(), regardless of the
111 mode (e.g. paused, or on hold).
113 @param fOffset
114 This value will be added to the current time, i.e. the
115 next call to getElapsedTime() (when performed
116 immediately) will be adjusted by fOffset.
118 @param bLimitToLastQueriedTime
119 Limits the given offset to the time that has been
120 taken via getElapsedTime()
122 void adjustTimer( double fOffset,
123 bool bLimitToLastQueriedTime = true );
125 /** Holds the current time.
127 This call makes the timer hold the current time
128 (e.g. getElapsedTime() will return the time when
129 holdTimer() was called), while the underlying time is
130 running on. When releaseTimer() is called, the time
131 will 'jump' to the then-current, underlying time. This
132 is equivalent to pressing the "interim time" button on
133 a stop watch, which shows this stopped time, while the
134 clock keeps running internally.
136 void holdTimer();
138 /** Releases a held timer.
140 After this call, the timer again returns the running
141 time on getElapsedTime().
143 void releaseTimer();
145 private:
146 static double getSystemTime();
147 double getCurrentTime() const;
148 double getElapsedTimeImpl() const; // does not set m_fLastQueriedTime
150 const ::boost::shared_ptr<ElapsedTime> m_pTimeBase;
152 /// To validate adjustTimer() calls with bLimitToLastQueriedTime=true
153 mutable double m_fLastQueriedTime;
155 /// Start time, from which the difference to the time base is returned
156 double m_fStartTime;
158 /// Instant, when last pause or hold started, relative to m_fStartTime
159 double m_fFrozenTime;
161 /// True, when in pause mode
162 bool m_bInPauseMode;
164 /// True, when in hold mode
165 bool m_bInHoldMode;
171 #endif /* INCLUDED_CANVAS_ELAPSEDTIME_HXX */
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */