LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/canvas - elapsedtime.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1 100.0 %
Date: 2012-08-25 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef INCLUDED_CANVAS_ELAPSEDTIME_HXX
      30                 :            : #define INCLUDED_CANVAS_ELAPSEDTIME_HXX
      31                 :            : 
      32                 :            : #include <sal/types.h>
      33                 :            : 
      34                 :            : #include "boost/shared_ptr.hpp"
      35                 :            : #include <canvas/canvastoolsdllapi.h>
      36                 :            : 
      37                 :            : namespace canvas
      38                 :            : {
      39                 :            :     namespace tools
      40                 :            :     {
      41                 :            :         /** Calculate elapsed time.
      42                 :            : 
      43                 :            :             This class provides several time-measurement and
      44                 :            :             -management functions. In its simplest use-case, it
      45                 :            :             measures the time from its creation.
      46                 :            :          */
      47                 :        130 :         class CANVASTOOLS_DLLPUBLIC ElapsedTime
      48                 :            :         {
      49                 :            :         public:
      50                 :            :             /** Create a new ElapsedTime object
      51                 :            : 
      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.
      56                 :            :              */
      57                 :            :             ElapsedTime();
      58                 :            : 
      59                 :            :             /** Creates a new ElapsedTime object based on another
      60                 :            :                 timer.
      61                 :            : 
      62                 :            :                 The moment of construction starts the time
      63                 :            :                 measurement. That means, a subsequent getElapsedTime()
      64                 :            :                 call will return the time difference between object
      65                 :            :                 creation and getElapsedTime() call. All time values
      66                 :            :                 are not taken from the system's time base, but from
      67                 :            :                 the provided timer.
      68                 :            :              */
      69                 :            :             ElapsedTime( ::boost::shared_ptr<ElapsedTime> const & pTimeBase );
      70                 :            : 
      71                 :            :             /** Reset the time
      72                 :            : 
      73                 :            :                 The instance of the reset() call starts the time
      74                 :            :                 measurement from scratch. That means, a subsequent
      75                 :            :                 getElapsedTime() call will return the time difference
      76                 :            :                 between reset() and getElapsedTime() call.
      77                 :            :              */
      78                 :            :             void reset();
      79                 :            : 
      80                 :            :             /** Query the elapsed time
      81                 :            : 
      82                 :            :                 This method returns the elapsed time in seconds
      83                 :            :                 between either the construction of this object, or the
      84                 :            :                 last reset() call, if any (but see the time modulation
      85                 :            :                 methods below, for means to modify the otherwise
      86                 :            :                 continuous flow of time).
      87                 :            : 
      88                 :            :                 @return the elapsed time in seconds.
      89                 :            :              */
      90                 :            :             double getElapsedTime() const;
      91                 :            : 
      92                 :            :             /** Pauses the running timer.
      93                 :            : 
      94                 :            :                 This method stops the time, as returned by this
      95                 :            :                 object, until continueTimer() is called. During this
      96                 :            :                 period, getElapsedTime() will always return the same
      97                 :            :                 time value (i.e. the instant when pauseTimer() was
      98                 :            :                 called).
      99                 :            :              */
     100                 :            :             void pauseTimer();
     101                 :            : 
     102                 :            :             /** Continues the paused timer.
     103                 :            : 
     104                 :            :                 This method re-enables the time flow, that is, time
     105                 :            :                 starts running again for clients calling
     106                 :            :                 getElapsedTime(). The (subtle) difference to the
     107                 :            :                 holdTimer/releaseTimer() methods below is, that there
     108                 :            :                 is no perceived time 'jump' between the pauseTimer()
     109                 :            :                 call and the continueTimer() call, i.e. the time
     110                 :            :                 starts over with the same value it has stopped on
     111                 :            :                 pauseTimer().
     112                 :            :              */
     113                 :            :             void continueTimer();
     114                 :            : 
     115                 :            :             /** Adjusts the timer, hold and pause times.
     116                 :            : 
     117                 :            :                 This method modifies the time as returned by this
     118                 :            :                 object by the specified amount. This affects the time
     119                 :            :                 as returned by getElapsedTime(), regardless of the
     120                 :            :                 mode (e.g. paused, or on hold).
     121                 :            : 
     122                 :            :                 @param fOffset
     123                 :            :                 This value will be added to the current time, i.e. the
     124                 :            :                 next call to getElapsedTime() (when performed
     125                 :            :                 immediately) will be adjusted by fOffset.
     126                 :            : 
     127                 :            :                 @param bLimitToLastQueriedTime
     128                 :            :                 Limits the given offset to the time that has been
     129                 :            :                 taken via getElapsedTime()
     130                 :            :             */
     131                 :            :             void adjustTimer( double fOffset,
     132                 :            :                               bool bLimitToLastQueriedTime = true );
     133                 :            : 
     134                 :            :             /** Holds the current time.
     135                 :            : 
     136                 :            :                 This call makes the timer hold the current time
     137                 :            :                 (e.g. getElapsedTime() will return the time when
     138                 :            :                 holdTimer() was called), while the underlying time is
     139                 :            :                 running on. When releaseTimer() is called, the time
     140                 :            :                 will 'jump' to the then-current, underlying time. This
     141                 :            :                 is equivalent to pressing the "interim time" button on
     142                 :            :                 a stop watch, which shows this stopped time, while the
     143                 :            :                 clock keeps running internally.
     144                 :            :             */
     145                 :            :             void holdTimer();
     146                 :            : 
     147                 :            :             /** Releases a held timer.
     148                 :            : 
     149                 :            :                 After this call, the timer again returns the running
     150                 :            :                 time on getElapsedTime().
     151                 :            :              */
     152                 :            :             void releaseTimer();
     153                 :            : 
     154                 :            :         private:
     155                 :            :             static double getSystemTime();
     156                 :            :             double getCurrentTime() const;
     157                 :            :             double getElapsedTimeImpl() const; // does not set m_fLastQueriedTime
     158                 :            : 
     159                 :            :             const ::boost::shared_ptr<ElapsedTime>  m_pTimeBase;
     160                 :            : 
     161                 :            :             /// To validate adjustTimer() calls with bLimitToLastQueriedTime=true
     162                 :            :             mutable double                          m_fLastQueriedTime;
     163                 :            : 
     164                 :            :             /// Start time, from which the difference to the time base is returned
     165                 :            :             double                                  m_fStartTime;
     166                 :            : 
     167                 :            :             /// Instant, when last pause or hold started, relative to m_fStartTime
     168                 :            :             double                                  m_fFrozenTime;
     169                 :            : 
     170                 :            :             /// True, when in pause mode
     171                 :            :             bool                                    m_bInPauseMode;
     172                 :            : 
     173                 :            :             /// True, when in hold mode
     174                 :            :             bool                                    m_bInHoldMode;
     175                 :            :         };
     176                 :            : 
     177                 :            :     }
     178                 :            : }
     179                 :            : 
     180                 :            : #endif /* INCLUDED_CANVAS_ELAPSEDTIME_HXX */
     181                 :            : 
     182                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10