This repository was archived by the owner on Sep 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpFunctions.h
More file actions
81 lines (71 loc) · 1.49 KB
/
helpFunctions.h
File metadata and controls
81 lines (71 loc) · 1.49 KB
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
#ifndef __HELP_FUNC__
#define __HELP_FUNC__
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
bool fileExists(string path) {
FILE* handle = fopen(path.c_str(), "r");
if(handle == nullptr) {
return false;
}
fclose(handle);
return true;
}
string tostring(int number) {
stringstream ss;
ss << number;
return ss.str();
}
string tostring(float number) {
stringstream ss;
ss << number;
return ss.str();
}
float str2float(string str) {
#if __unix__
return stof(str);
#else
return atof(str.c_str());
#endif
}
bool startsWith(const string& haystack, const string& needle) {
return needle.length() <= haystack.length()
&& equal(needle.begin(), needle.end(), haystack.begin());
}
bool endsWith(const string& haystack, const string& needle) {
return needle.length() <= haystack.length()
&& equal(needle.rbegin(), needle.rend(), haystack.rbegin());
}
string tolower(string in) {
string ret = in;
transform(in.begin(), in.end(), ret.begin(),
[](unsigned char c) -> unsigned char {
return tolower(c);
}
);
return ret;
}
void processingBar(unsigned int value, unsigned int max) {
if(value == 0) {
cout << "Processing[";
for(unsigned int p = 0; p < max; ++p) {
cout << '_';
}
cout << ']' << flush;
return;
}
cout << "\rProcessing[";
for(unsigned int p = 0; p < value; ++p) {
cout << '|';
}
cout << flush;
}
template<class T> void wipeVector(vector<T*>& list) {
for(T* element : list) {
delete element;
}
list.clear();
}
#endif