LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/canvas - elapsedtime.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1 100.0 %
Date: 2013-07-09 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_CANVAS_ELAPSEDTIME_HXX
      21             : #define INCLUDED_CANVAS_ELAPSEDTIME_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : 
      25             : #include "boost/shared_ptr.hpp"
      26             : #include <canvas/canvastoolsdllapi.h>
      27             : 
      28             : namespace canvas
      29             : {
      30             :     namespace tools
      31             :     {
      32             :         /** Calculate elapsed time.
      33             : 
      34             :             This class provides several time-measurement and
      35             :             -management functions. In its simplest use-case, it
      36             :             measures the time from its creation.
      37             :          */
      38          65 :         class CANVASTOOLS_DLLPUBLIC ElapsedTime
      39             :         {
      40             :         public:
      41             :             /** Create a new ElapsedTime object
      42             : 
      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.
      47             :              */
      48             :             ElapsedTime();
      49             : 
      50             :             /** Creates a new ElapsedTime object based on another
      51             :                 timer.
      52             : 
      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.
      59             :              */
      60             :             ElapsedTime( ::boost::shared_ptr<ElapsedTime> const & pTimeBase );
      61             : 
      62             :             /** Reset the time
      63             : 
      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.
      68             :              */
      69             :             void reset();
      70             : 
      71             :             /** Query the elapsed time
      72             : 
      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).
      78             : 
      79             :                 @return the elapsed time in seconds.
      80             :              */
      81             :             double getElapsedTime() const;
      82             : 
      83             :             /** Pauses the running timer.
      84             : 
      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).
      90             :              */
      91             :             void pauseTimer();
      92             : 
      93             :             /** Continues the paused timer.
      94             : 
      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().
     103             :              */
     104             :             void continueTimer();
     105             : 
     106             :             /** Adjusts the timer, hold and pause times.
     107             : 
     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).
     112             : 
     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.
     117             : 
     118             :                 @param bLimitToLastQueriedTime
     119             :                 Limits the given offset to the time that has been
     120             :                 taken via getElapsedTime()
     121             :             */
     122             :             void adjustTimer( double fOffset,
     123             :                               bool bLimitToLastQueriedTime = true );
     124             : 
     125             :             /** Holds the current time.
     126             : 
     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.
     135             :             */
     136             :             void holdTimer();
     137             : 
     138             :             /** Releases a held timer.
     139             : 
     140             :                 After this call, the timer again returns the running
     141             :                 time on getElapsedTime().
     142             :              */
     143             :             void releaseTimer();
     144             : 
     145             :         private:
     146             :             static double getSystemTime();
     147             :             double getCurrentTime() const;
     148             :             double getElapsedTimeImpl() const; // does not set m_fLastQueriedTime
     149             : 
     150             :             const ::boost::shared_ptr<ElapsedTime>  m_pTimeBase;
     151             : 
     152             :             /// To validate adjustTimer() calls with bLimitToLastQueriedTime=true
     153             :             mutable double                          m_fLastQueriedTime;
     154             : 
     155             :             /// Start time, from which the difference to the time base is returned
     156             :             double                                  m_fStartTime;
     157             : 
     158             :             /// Instant, when last pause or hold started, relative to m_fStartTime
     159             :             double                                  m_fFrozenTime;
     160             : 
     161             :             /// True, when in pause mode
     162             :             bool                                    m_bInPauseMode;
     163             : 
     164             :             /// True, when in hold mode
     165             :             bool                                    m_bInHoldMode;
     166             :         };
     167             : 
     168             :     }
     169             : }
     170             : 
     171             : #endif /* INCLUDED_CANVAS_ELAPSEDTIME_HXX */
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10