/
solution.hpp
160 lines (140 loc) · 3.59 KB
/
solution.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef SOLUTION_H
#define SOLUTION_H
#include <iomanip>
#include <ctime>
#include <string>
#include <sstream>
enum SolveFlag
{
NONE,
PLUS2,
DNF,
NA
};
class Solution
{
private:
time_t m_start;
time_t m_end;
std::string m_scramble;
std::string m_comment;
public:
Solution(time_t start, time_t end = 0, std::string scramble = "", std::string comment = "") :
m_start(start), m_end(end), m_scramble(scramble), m_comment(comment) {}
virtual ~Solution() {}
//////////////////////
//------------------//
// Inline functions //
//------------------//
/////////////////////
/**
* @brief Gets the start of the solve.
* @return The starting time of the solution in UNIX time.
*/
time_t getStart() const
{
return m_start;
}
/**
* @brief Sets the starting time of the solve.
* @param start The starting time of the solution in UNIX time.
*/
void setStart(time_t start)
{
m_start = start;
}
/**
* @brief Gets the end of the solve.
* @return The end time of the solution in UNIX time.
*/
time_t getEnd() const
{
return m_end;
}
/**
* @brief Sets the end time of the solve.
* @param end The end time of the solution in UNIX time.
*/
void setEnd(time_t end)
{
m_end = end;
}
/**
* @brief Gets the scramble string of the solve.
* @return The scramble string of the solve.
*/
std::string getScramble() const
{
return m_scramble;
}
/**
* @brief Sets the scramble string of this solve.
* @param scramble The scramble string for this solve.
*/
void setScramble(std::string scramble)
{
m_scramble = scramble;
}
/**
* @brief Gets the comment for the solve (if any).
* @return The comment for this solve.
*/
std::string getComment() const
{
return m_comment;
}
/**
* @brief Sets the comment string for the solve. This can contain anything.
* @param comment The string to be used as a comment. It can be empty.
*/
void setComment(std::string comment)
{
m_comment = comment;
}
/**
* @brief Returns the time of this solve (end - start).
* @return The time in ms for this solve.
*/
long int getTime() const
{
if (m_end != 0)
{
return m_end - m_start;
}
else
{
// TODO
throw "Unimplemented stuff in Solution::getTime()!!!";
}
}
/**
* @brief TimeToString Method to convert the time to some good-looking string.
* @return A std::string representing the time in HH:MM:SS.MM format.
* The starting HH:MM: part is left out if not needed.
*/
std::string toString() const
{
return TimeToString(getTime());
}
static std::string TimeToString(long int time)
{
long int hour, min, sec, ms;
ms = time % 1000;
hour = time / (1000 * 60 * 60);
min = (time - hour * 1000 * 60 * 60) / (1000 * 60);
sec = (time - hour * 1000 * 60 * 60 - min * 1000 * 60) / 1000;
std::stringstream t_str;
if (hour)
{
t_str << std::setw(2) << std::setfill('0') << hour << ":";
}
if (min || hour)
{
t_str << std::setw(2) << std::setfill('0') << min << ":";
}
t_str << std::setw(2) << std::setfill('0') << sec << "."
<< std::setw(2) << std::setfill('0') << ms / 10;
return t_str.str().c_str();
}
};
#endif // SOLUTION_H