Menu

[2d617b]: / src / CategoryStream.cpp  Maximize  Restore  History

Download this file

111 lines (99 with data), 2.8 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
/*
* 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;
}
}
CategoryStream& CategoryStream::operator<<(const char* t)
{
if (getPriority() != Priority::NOTSET) {
if (!_buffer) {
if (!(_buffer = new std::ostringstream)) {
// XXX help help help
}
}
(*_buffer) << t;
}
return *this;
}
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;
}
}
// MSVC6 bug in member templates instantiation
#if defined(_MSC_VER) && _MSC_VER < 1300
namespace
{
struct dummy
{
void instantiate()
{
using namespace log4cpp;
CategoryStream t(Category::getInstance(""), Priority::DEBUG);
t << static_cast<const char*>("")
<< Priority::DEBUG
<< static_cast<char>(0)
<< static_cast<unsigned char>(0)
<< static_cast<signed char>(0)
<< static_cast<short>(0)
<< static_cast<unsigned short>(0)
<< static_cast<int>(0)
<< static_cast<unsigned int>(0)
<< static_cast<long>(0)
<< static_cast<unsigned long>(0)
<< static_cast<float>(0.0)
<< static_cast<double>(0.0)
#if LOG4CPP_HAS_WCHAR_T != 0
<< std::wstring()
#endif
<< std::string();
}
};
}
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.