-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stream.h
67 lines (51 loc) · 1.22 KB
/
Stream.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
#pragma once
struct Endl {};
template <typename DerivedType>
class WriteStream {
public:
template <typename... Types>
void write(Types... args);
template <typename Type>
void write(Type arg);
template <typename Type, typename... Types>
void write(Type arg, Types... args) {
write(arg);
write(args...);
}
template <typename... Types>
void writeln(Types... args) {
write(args...);
write("\n");
}
void write(const char* arg) {
write(AW::StringBuf(arg));
}
void write(const String& arg) {
write(AW::StringBuf(arg.c_str(), arg.length()));
}
void write(unsigned long arg) {
write(String(arg));
}
void write(double arg) {
write(String(arg));
}
void write(float arg) {
write(String(arg));
}
void write(AW::StringBuf arg) {
static_cast<DerivedType*>(this)->send(arg);
}
WriteStream& operator <<(const char* arg) {
write(arg);
return *this;
}
WriteStream& operator <<(double arg) {
write(arg);
return *this;
}
WriteStream& operator <<(Endl) {
write("\r\n");
return *this;
}
};
extern Endl endl;