CategoryStream.cpp
Go to the documentation of this file.
00001 /*
00002  * CategoryStream.cpp
00003  *
00004  * Copyright 2001, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
00005  * Copyright 2001, Bastiaan Bakker. All rights reserved.
00006  *
00007  * See the COPYING file for the terms of usage and distribution.
00008  */
00009 
00010 #include "PortabilityImpl.hh"
00011 
00012 #ifdef LOG4CPP_HAVE_UNISTD_H
00013 #    include <unistd.h>
00014 #endif
00015 
00016 #include <log4cpp/CategoryStream.hh>
00017 #include <log4cpp/Category.hh>
00018 
00019 namespace log4cpp {
00020 
00021     CategoryStream::CategoryStream(Category& category, Priority::Value priority) :
00022         _category(category),
00023         _priority(priority),
00024         _buffer(NULL) {
00025     }
00026 
00027     CategoryStream::~CategoryStream() { 
00028         flush();
00029     }
00030 
00031     void CategoryStream::flush() {
00032         if (_buffer) {
00033             getCategory().log(getPriority(), _buffer->str());
00034             delete _buffer;
00035             _buffer = NULL;
00036         }
00037     }
00038      std::streamsize CategoryStream::width(std::streamsize wide ) {
00039         if (getPriority() != Priority::NOTSET) {
00040             if (!_buffer) {
00041                 if (!(_buffer = new std::ostringstream)) {
00042                     // XXX help help help
00043                 }
00044             }
00045         }
00046         return _buffer->width(wide); 
00047     }
00048     CategoryStream& CategoryStream::operator<< (cspf pf) {
00049                 return (*pf)(*this);
00050     }
00051     CategoryStream& eol (CategoryStream& os) {
00052         if  (os._buffer) {
00053                 os.flush();
00054         }
00055         return os;
00056     }
00057     CategoryStream& left (CategoryStream& os) {
00058         if  (os._buffer) {
00059             os._buffer->setf(std::ios::left);
00060         }
00061         return os;
00062     }
00063 }


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung.
autogenerated on Thu Jan 2 2014 11:35:02