-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
37 lines (28 loc) · 891 Bytes
/
utils.cpp
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
#include "utils.h"
void Timer::start() {
startTime = getTime();
}
int Timer::stop() {
return getTime() - startTime;
}
unsigned long long Timer::getTime() {
return (unsigned long long)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
std::vector<std::string> splitString(const std::string &s, const std::string &delimiter) {
size_t lastPos = 0;
size_t pos = 0;
std::vector<std::string> res;
pos = s.find(delimiter, lastPos);
while (pos != std::string::npos) {
res.push_back(s.substr(lastPos, pos - lastPos));
lastPos = pos + delimiter.length();
pos = s.find(delimiter, lastPos);
}
res.push_back(s.substr(lastPos));
return res;
}
float clip(float n, float min, float max) {
if (n < min) return min;
if (n > max) return max;
return n;
}