SimpleKernel  0.0.1
ostream.hpp
Go to the documentation of this file.
1 
17 #ifndef SIMPLEKERNEL_OSTREAM_HPP
18 #define SIMPLEKERNEL_OSTREAM_HPP
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include "efi.h"
25 #include "efilib.h"
26 
27 #ifdef __cplusplus
28 }
29 #endif
30 
36 [[maybe_unused]] auto wait_for_input(EFI_INPUT_KEY *_key) -> EFI_STATUS;
37 
41 class ostream {
42 public:
46  ostream() = default;
47 
51  ~ostream() = default;
52 
55  ostream(const ostream &) = delete;
56  ostream(ostream &&) = delete;
57  auto operator=(const ostream &) -> ostream & = delete;
58  auto operator=(ostream &&) -> ostream & = delete;
60 
67  template <class _t> inline auto operator<<(_t _val) -> ostream &;
68 
74  auto operator<<(ostream &(*_ostream)(ostream &)) -> ostream &;
75 
81  static auto hex_x(ostream &_ostream) -> ostream &;
82 
88  static auto hex_X(ostream &_ostream) -> ostream &;
89 
95  static auto endl(ostream &_ostream) -> ostream &;
96 
97 private:
101  enum mode_t : uint8_t {
103  x,
105  X,
107  d,
108  };
111 };
112 
115 
116 template <class _t> auto ostream::operator<<(_t _val) -> ostream & {
117  *this << (uint64_t)_val;
118  return *this;
119 }
120 
121 template <> inline auto ostream::operator<<(int32_t _val) -> ostream & {
122  if (mode == d) {
123  Print(L"%d", _val);
124  } else if (mode == x) {
125  Print(L"0x%x", _val);
126  } else if (mode == X) {
127  Print(L"0x%X", _val);
128  }
129  mode = d;
130  return *this;
131 }
132 
133 template <> inline auto ostream::operator<<(uint32_t _val) -> ostream & {
134  if (mode == d) {
135  Print(L"%d", _val);
136  } else if (mode == x) {
137  Print(L"0x%x", _val);
138  } else if (mode == X) {
139  Print(L"0x%X", _val);
140  }
141  mode = d;
142  return *this;
143 }
144 
145 template <> inline auto ostream::operator<<(int64_t _val) -> ostream & {
146  if (mode == d) {
147  Print(L"%ld", _val);
148  } else if (mode == x) {
149  Print(L"0x%x", _val);
150  } else if (mode == X) {
151  Print(L"0x%X", _val);
152  }
153  mode = d;
154  return *this;
155 }
156 
157 template <> inline auto ostream::operator<<(uint64_t _val) -> ostream & {
158  if (mode == d) {
159  Print(L"%ld", _val);
160  } else if (mode == x) {
161  Print(L"0x%x", _val);
162  } else if (mode == X) {
163  Print(L"0x%X", _val);
164  }
165  mode = d;
166  return *this;
167 }
168 
169 template <> inline auto ostream::operator<<(wchar_t _val) -> ostream & {
170  Print(L"%c", _val);
171  mode = d;
172  return *this;
173 }
174 
175 template <> inline auto ostream::operator<<(const wchar_t *_val) -> ostream & {
176  Print(L"%s", _val);
177  mode = d;
178  return *this;
179 }
180 
181 template <> inline auto ostream::operator<<(void *_val) -> ostream & {
182  *this << reinterpret_cast<uint64_t>(_val);
183  return *this;
184 }
185 
186 template <> inline auto ostream::operator<<(const void *_val) -> ostream & {
187  *this << reinterpret_cast<uint64_t>(_val);
188  return *this;
189 }
190 
192 
194 static ostream debug;
195 
196 #endif /* SIMPLEKERNEL_OSTREAM_HPP */
auto operator<<(_t _val) -> ostream &
Definition: ostream.hpp:116
static auto endl(ostream &_ostream) -> ostream &
Definition: ostream.cpp:42
@ d
10 进制 d
Definition: ostream.hpp:107
@ X
16 进制 X
Definition: ostream.hpp:105
@ x
16 进制 x
Definition: ostream.hpp:103
~ostream()=default
mode_t mode
输出流模式
Definition: ostream.hpp:110
static auto hex_x(ostream &_ostream) -> ostream &
Definition: ostream.cpp:32
auto operator=(ostream &&) -> ostream &=delete
ostream(const ostream &)=delete
ostream(ostream &&)=delete
ostream()=default
auto operator=(const ostream &) -> ostream &=delete
static auto hex_X(ostream &_ostream) -> ostream &
Definition: ostream.cpp:37
auto wait_for_input(EFI_INPUT_KEY *_key) -> EFI_STATUS
Definition: ostream.cpp:19
static ostream debug
全局输出流
Definition: ostream.hpp:194