forked from orocos-toolchain/log4cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategoryStream.cpp
More file actions
63 lines (56 loc) · 1.51 KB
/
CategoryStream.cpp
File metadata and controls
63 lines (56 loc) · 1.51 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
/*
* CategoryStream.cpp
*
* Copyright 2001, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
* Copyright 2001, Bastiaan Bakker. All rights reserved.
*
* See the COPYING file for the terms of usage and distribution.
*/
#include "PortabilityImpl.hh"
#ifdef LOG4CPP_HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <log4cpp/CategoryStream.hh>
#include <log4cpp/Category.hh>
namespace log4cpp {
CategoryStream::CategoryStream(Category& category, Priority::Value priority) :
_category(category),
_priority(priority),
_buffer(NULL) {
}
CategoryStream::~CategoryStream() {
flush();
}
void CategoryStream::flush() {
if (_buffer) {
getCategory().log(getPriority(), _buffer->str());
delete _buffer;
_buffer = NULL;
}
}
std::streamsize CategoryStream::width(std::streamsize wide ) {
if (getPriority() != Priority::NOTSET) {
if (!_buffer) {
if (!(_buffer = new std::ostringstream)) {
// XXX help help help
}
}
}
return _buffer->width(wide);
}
CategoryStream& CategoryStream::operator<< (cspf pf) {
return (*pf)(*this);
}
CategoryStream& eol (CategoryStream& os) {
if (os._buffer) {
os.flush();
}
return os;
}
CategoryStream& left (CategoryStream& os) {
if (os._buffer) {
os._buffer->setf(std::ios::left);
}
return os;
}
}