log4shib  1.0.4
 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