Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Timer.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Barbarian Group
3  All rights reserved.
4 
5  Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8  the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this list of conditions and
11  the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13  the following disclaimer in the documentation and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22  POSSIBILITY OF SUCH DAMAGE.
23 */
24 
25 #pragma once
26 
27 #include "cinder/Cinder.h"
28 
29 #if defined( CINDER_COCOA )
30  #include <CoreFoundation/CoreFoundation.h>
31 #endif
32 
33 namespace cinder {
34 
36 class Timer {
37  public:
39  Timer();
41  Timer( bool startOnConstruction );
42 
44  void start();
46  double getSeconds() const;
48  void stop();
49 
51  bool isStopped() const { return mIsStopped; }
52 
53  private:
54  bool mIsStopped;
55 #if defined( CINDER_COCOA )
56  ::CFAbsoluteTime mStartTime, mEndTime;
57 #elif (defined( CINDER_MSW ) || defined( CINDER_WINRT ))
58  double mStartTime, mEndTime, mInvNativeFreq;
59 #endif
60 };
61 
62 } // namespace cinder
Timer()
Constructs a default timer which is initialized as stopped.
Definition: Timer.cpp:33
double getSeconds() const
Returns the elapsed seconds if the timer is running, or the total time between calls to start() and s...
Definition: Timer.cpp:75
void start()
Begins timing.
Definition: Timer.cpp:62
bool isStopped() const
Returns whether the timer is currently running.
Definition: Timer.h:51
void stop()
Ends timing.
Definition: Timer.cpp:90
A high-resolution timer class.
Definition: Timer.h:36