You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
767 B
C++
45 lines
767 B
C++
#ifndef TEXTOUTPUT_HPP
|
|
#define TEXTOUTPUT_HPP
|
|
|
|
class TextOutput
|
|
{
|
|
public:
|
|
virtual void write(char c) noexcept = 0;
|
|
|
|
void write(const char *s) noexcept {
|
|
if (s) {
|
|
while (*s)
|
|
write(*s++);
|
|
}
|
|
}
|
|
|
|
void write(int n) noexcept {
|
|
char buf[32];
|
|
auto ptr = buf + sizeof(buf);
|
|
|
|
*--ptr = '\0';
|
|
do {
|
|
*--ptr = "0123456789"[n % 10];
|
|
n /= 10;
|
|
} while (n);
|
|
|
|
write(ptr);
|
|
}
|
|
|
|
void write(unsigned n) noexcept {
|
|
char buf[32];
|
|
auto ptr = buf + sizeof(buf);
|
|
|
|
*--ptr = '\0';
|
|
do {
|
|
*--ptr = "0123456789"[n % 10];
|
|
n /= 10;
|
|
} while (n);
|
|
|
|
write(ptr);
|
|
}
|
|
};
|
|
|
|
#endif // TEXTOUTPUT_HPP
|
|
|