MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
extendedtimer.h
1 //© Copyright 2010 - 2013 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 _extendedtimer_h
41 #define _extendedtimer_h
42 
43 #include "timer.h"
44 
45 namespace Mezzanine
46 {
47  ///////////////////////////////////////////////////////////////////////////////
48  /// @struct Time
49  /// @headerfile timer.h
50  /// @brief A container for the metrics of time relevant for the timer class.
51  ///////////////////////////////////////
52  struct Time
53  {
54  Integer Microseconds;
55  Integer Milliseconds;
56  Integer Seconds;
57  Integer Minutes;
58  Integer Hours;
59  Integer Days;
60 
61  Time() : Microseconds(0),Milliseconds(0),Seconds(0),Minutes(0),Hours(0),Days(0) {};
62  ~Time() {};
63  };
64 
65  ///////////////////////////////////////////////////////////////////////////////
66  /// @class ExtendedTimer
67  /// @headerfile extendedtimer.h
68  /// @brief An enhanced timer class that can store and track many units of time.
69  /// @details This timer class should be used only for longer periods, such as tracking game uptime.
70  /// For shorter periods of time look at the SimpleTimer class.
71  ///////////////////////////////////////
72  class MEZZ_LIB ExtendedTimer : public Timer
73  {
74  public:
75  /// @brief The internal time struct to be used...
77  {
78  Current, ///< Current description
79  Goal, ///< Goal description
80  Initial ///< Initial description
81  };
82  protected:
83  Time CurrentTime;
84  Time GoalTime;
85  Time InitialTime;
86  virtual Time& GetStruct(const ExtendedTimer::TimeStruct Struct);
87  virtual void Update(const Whole MicroSecondsElapsed);
88  virtual void UpdateAsNormal(const Whole MicroSecondsElapsed);
89  virtual void UpdateAsStopWatch(const Whole MicroSecondsElapsed);
90  virtual bool CheckMicroSeconds(const ExtendedTimer::TimeStruct Struct);
91  virtual bool CheckMilliSeconds(const ExtendedTimer::TimeStruct Struct);
92  virtual bool CheckSeconds(const ExtendedTimer::TimeStruct Struct);
93  virtual bool CheckMinutes(const ExtendedTimer::TimeStruct Struct);
94  virtual bool CheckHours(const ExtendedTimer::TimeStruct Struct);
95  virtual bool CheckDays(const ExtendedTimer::TimeStruct Struct);
96  virtual bool CheckAll(const ExtendedTimer::TimeStruct Struct);
97  virtual bool CompareCurrentAndGoal(const Integer Current, const Integer Goal);
98  virtual bool GoalReached();
99  public:
100  /// @brief Standard Constructor.
101  /// @param style The styling/type of timer to be constructed.
102  ExtendedTimer(const Timer::TimerStyle style);
103  /// @brief Class destructor.
104  virtual ~ExtendedTimer();
105  /// @brief Sets the current values to their initial values.
106  virtual void Reset();
107  /// @brief Sets whether or not the Timer should reset if it reaches it's goal. @n
108  /// Ex. If a stopwatch reaches 0.
109  /// @return Returns a reference to this timer.
110  virtual ExtendedTimer& SetAutoReset(const bool AutoReset);
111  /// @brief Sets the value for Microseconds of the specified struct.
112  /// @details If a number greater then 999 is passed in, it will be reduced to 999.
113  /// @return Returns a reference to this timer.
114  /// @param MS The number of Microseconds to set.
115  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
116  virtual ExtendedTimer& SetMicroseconds(Integer MS, const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
117  /// @brief Sets the value for Milliseconds of the specified struct.
118  /// @details If a number greater then 999 is passed in, it will be reduced to 999.
119  /// @return Returns a reference to this timer.
120  /// @param MS The number of Milliseconds to set.
121  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
122  virtual ExtendedTimer& SetMilliseconds(Integer MS, const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
123  /// @brief Sets the value for Seconds of the specified struct.
124  /// @details If a number greater then 59 is passed in, it will be reduced to 59.
125  /// @return Returns a reference to this timer.
126  /// @param Sec The number of Seconds to set.
127  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
128  virtual ExtendedTimer& SetSeconds(Integer Sec, const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
129  /// @brief Sets the value for Minutes of the specified struct.
130  /// @details If a number greater then 59 is passed in, it will be reduced to 59.
131  /// @return Returns a reference to this timer.
132  /// @param Min The number of Minutes to set.
133  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
134  virtual ExtendedTimer& SetMinutes(Integer Min, const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
135  /// @brief Sets the value for Hours of the specified struct.
136  /// @details If a number greater then 23 is passed in, it will be reduced to 23.
137  /// @return Returns a reference to this timer.
138  /// @param Hr The number of Hours to set.
139  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
140  virtual ExtendedTimer& SetHours(Integer Hr, const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
141  /// @brief Sets the value for Days of the specified struct.
142  /// @return Returns a reference to this timer.
143  /// @param Day The number of Days to set.
144  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
145  virtual ExtendedTimer& SetDays(Integer Day, const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
146  /// @brief Gets the current internal Millisecond count.
147  /// @return Returns an Integer representing the current Millisecond count of this Timer.
148  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
149  virtual Integer GetMilliseconds(const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
150  /// @brief Gets the current internal Second count.
151  /// @return Returns an Integer representing the current Second count of this Timer.
152  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
153  virtual Integer GetSeconds(const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
154  /// @brief Gets the current internal Minute count.
155  /// @return Returns an Integer representing the current Minute count of this Timer.
156  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
157  virtual Integer GetMinutes(const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
158  /// @brief Gets the current internal Hour count.
159  /// @return Returns an Integer representing the current Hour count of this Timer.
160  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
161  virtual Integer GetHours(const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
162  /// @brief Gets the current internal Day count.
163  /// @return Returns an Integer representing the current Day count of this Timer.
164  /// @param Struct The Kind of TimeStructure this timer should use, defaults to ExtendedTimer::Current
165  virtual Integer GetDays(const ExtendedTimer::TimeStruct Struct = ExtendedTimer::Current);
166  };
167 }
168 
169 #endif