Timer Console
Loading...
Searching...
No Matches
timerData.h
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2025 Ryan Large
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#ifndef TIMER_DATA_H
26#define TIMER_DATA_H
27
28#include <chrono>
29
33class TimerData {
34 public:
35 bool index;
36
40 struct Times {
41 int hours;
45
46 Times(const int& h, const int& m, const int& s, const int& mill): hours(h),
47 minutes(m),
48 seconds(s),
49 milliseconds(mill) {};
50 };
51
57 TimerData(const int& i);
58
63 void setTime(const int& hours, const int& minutes, const int& seconds);
64
71 void start();
72
77 void pause();
78
85 void reset();
86
91 bool isComplete();
92 std::chrono::milliseconds getTimeRemaining();
93
97 void printRemainingTime();
98
104 void setIndex(const int& newIndex);
105
109 bool getIsPaused();
110
114 bool getIsRunning();
115
120 std::vector < Times > getTimes();
121
122 protected:
123
124 private:
125 std::chrono::milliseconds duration;
126 std::chrono::steady_clock::time_point startTime;
127 std::chrono::steady_clock::duration elapsedTime;
129 bool paused;
130};
131
132#endif
void reset()
reset method updates paused and running g member variables and sets the elapsedTime to 0
Definition timerData.cpp:65
std::chrono::milliseconds duration
Definition timerData.h:125
bool running
Definition timerData.h:128
bool isComplete()
isComplete method returns a true or false depending on if getTimeRemaining returns a value less than ...
Definition timerData.cpp:73
bool index
Definition timerData.h:35
void setTime(const int &hours, const int &minutes, const int &seconds)
setTime method sets the initial time on creation when called from Timer class.
Definition timerData.cpp:36
void pause()
pause stops the timer and calculates the elapsed time to update it
Definition timerData.cpp:54
void setIndex(const int &newIndex)
setIndex method changes the index of the timer depending on if the user moves the timer within the li...
Definition timerData.cpp:113
void printRemainingTime()
printRemainingTime method prints the timer to the console in a user friendly way and in the correctly...
Definition timerData.cpp:93
bool getIsPaused()
getIsPaused tells the caller of the method if the timer is counting down
Definition timerData.cpp:121
TimerData(const int &i)
Definition timerData.cpp:33
bool paused
Definition timerData.h:129
std::vector< Times > getTimes()
getTimes method returns the time of the timer as a Times structure
Definition timerData.cpp:125
void start()
start method updates paused and running member methods to start counting time and updates the startTi...
Definition timerData.cpp:41
std::chrono::steady_clock::time_point startTime
Definition timerData.h:126
std::chrono::milliseconds getTimeRemaining()
Definition timerData.cpp:78
bool getIsRunning()
getIsRunning tells the caller of the method if the timer is counting down
Definition timerData.cpp:117
std::chrono::steady_clock::duration elapsedTime
Definition timerData.h:127
int hours
Definition timerData.h:41
Times(const int &h, const int &m, const int &s, const int &mill)
Definition timerData.h:46
int milliseconds
Definition timerData.h:44
int seconds
Definition timerData.h:43
int minutes
Definition timerData.h:42