-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmadmop.hh
57 lines (47 loc) · 1.12 KB
/
xmadmop.hh
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
#pragma once
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
using namespace std::literals;
constexpr inline std::string_view version{"xmadmop 0.0.0"};
constexpr inline std::string_view help_msg{
"usage: xmadmop [-options ...]\n"
"\n"
"where options include:\n"
" -help print this usage message\n"
" -version print program version\n"};
struct Context {
bool show_help = false;
bool show_version = false;
bool has_err = false;
};
class Logger {
protected:
std::stringstream ss;
std::ostream& os;
public:
Logger(std::ostream& os): os{os} { ss << "xmadmop: "; }
~Logger() { os << ss.str() << '\n'; }
};
class Log: public Logger {
public:
Log(): Logger{std::cout} {}
template<typename T>
auto operator<<(T&& val) -> Log& {
ss << std::forward<T>(val);
return *this;
}
};
class Err: public Logger {
public:
Err(): Logger{std::cerr} {}
template<typename T>
auto operator<<(T&& val) -> Err& {
ss << std::forward<T>(val);
return *this;
}
};