-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.h
95 lines (89 loc) · 2.14 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
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
const int data_pos = 60;
inline void date_time(ostream &o) {
long t = time(0);
o << ctime(&t) << endl;
}
inline void out_char (ostream &o, char ch, int count) {
o << string (count, ch);
}
inline bool get_bool (istream &i, int pos = data_pos) {
string line;
getline (i, line);
bool b;
string data (line, pos);
istringstream(data) >> b;
return b;
}
inline int get_int (istream &i, int pos = data_pos) {
string line;
getline (i, line);
int n;
string data (line, pos);
istringstream(data) >> n;
return n;
}
inline double get_double (istream &i, int pos = data_pos) {
string line;
getline (i, line);
double d;
string data (line, pos);
istringstream(data) >> d;
return d;
}
inline void omit_line (istream &i) {
string line;
getline (i, line);
}
inline void ivar(ostream &o, string sname_p, int kvalue_p, string smean_p) {
o.setf(ios::left, ios::adjustfield);
o << setw (12) << sname_p;
o.setf(ios::right, ios::adjustfield);
o << setw (13) << kvalue_p;
o.fill ('.');
o << setw (45) << smean_p;
o.fill (' ');
o << endl;
}
inline void lvar(ostream &o, string sname_p, long kvalue_p, string smean_p) {
o.setf(ios::left, ios::adjustfield);
o << setw (12) << sname_p;
o.setf(ios::right, ios::adjustfield);
o << setw (13) << kvalue_p;
o.fill ('.');
o << setw (45) << smean_p;
o.fill (' ');
o << endl;
}
inline void rvar(ostream &o, string sname_p, double dvalue_p, string smean_p) {
o.setf(ios::left, ios::adjustfield);
o << setw (12) << sname_p;
o.setf(ios::right, ios::adjustfield);
o << setw (13) << dvalue_p;
o.fill ('.');
o << setw (45) << smean_p;
o.fill (' ');
o << endl;
}
inline void open_failure (ostream &o, char *s) {
o << "Cannot open " << s << " file" << endl;
exit(1);
}
inline void error (ostream &o, const char *s) {
o << "Error: " << s << endl;
exit(1);
}
inline void blines (ostream &o, int n = 1) {
for (int i = 0; i < n; i++) o << endl;
}
inline void page (ostream &o) {
o << endl << (char) 12 << endl;
}
inline double max (double a, double b) {
return (a >= b) ? a : b;
}
inline double min (double a, double b) {
return (a <= b) ? a : b;
}
inline double sign (double a, double b) {
return (b >= 0) ? fabs(a) : -fabs(a);
}