-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
102 lines (73 loc) · 1.85 KB
/
utils.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
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
#ifndef UTILS_H
#define UTILS_H
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <chrono>
#include <mpi.h>
// trim from start
std::string <rim(std::string &s);
// trim from end
std::string &rtrim(std::string &s);
// trim from both ends
std::string &trim(std::string &s);
std::string getCurrentDir();
// display vectors
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
out << "[";
typename std::vector<T>::const_iterator first = v.cbegin();
typename std::vector<T>::const_iterator last = v.cend();
while (first < last) {
out << *first;
++first;
if (first < last) {
out << ", ";
}
}
out << "]";
return out;
}
// display set
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::set<T> &v) {
out << "{";
typename std::set<T>::const_iterator first = v.cbegin();
typename std::set<T>::const_iterator last = v.cend();
while (first < last) {
out << *first;
++first;
if (first < last) {
out << ", ";
}
}
out << "}";
return out;
}
// display pairs
template<typename T, typename U>
std::ostream &operator<<(std::ostream &out, const std::pair<T, U> &v) {
out << "<" << v.first << "," << v.second << ">";
return out;
}
std::string ssystem(std::string cmds);
std::string recv_string(int src, MPI_Status *status);
std::string recv_file(int src, MPI_Status *status);
std::string to_string(int i);
void debug(std::string msg);
void error(std::string msg);
void send_file(int dest, std::string file_name);
int m_stoi(std::string s);
void timet(std::string msg, std::chrono::high_resolution_clock::duration dtn);
void time(std::string msg);
void bench(std::string msg, long value);
inline bool file_exists (const std::string& name) {
if (FILE *file = fopen(name.c_str(), "r")) {
fclose(file);
return true;
} else {
return false;
}
}
#endif