-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathverbosity.cpp
More file actions
57 lines (53 loc) · 1.38 KB
/
verbosity.cpp
File metadata and controls
57 lines (53 loc) · 1.38 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
#include "verbosity.hpp"
#include <stdexcept>
using namespace std;
string to_string(Verbosity verb) {
switch (verb) {
case Verbosity::everything:
return "everything";
case Verbosity::trace:
return "trace";
case Verbosity::debug:
return "debug";
case Verbosity::verbose:
return "verbose";
case Verbosity::info:
return "info";
case Verbosity::warning:
return "warning";
case Verbosity::error:
return "error";
case Verbosity::fatal:
return "fatal";
default:
throw logic_error("Implementation of to_string(Verbosity) incomplete!");
}
}
Verbosity verbosity = Verbosity::info;
ostream &operator<<(ostream &os, Verbosity verb) {
os << to_string(verb);
return os;
}
istream &operator>>(istream &is, Verbosity &verb) {
string token;
is >> token;
if (token == "everything")
verb = Verbosity::everything;
else if (token == "trace")
verb = Verbosity::trace;
else if (token == "debug")
verb = Verbosity::debug;
else if (token == "verbose")
verb = Verbosity::verbose;
else if (token == "info")
verb = Verbosity::info;
else if (token == "warning")
verb = Verbosity::warning;
else if (token == "error")
verb = Verbosity::error;
else if (token == "fatal")
verb = Verbosity::fatal;
else
throw runtime_error("Error: unkown verbosity level '" + token + "'.");
return is;
}