log4cpp  1.0
 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 _LOG4CPP_CATEGORYSTREAM_HH
11 #define _LOG4CPP_CATEGORYSTREAM_HH
12 
13 #include <log4cpp/Portability.hh>
14 #include <log4cpp/Priority.hh>
15 #include <ios>
16 #ifdef LOG4CPP_HAVE_SSTREAM
17 #include <sstream>
18 #endif
19 #include <log4cpp/Manipulator.hh>
20 
21 namespace log4cpp {
22 
29 
34 
40  public:
41 
48  CategoryStream(Category& category, Priority::Value priority);
49 
53  ~CategoryStream();
54 
59  inline Category& getCategory() const { return _category; };
60 
65  inline Priority::Value getPriority() const throw() {
66  return _priority;
67  };
68 
73  void flush();
74 
80  template<typename T> CategoryStream& operator<<(const T& t) {
81  if (getPriority() != Priority::NOTSET) {
82  if (!_buffer) {
83  if (!(_buffer = new std::ostringstream)) {
84  // XXX help help help
85  }
86  }
87  (*_buffer) << t;
88  }
89  return *this;
90  }
91 
92  template<typename T>
93  CategoryStream& operator<<(const std::string& t) {
94  if (getPriority() != Priority::NOTSET) {
95  if (!_buffer) {
96  if (!(_buffer = new std::ostringstream)) {
97  // XXX help help help
98  }
99  }
100  (*_buffer) << t;
101  }
102  return *this;
103  }
104 #if LOG4CPP_HAS_WCHAR_T != 0
105  template<typename T>
106  CategoryStream& operator<<(const std::wstring& t) {
107  if (getPriority() != Priority::NOTSET) {
108  if (!_wbuffer) {
109  if (!(_wbuffer = new std::wostringstream)) {
110  // XXX help help help
111  }
112  }
113  (*_wbuffer) << t;
114  }
115  return *this;
116  }
117 #endif
118 
121  std::streamsize width(std::streamsize wide );
122 
123 
124  private:
125  Category& _category;
126  Priority::Value _priority;
127  union {
129 #if LOG4CPP_HAS_WCHAR_T != 0
130  std::wostringstream* _wbuffer;
131 #endif
132  };
133 
134  public:
135  typedef CategoryStream& (*cspf) (CategoryStream&);
136 
137  CategoryStream& operator<< (cspf);
140  };
141 }
142 #endif // _LOG4CPP_CATEGORYSTREAM_HH