log4shib 2.0.0

CategoryStream.hh
Go to the documentation of this file.
1/*
2 * CategoryStream.hh
3 *
4 * Copyright 2001, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
5 * Copyright 2001, Bastiaan Bakker. All rights reserved.
6 *
7 * See the COPYING file for the terms of usage and distribution.
8 */
9
10#ifndef _LOG4SHIB_CATEGORYSTREAM_HH
11#define _LOG4SHIB_CATEGORYSTREAM_HH
12
13#include <log4shib/Portability.hh>
14#include <log4shib/Priority.hh>
15#ifdef LOG4SHIB_HAVE_SSTREAM
16#include <sstream>
17#endif
18
19 namespace log4shib {
20
21 class LOG4SHIB_EXPORT Category;
22 class LOG4SHIB_EXPORT CategoryStream;
23
27 LOG4SHIB_EXPORT CategoryStream& eol (CategoryStream& os);
28
33 class LOG4SHIB_EXPORT CategoryStream {
34 public:
35
42 CategoryStream(Category& category, Priority::Value priority);
43
47 ~CategoryStream();
48
53 inline Category& getCategory() const { return _category; };
54
59 inline Priority::Value getPriority() const throw() {
60 return _priority;
61 };
62
67 void flush();
68
74 template<typename T> CategoryStream& operator<<(const T& t) {
75 if (getPriority() != Priority::NOTSET) {
76 if (!_buffer) {
77 if (!(_buffer = new std::ostringstream)) {
78 // XXX help help help
79 }
80 }
81 (*_buffer) << t;
82 }
83 return *this;
84 }
85
86 private:
87 Category& _category;
88 Priority::Value _priority;
89 std::ostringstream* _buffer;
90
91 public:
92 typedef CategoryStream& (*cspf) (CategoryStream&);
93 CategoryStream& operator << (cspf);
94 LOG4SHIB_EXPORT friend CategoryStream& eol (CategoryStream& os);
95 };
96
97}
98#endif // _LOG4SHIB_CATEGORYSTREAM_HH
LOG4SHIB_EXPORT
#define LOG4SHIB_EXPORT
Definition: Export.hh:11
Portability.hh
Priority.hh
log4shib::CategoryStream
This class enables streaming simple types and objects to a category.
Definition: CategoryStream.hh:33
log4shib::CategoryStream::operator<<
CategoryStream & operator<<(const T &t)
Stream in arbitrary types and objects.
Definition: CategoryStream.hh:74
log4shib::CategoryStream::getPriority
Priority::Value getPriority() const
Returns the priority for this stream.
Definition: CategoryStream.hh:59
log4shib::CategoryStream::getCategory
Category & getCategory() const
Returns the destination Category for this stream.
Definition: CategoryStream.hh:53
log4shib::Category
This is the central class in the log4j package.
Definition: Category.hh:32
log4shib::Priority::NOTSET
@ NOTSET
Definition: Priority.hh:78
log4shib::Priority::Value
int Value
The type of Priority Values.
Definition: Priority.hh:84
std::ostringstream
Definition: Portability.hh:38
log4shib
The top level namespace for all 'Log for C++' types and classes.
Definition: AbortAppender.hh:16
log4shib::eol
LOG4SHIB_EXPORT CategoryStream & eol(CategoryStream &os)
eol manipulator
Definition: CategoryStream.cpp:43
log4shib::CategoryStream
class LOG4SHIB_EXPORT CategoryStream
Definition: CategoryStream.hh:22