log4shib  1.0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
23 
28 
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);
95  };
96 
97 }
98 #endif // _LOG4SHIB_CATEGORYSTREAM_HH
This class enables streaming simple types and objects to a category.
Definition: CategoryStream.hh:33
Priority::Value getPriority() const
Returns the priority for this stream.
Definition: CategoryStream.hh:59
Definition: Priority.hh:78
CategoryStream & operator<<(const T &t)
Stream in arbitrary types and objects.
Definition: CategoryStream.hh:74
#define LOG4SHIB_EXPORT
Definition: Export.hh:11
LOG4SHIB_EXPORT CategoryStream & eol(CategoryStream &os)
eol manipulator
Definition: CategoryStream.cpp:43
int Value
The type of Priority Values.
Definition: Priority.hh:84
Category & getCategory() const
Returns the destination Category for this stream.
Definition: CategoryStream.hh:53
This is the central class in the log4j package.
Definition: Category.hh:32
Definition: Portability.hh:38
class LOG4SHIB_EXPORT CategoryStream
Definition: CategoryStream.hh:22