MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
timer.h
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU 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  The Mezzanine Engine 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 General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _timer_h
41 #define _timer_h
42 
43 #include "datatypes.h"
44 
45 namespace Mezzanine
46 {
47  ///////////////////////////////////////////////////////////////////////////////
48  /// @class Timer
49  /// @headerfile timer.h
50  /// @brief A base timer class for the different timers.
51  /// @details
52  ///////////////////////////////////////
54  {
55  public:
56  /// @brief The style of timer to be used.
57  enum TimerType
58  {
59  Normal, ///< Counts up forever, ignoring any goal and autoreset
60  StopWatch, ///< Counts down, respecting any goal and autoreset
61  Alarm ///< Counts up, respecting any goal and autoreset
62  };
63  protected:
64  /// @internal
65  /// @brief The time stamp from when the timer first started tracking time.
67  /// @internal
68  /// @brief The current amount of microseconds that has elapsed since starting to track time.
70  /// @internal
71  /// @brief The amount of microseconds elapsed that is considered the starting point for tracking time.
73  /// @internal
74  /// @brief Updates all the timings in this timer.
75  virtual void Update();
76  public:
77  /// @brief Standard Constructor.
78  /// @param Style The styling/type of timer to be constructed.
79  Timer();
80  /// @brief Class Destructor.
81  virtual ~Timer();
82 
83  ///////////////////////////////////////////////////////////////////////////////
84  // Utility
85 
86  /// @brief Sets the current time in Microseconds.
87  /// @return Returns a reference to this timer.
88  /// @param Current The value to set as current time in Microseconds.
89  virtual void SetCurrentTime(const Whole Current);
90  /// @brief Sets the current time in Milliseconds. The time that resetting sets the timer to.
91  /// @return Returns a reference to this timer.
92  /// @param Current The value to set as current time in Milliseconds.
93  virtual void SetCurrentTimeInMilliseconds(const Whole Current);
94  /// @brief Gets the Current time in Microseconds.
95  /// @return Returns a Whole representing the current time in Microseconds.
96  virtual Whole GetCurrentTime();
97  /// @brief Gets the Current time in Milliseconds.
98  /// @return Returns a Whole representing the current time in Milliseconds.
99  virtual Whole GetCurrentTimeInMilliseconds();
100  /// @brief Sets the initial time in Microseconds. The time that resetting sets the timer to.
101  /// @return Returns a reference to this timer.
102  /// @param Initial The value to set as initial time in Microseconds.
103  virtual void SetInitialTime(const Whole Initial);
104  /// @brief Sets the initial time in Milliseconds. The time that resetting sets the timer to.
105  /// @return Returns a reference to this timer.
106  /// @param Initial The value to set as initial time in Milliseconds.
107  virtual void SetInitialTimeInMilliseconds(const Whole Initial);
108  /// @brief Gets the Initial time in Microseconds.
109  /// @return Returns a Whole representing the initial time in Microseconds.
110  virtual Whole GetInitialTime() const;
111  /// @brief Gets the Initial time in Milliseconds.
112  /// @return Returns a Whole representing the initial time in Milliseconds.
113  virtual Whole GetInitialTimeInMilliseconds() const;
114 
115  /// @brief Activates the Timer.
116  virtual void Start();
117  /// @brief Deactivates the Timer.
118  virtual void Stop();
119  /// @brief Gets Whether or not this timer is currently running.
120  /// @return Returns true if this timer is not currently active, false otherwise.
121  virtual Boolean IsStopped();
122  /// @brief Sets the current values to their initial values.
123  virtual void Reset();
124  /// @brief Gets the type of timer this is.
125  /// @return Returns an enum value representing the type of timer this is.
126  virtual Timer::TimerType GetType() const;
127  };//Timer
128 
129  ///////////////////////////////////////////////////////////////////////////////
130  /// @brief This is the base class for timers intended to run only until they reach a specific goal.
131  /// @details
132  ///////////////////////////////////////
133  class MEZZ_LIB GoalTimer : public Timer
134  {
135  protected:
136  /// @internal
137  /// @brief The time this timer should stop at.
139  /// @internal
140  /// @brief Wether or not this timer will reset itself when it reaches it's goal.
141  Boolean ResetAtGoal;
142  /// @internal
143  /// @brief Checks to see if the goal has been attained as dictated by the type of timer this is.
144  virtual Boolean GoalReached() = 0;
145  public:
146  /// @brief Class constructor.
147  GoalTimer();
148  /// @brief Class destructor.
149  virtual ~GoalTimer();
150 
151  ///////////////////////////////////////////////////////////////////////////////
152  // Utility
153 
154  /// @brief Sets whether or not this Timer should reset if it reaches it's goal.
155  /// @param AutoReset Should be true if you want this timer to reset itself back to it's initial time when it reaches it's goal.
156  virtual void SetAutoReset(const bool AutoReset);
157  /// @brief Gets whether or not this Timer will reset when it reaches it's goal.
158  /// @return Returns true if this timer will automatically reset when it reaches it's goal.
159  virtual Boolean GetAutoReset() const;
160 
161  /// @brief Sets the goal time in Microseconds.
162  /// @param Goal The value to set as goal time in Microseconds.
163  virtual void SetGoalTime(const Whole Goal);
164  /// @brief Sets the goal time in Milliseconds.
165  /// @param Goal The value to set as goal time in Milliseconds.
166  virtual void SetGoalTimeInMilliseconds(const Whole Goal);
167  /// @brief Gets the Goal time in Microseconds.
168  /// @return Returns a Whole representing the goal time in Microseconds.
169  virtual Whole GetGoalTime() const;
170  /// @brief Gets the Goal time in Milliseconds.
171  /// @return Returns a Whole representing the goal time in Milliseconds.
172  virtual Whole GetGoalTimeInMilliseconds() const;
173  };//GoalTimer
174 
175  ///////////////////////////////////////////////////////////////////////////////
176  /// @brief This is a timer class for counting down to a specified time.
177  /// @details
178  ///////////////////////////////////////
180  {
181  protected:
182  /// @copydoc Timer::Update()
183  virtual void Update();
184  /// @copydoc GoalTimer::GoalReached()
185  virtual Boolean GoalReached();
186  public:
187  /// @brief Class constructor.
188  StopWatchTimer();
189  /// @brief Class destructor.
190  virtual ~StopWatchTimer();
191 
192  ///////////////////////////////////////////////////////////////////////////////
193  // Utility
194 
195  /// @copydoc Timer::GetType() const
196  virtual Timer::TimerType GetType() const;
197  };//StopWatchTimer
198 
199  ///////////////////////////////////////////////////////////////////////////////
200  /// @brief This is a timer class that increments normally to a specified time.
201  /// @details
202  ///////////////////////////////////////
204  {
205  protected:
206  /// @copydoc Timer::Update()
207  virtual void Update();
208  /// @copydoc GoalTimer::GoalReached()
209  virtual Boolean GoalReached();
210  public:
211  /// @brief Class constructor.
212  AlarmTimer();
213  /// @brief Class destructor.
214  virtual ~AlarmTimer();
215 
216  ///////////////////////////////////////////////////////////////////////////////
217  // Utility
218 
219  /// @copydoc Timer::GetType() const
220  virtual Timer::TimerType GetType() const;
221  };//AlarmTimer
222 }//Mezzanine
223 
224 #endif