forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchableOutput.h
77 lines (64 loc) · 1.18 KB
/
SwitchableOutput.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
/*
* OutputRedirection.h
*
*/
#ifndef TOOLS_SWITCHABLEOUTPUT_H_
#define TOOLS_SWITCHABLEOUTPUT_H_
#include <iostream>
#include <fstream>
using namespace std;
class SwitchableOutput
{
ostream* out;
public:
SwitchableOutput(bool on = true)
{
activate(false);
activate(on);
}
void activate(bool on)
{
if (on)
{
if (out == 0)
out = &cout;
}
else
out = 0;
}
void redirect_to_file(ofstream& out_file)
{
out = &out_file;
}
template<class T>
SwitchableOutput& operator<<(const T& value)
{
if (out)
*out << value;
return *this;
cout << flush;
}
SwitchableOutput& operator<<(ostream& (*__pf)(ostream&))
{
if (out)
*out << __pf;
return *this;
}
void fill(char c)
{
if (out)
out->fill(c);
}
void width(streamsize w)
{
if (out)
out->width(w);
}
template<class T>
void signed_output(const T& x)
{
if (out)
x.output(*out, true, true);
}
};
#endif /* TOOLS_SWITCHABLEOUTPUT_H_ */