aboutsummaryrefslogtreecommitdiffstats
path: root/src/textoutput.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/textoutput.hpp')
-rw-r--r--src/textoutput.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/textoutput.hpp b/src/textoutput.hpp
new file mode 100644
index 0000000..7ef12fa
--- /dev/null
+++ b/src/textoutput.hpp
@@ -0,0 +1,44 @@
+#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
+