log4cpp  1.1.6
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 <ios>
14 #include <log4cpp/Portability.hh>
15 #include <log4cpp/Priority.hh>
16 #ifdef LOG4CPP_HAVE_SSTREAM
17 #include <sstream>
18 #endif
19 #include <log4cpp/Manipulator.hh>
20 
21 namespace log4cpp {
22 
29 
34 
40  public:
47  CategoryStream(Category& category, Priority::Value priority);
48 
52  ~CategoryStream();
53 
58  inline Category& getCategory() const {
59  return _category;
60  };
61 
67  return _priority;
68  };
69 
74  void flush();
75 
81  template <typename T> CategoryStream& operator<<(const T& t) {
82  if (getPriority() != Priority::NOTSET) {
83  if (!_buffer) {
84  if (!(_buffer = new std::ostringstream)) {
85  // XXX help help help
86  }
87  }
88  (*_buffer) << t;
89  }
90  return *this;
91  }
92 
93  CategoryStream& operator<<(const char* t);
94 
95  template <typename T> CategoryStream& operator<<(const std::string& t) {
96  if (getPriority() != Priority::NOTSET) {
97  if (!_buffer) {
98  if (!(_buffer = new std::ostringstream)) {
99  // XXX help help help
100  }
101  }
102  (*_buffer) << t;
103  }
104  return *this;
105  }
106 #if LOG4CPP_HAS_WCHAR_T != 0
107  template <typename T> CategoryStream& operator<<(const std::wstring& t) {
108  if (getPriority() != Priority::NOTSET) {
109  if (!_wbuffer) {
110  if (!(_wbuffer = new std::wostringstream)) {
111  // XXX help help help
112  }
113  }
114  (*_wbuffer) << t;
115  }
116  return *this;
117  }
118 #endif
119 
122  std::streamsize width(std::streamsize wide);
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 } // namespace log4cpp
142 
143 #endif // _LOG4CPP_CATEGORYSTREAM_HH
Priority::Value getPriority() const LOG4CPP_NOTHROW
Returns the priority for this stream.
Definition: CategoryStream.hh:66
This is the central class in the log4j package.
Definition: Category.hh:32
ostream & operator<<(ostream &os, const width &w)
Definition: Manipulator.cpp:10
LOG4CPP_EXPORT CategoryStream & eol(CategoryStream &os)
eol manipulator
Definition: CategoryStream.cpp:61
Definition: Priority.hh:79
This class enables streaming simple types and objects to a category.
Definition: CategoryStream.hh:39
class LOG4CPP_EXPORT CategoryStream
Definition: CategoryStream.hh:24
#define LOG4CPP_EXPORT
Definition: Export.hh:26
CategoryStream & operator<<(const T &t)
Stream in arbitrary types and objects.
Definition: CategoryStream.hh:81
The top level namespace for all &#39;Log for C++&#39; types and classes.
Definition: AbortAppender.hh:16
LOG4CPP_EXPORT CategoryStream & left(CategoryStream &os)
left manipulator
Definition: CategoryStream.cpp:67
int Value
The type of Priority Values.
Definition: Priority.hh:85
std::ostringstream * _buffer
Definition: CategoryStream.hh:128
CategoryStream & operator<<(const std::string &t)
Definition: CategoryStream.hh:95
class LOG4CPP_EXPORT Category
Definition: CategoryStream.hh:23
Definition: Portability.hh:62
Category & getCategory() const
Returns the destination Category for this stream.
Definition: CategoryStream.hh:58
#define LOG4CPP_NOTHROW
Definition: Portability.hh:82