-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathaaron_utils.cpp
More file actions
39 lines (28 loc) · 877 Bytes
/
aaron_utils.cpp
File metadata and controls
39 lines (28 loc) · 877 Bytes
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
#include "aaron_utils.hpp"
int testForError(FILE *x) { return x == NULL; }
int testForError(int x) { return x == -1; }
string show(long x) {
ostringstream s;
s << x;
return s.str();
}
string show(const char *x) {
ostringstream s;
s << x;
return s.str();
}
string show(const string &s) { return s; }
runningAverage::runningAverage() : total(0), n(0) {}
void runningAverage::operator()(long int i) {
total += i;
if (total < 0) Die("total overflowed %ld", i);
n++;
}
string runningAverage::operator()(void) const {
ostringstream o;
o << "Average Time (" << n << " points)" << ": " << (double) total / (double) n;
return o.str();
}
DummyOutputStream &DummyOutputStream::operator<<(int) { return *this; }
DummyOutputStream &DummyOutputStream::operator<<(const char *) { return *this; }
DummyOutputStream dummyOutputStream;