summaryrefslogtreecommitdiff
path: root/include/object/outputstream.h
blob: c6b503f728e38cc2c38fed1622f56354221df3e1 (plain)
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
68
69
70
71
72
73
74
75
76
#ifndef OUTPUTSTREAM_H
#define OUTPUTSTREAM_H

#include <stdint.h>
#ifdef WITH_OSTREAM
#include <ostream>
#endif

class OutputStream {
 private:
	OutputStream(const OutputStream& copy);

	char digit_buffer[sizeof(long long) * 8];
	uint8_t base;

 public:
	OutputStream();

	virtual void put(char c) = 0;

	virtual void write(const char *s) {
		while (*s) {
			put(*s++);
		}
	}

	virtual void flush() {}

	OutputStream & operator<<(char c);
	OutputStream & operator<<(unsigned char c);
	OutputStream & operator<<(unsigned short number);
	OutputStream & operator<<(short number);
	OutputStream & operator<<(unsigned int number);
	OutputStream & operator<<(int number);
	OutputStream & operator<<(unsigned long number);
	OutputStream & operator<<(long number);
	OutputStream & operator<<(unsigned long long number);
	OutputStream & operator<<(long long number);
	OutputStream & operator<<(void *pointer);
	OutputStream & operator<<(const char *text);
	OutputStream & operator<<(float number);
	OutputStream & operator<<(double number);
	OutputStream & operator<<(OutputStream & (*fun) (OutputStream &));

#ifdef WITH_OSTREAM
	OutputStream & operator<<(std::string s);
#endif

	void setBase(uint8_t b);
	void printf_uint8(uint8_t num);
	void printf_float(float num);
};


// ENDL: new line character (and flush)
OutputStream & endl(OutputStream & os);

// BIN: print numbers in binary form.
OutputStream & bin(OutputStream & os);

// OCT: print numbers in octal form.
OutputStream & oct(OutputStream & os);

// DEC: print numbers in decimal form.
OutputStream & dec(OutputStream & os);

// HEX: print numbers in hexadecimal form.
OutputStream & hex(OutputStream & os);

// FLUSH: flush OutputStream buffer
OutputStream & flush(OutputStream & os);

// TERM: zero-termination
OutputStream & term(OutputStream & os);

#endif //OUTPUTSTREAM_H