summaryrefslogtreecommitdiff
path: root/Source/Library/Common/OStream.proto.h
blob: ff19e7b43fa246d3acb67d4f14fc87d9113b5af6 (plain) (blame)
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
#ifndef DEF_ISTREAM_PROTO_H
#define DEF_ISTREAM_PROTO_H

#include <String.class.h>
#include <SimpleList.class.h>
#include <Mutex.class.h>

enum ostream_modifiers_e {
	FLUSH,
	ENDL,
	END
};

class OStream : private Mutex {
	private:
	SimpleList<String> *m_buffer;
	SimpleList<String> *m_last;
	void operator =(OStream& other);

	protected:
	virtual void write(const String &s) = 0;
	
	public:
	OStream();
	OStream(const OStream& other);
	virtual ~OStream() { flush(); }

	void put(const String& s);
	void flush();
	
	//Formatting functions
	OStream& operator << (const String& s) { put(s); if (s.contains("\n")) flush(); return *this; }
	OStream& operator << (s64int i) { put(String::number(i)); return *this; }
	OStream& operator << (s32int i) { put(String::number(i)); return *this; }
	OStream& operator << (u32int i) { put(String::hex(i)); return *this; }
	OStream& operator << (ostream_modifiers_e m);
};

#endif