PixelLightAPI  .
Stopwatch.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Stopwatch.h                                    *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_STOPWATCH_H__
00024 #define __PLCORE_STOPWATCH_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/PLCore.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    Stopwatch
00046 *
00047 *  @verbatim
00048 *    Usage example:
00049 *
00050 *    // Start the stopwatch
00051 *    Stopwatch cStopwatch(true);
00052 *
00053 *    // Do some stuff
00054 *
00055 *    // Measure elapsed time
00056 *    float fElapsedSeconds = cStopwatch.GetSeconds();
00057 *  @endverbatim
00058 *
00059 *  @note
00060 *    - The stopwatch implementation is just using "System::GetInstance()->GetMicroseconds()" and is therefore quite lightweight
00061 */
00062 class Stopwatch {
00063 
00064 
00065     //[-------------------------------------------------------]
00066     //[ Public functions                                      ]
00067     //[-------------------------------------------------------]
00068     public:
00069         /**
00070         *  @brief
00071         *    Default constructor
00072         */
00073         inline Stopwatch();
00074 
00075         /**
00076         *  @brief
00077         *    Constructor
00078         *
00079         *  @param[in] bStartAtOnce
00080         *    If this parameter is 'true', the stopwatch is started automatically at once
00081         */
00082         inline Stopwatch(bool bStartAtOnce);
00083 
00084         /**
00085         *  @brief
00086         *    Destructor
00087         */
00088         inline ~Stopwatch();
00089 
00090         /**
00091         *  @brief
00092         *    Starts the stopwatch
00093         *
00094         *  @note
00095         *    - If the stopwatch is already running it's restarted
00096         */
00097         PLCORE_API void Start();
00098 
00099         /**
00100         *  @brief
00101         *    Stops the stopwatch
00102         *
00103         *  @return
00104         *    The elapsed time in microseconds since Start()
00105         *
00106         *  @note
00107         *    - Often it's adequate to just request the past time using
00108         *      e.g. "GetMilliseconds()" and not explicitly stopping the stopwatch
00109         */
00110         PLCORE_API uint64 Stop();
00111 
00112         /**
00113         *  @brief
00114         *    Returns the number of weeks since the stopwatch was started
00115         *
00116         *  @return
00117         *    Number of weeks elapsed since the stopwatch was started
00118         */
00119         inline float GetWeeks() const;
00120 
00121         /**
00122         *  @brief
00123         *    Returns the number of days since the stopwatch was started
00124         *
00125         *  @return
00126         *    Number of days elapsed since the stopwatch was started
00127         */
00128         inline float GetDays() const;
00129 
00130         /**
00131         *  @brief
00132         *    Returns the number of hours since the stopwatch was started
00133         *
00134         *  @return
00135         *    Number of hours elapsed since the stopwatch was started
00136         */
00137         inline float GetHours() const;
00138 
00139         /**
00140         *  @brief
00141         *    Returns the number of minutes since the stopwatch was started
00142         *
00143         *  @return
00144         *    Number of minutes elapsed since the stopwatch was started
00145         */
00146         inline float GetMinutes() const;
00147 
00148         /**
00149         *  @brief
00150         *    Returns the number of seconds since the stopwatch was started
00151         *
00152         *  @return
00153         *    Number of seconds elapsed since the stopwatch was started
00154         */
00155         inline float GetSeconds() const;
00156 
00157         /**
00158         *  @brief
00159         *    Returns the number of milliseconds since the stopwatch was started
00160         *
00161         *  @return
00162         *    Number of milliseconds elapsed since the stopwatch was started
00163         */
00164         inline float GetMilliseconds() const;
00165 
00166         /**
00167         *  @brief
00168         *    Retrieves the number of microseconds since the stopwatch was started
00169         *
00170         *  @return
00171         *    Number of microseconds elapsed since the stopwatch was started
00172         */
00173         PLCORE_API uint64 GetMicroseconds() const;
00174 
00175 
00176     //[-------------------------------------------------------]
00177     //[ Private data                                          ]
00178     //[-------------------------------------------------------]
00179     private:
00180         bool   m_bRunning;  /**< Is the stopwatch currently running? */
00181         uint64 m_nStart;    /**< Stopwatch start time (microseconds) */
00182         uint64 m_nStop;     /**< Stopwatch stop time (microseconds) */
00183 
00184 
00185 };
00186 
00187 
00188 //[-------------------------------------------------------]
00189 //[ Namespace                                             ]
00190 //[-------------------------------------------------------]
00191 } // PLCore
00192 
00193 
00194 //[-------------------------------------------------------]
00195 //[ Implementation                                        ]
00196 //[-------------------------------------------------------]
00197 #include "PLCore/Tools/Stopwatch.inl"
00198 
00199 
00200 #endif // __PLCORE_STOPWATCH_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:01
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported