forked from udacity/CppND-System-Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
56 lines (49 loc) · 1.18 KB
/
util.h
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
#ifndef UTIL_H
#define UTIL_H
#include<string>
#include<fstream>
class Util
{
public:
static std::string convertToTime(long int input_seconds);
static std::string getProgressBar(std::string percent);
static std::ifstream getStream(std::string path);
};
std::string Util::convertToTime(long int input_seconds)
{
long minutes = input_seconds/60;
long hours = minutes/60;
long seconds = input_seconds%60;
minutes = minutes%60;
std::string result = std::to_string(hours) + ":" + std::to_string(minutes) + ":" + std::to_string(seconds);
return result;
}
std::string Util::getProgressBar(std::string percent)
{
std::string result = "0% ";
int _size = 50;
int boundaries = (stof(percent)/100)*_size;
for(int i = 0; i < _size; i++)
{
if (i < boundaries)
{
result += "|";
}
else
{
result +=" ";
}
}
result += " " + percent.substr(0,4) + "/100%";
return result;
}
std::ifstream Util::getStream(std::string path)
{
std::ifstream stream(path);
if(!stream)
{
throw std::runtime_error("Non-exisiting PID");
}
return stream;
}
#endif