blob: f0667e75c95c888040d6b15273aaf9a7ba55134a (
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
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
|
#include <OStream.proto.h>
OStream::OStream() {
m_buffer = NULL;
m_last = NULL;
}
OStream::OStream(const OStream& other) {
m_buffer = NULL;
m_last = NULL;
}
void OStream::put(const String &s) {
if (s.empty()) return;
waitLock();
if (m_buffer == NULL or m_last == NULL) {
m_buffer = m_last = new SimpleList<String>(s);
} else {
m_last = m_last->addAtEnd(s);
}
unlock();
}
void OStream::flush() {
if (m_buffer == NULL or m_last == NULL) return;
waitLock();
//Calculate buffer size
int size = 0;
SimpleList<String>* iter = m_buffer;
for (; iter != 0; iter = iter->next()) {
size += iter->v().size();
}
//Get stuff
String buff(WChar(" "), size);
iter = m_buffer;
for (int i = 0, pos = 0; i < size; i++, pos++) {
if (pos >= iter->v().size()) {
iter = iter->next();
pos = 0;
}
buff[i] = iter->v()[pos];
}
//Write it
write(buff);
delete m_buffer;
m_buffer = NULL;
m_last = NULL;
unlock();
}
OStream& OStream::operator<< (ostream_modifiers_e m) {
if (m == FLUSH) {
flush();
} else if (m == ENDL) {
put("\n");
flush();
} else if (m == END) {
put(EOF);
flush();
}
return *this;
}
|