zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Chronometer.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
30 #ifndef ZENI_CHRONOMETER_H
31 #define ZENI_CHRONOMETER_H
32 
33 /* \cond */
34 #include <set>
35 /* \endcond */
36 
37 namespace Zeni {
38 
39  template <class TIME>
40  class Chronometer {
41  public:
42  Chronometer();
43  ~Chronometer();
44 
45  Chronometer(const Chronometer<TIME> &rhs);
47 
48  // Starting and Stopping
49  const bool & is_running() const;
50  const TIME & start();
51  const TIME & stop();
52 
53  // Time Accessor and Modifiers
54  typename TIME::Second_Type seconds() const;
55  void set(const typename TIME::Second_Type &time);
56  void reset();
57 
58  // Scaling
59  const typename TIME::Second_Type & scaling_factor() const;
60  void scale(const typename TIME::Second_Type &scaling_factor = typename TIME::Second_Type(1));
61 
62  private:
63  typename TIME::Second_Type m_seconds_counted;
64 
65  TIME m_start_time;
66  TIME m_end_time;
67  bool m_running;
68 
69  typename TIME::Second_Type m_scaling_factor;
70 
71  public:
72  static bool are_paused();
73  static void pause_all();
74  static void unpause_all();
75 
76  private:
77  static std::set<Chronometer<TIME> *> & get_chronometers();
78  static std::set<Chronometer<TIME> *> & get_paused();
79  static bool g_are_paused;
80  };
81 
82 }
83 
84 #endif
Chronometer & operator=(const Chronometer< TIME > &rhs)
Definition: Chronometer.hxx:59
void scale(const typename TIME::Second_Type &scaling_factor=typename TIME::Second_Type(1))
Scale the amount of time that passes by some amount.
void set(const typename TIME::Second_Type &time)
Set the number of seconds counted by the Chronometer.
const TIME::Second_Type & scaling_factor() const
Get the scaling factor.
static void pause_all()
Pause all Chronometer&lt;TIME&gt; objects.
const bool & is_running() const
Get whether the Chronometer is currently counting or stopped.
Definition: Chronometer.hxx:76
const TIME & stop()
Stop the Chronometer and get the current TIME.
Definition: Chronometer.hxx:97
Definition: inflate.h:23
A stoppable running timer.
Definition: Chronometer.h:40
static bool are_paused()
Check to see if all Chronometer&lt;TIME&gt; objects are paused.
void reset()
Reset the Chronometer. This does NOT stop the Chronometer.
TIME::Second_Type seconds() const
Get the number of seconds counted by the Chronometer.
const TIME & start()
Start the Chronometer and get the current TIME. This does NOT reset the Chronometer.
Definition: Chronometer.hxx:81
static void unpause_all()
Unpause all Chronometer&lt;TIME&gt; objects.