Repository navigation
Expand file tree
/
Copy pathNameTimeInserter.cpp
More file actions
144 lines (116 loc) · 2.75 KB
/
Copy pathNameTimeInserter.cpp
File metadata and controls
144 lines (116 loc) · 2.75 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "NameTimeInserter.h"
#include <sstream>
#include "Singleton.h"
namespace dispatch { namespace util {
typedef Singleton<Mutex> _NameTimeLock;
NameTimeInserter::NameTimeInserter() : name(NULL) {}
void NameTimeInserter::setNameProvider(NameProvider* n) {
name = n;
}
string NameTimeInserter::getPrefix() {
return "[";
}
string NameTimeInserter::getPostfix() {
stringstream buf;
buf << "] ";
if (name != NULL) {
buf << name->getName();
buf << ": ";
}
// buf << "[";
return buf.str();
}
NameTimeTaggedOutput::NameTimeTaggedOutput(NameProvider* n, streambuf* buf) :
ostream(buf),
name(n)
{
wrapper = new FilteringOutputStreambuf<NameTimeInserter>(buf);
wrapper->inserter().setNameProvider(n);
rdbuf(wrapper);
}
NameTimeTaggedOutput::~NameTimeTaggedOutput()
{
if (wrapper != NULL) {
delete wrapper;
}
}
/**
* @TODO få forskjellig lås for forskjellig utkanal
*/
bool NameTimeTaggedOutput::lock() {
return _NameTimeLock::instance().lock();
// return _lock.lock();
}
bool NameTimeTaggedOutput::unlock() {
return _NameTimeLock::instance().unlock();
// return _lock.unlock();
}
OStreamProxy NameTimeTaggingOutputSet::out() {
if (!_out) {
_out = new NameTimeTaggedOutput(this, stream_provider->out()); //cout.rdbuf());
}
return OStreamProxy(_out);
}
OStreamProxy NameTimeTaggingOutputSet::log() {
if (!_log) {
_log = new NameTimeTaggedOutput(this, stream_provider->log()); //clog.rdbuf());
}
return OStreamProxy(_log);
}
OStreamProxy NameTimeTaggingOutputSet::err() {
if (!_err) {
_err = new NameTimeTaggedOutput(this, stream_provider->err()); //;cerr.rdbuf());
}
return OStreamProxy(_err);
}
OStreamProxy NameTimeTaggingOutputSet::dbg(int level) {
if (!_dbg[level]) {
_dbg[level] = new NameTimeTaggedOutput(this, stream_provider->dbg(level)); // cerr.rdbuf());
}
return OStreamProxy(_dbg[level]);
}
OStreamProxy::OStreamProxy(NameTimeTaggedOutput* out) :
_dest(out)
{
// cout << "Starter IO Proxy med tagged output " << endl;
}
OStreamProxy::OStreamProxy(OStreamProxy const& o):
_dest(o._dest)
{
// cout << "Kopierer IO proxy" << endl;
// *this << o;
}
OStreamProxy& OStreamProxy::operator=(OStreamProxy const& o) {
_dest = o._dest;
return *this;
}
OStreamProxy::~OStreamProxy() {
_dest->lock();
*_dest << this->rdbuf();
_dest->unlock();
}
ostream& OStreamProxy::operator<<(string s) {
// stringstream ick;
stringstream* ick = this;
*ick << s;
// ick << s;
// *this << ick;
return *this;
}
ostream& OStreamProxy::operator<<(int i) {
stringstream::operator<<(i);
return *this;
}
ostream& OStreamProxy::operator<<(ostream& (*p)(ostream&)) {
return (*p)(*this);
// stringstream::operator<<(p, *this);
// return *this;
}
/*
ostream& OStreamProxy::operator<<() {
_dest->lock();
_dest->unlock();
return *this;
}
*/
}} // end namespace