00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _LOG4CPP_CATEGORYSTREAM_HH
00011 #define _LOG4CPP_CATEGORYSTREAM_HH
00012
00013 #include <log4cpp/Portability.hh>
00014 #include <log4cpp/Priority.hh>
00015 #include <ios>
00016 #ifdef LOG4CPP_HAVE_SSTREAM
00017 #include <sstream>
00018 #endif
00019 #include <log4cpp/Manipulator.hh>
00020
00021 namespace log4cpp {
00022
00023 class LOG4CPP_EXPORT Category;
00024
00029 class LOG4CPP_EXPORT CategoryStream {
00030 public:
00031
00036 typedef enum {
00037 ENDLINE = 0,
00038 EOL = 0
00039 } Separator;
00040
00047 CategoryStream(Category& category, Priority::Value priority);
00048
00052 ~CategoryStream();
00053
00058 inline Category& getCategory() const { return _category; };
00059
00064 inline Priority::Value getPriority() const throw() {
00065 return _priority;
00066 };
00067
00075 CategoryStream& operator<<(Separator separator);
00076
00081 void flush();
00082
00088 template<typename T> CategoryStream& operator<<(const T& t) {
00089 if (getPriority() != Priority::NOTSET) {
00090 if (!_buffer) {
00091 if (!(_buffer = new std::ostringstream)) {
00092
00093 }
00094 }
00095 (*_buffer) << t;
00096 }
00097 return *this;
00098 }
00099 template<typename T> CategoryStream& operator<<(const std::string& t) {
00100 if (getPriority() != Priority::NOTSET) {
00101 if (!_buffer) {
00102 if (!(_buffer = new std::ostringstream)) {
00103
00104 }
00105 }
00106 (*_buffer) << t;
00107 }
00108 return *this;
00109 }
00110 template<typename T> CategoryStream& operator<<(const std::wstring& t) {
00111 if (getPriority() != Priority::NOTSET) {
00112 if (!_wbuffer) {
00113 if (!(_wbuffer = new std::wostringstream)) {
00114
00115 }
00116 }
00117 (*_wbuffer) << t;
00118 }
00119 return *this;
00120 }
00121
00125 std::streamsize width(std::streamsize wide );
00126
00127
00128 private:
00129 Category& _category;
00130 Priority::Value _priority;
00131 union {
00132 std::ostringstream* _buffer;
00133 std::wostringstream* _wbuffer;
00134 };
00135
00136 public:
00137 typedef CategoryStream& (*cspf) (CategoryStream&);
00138
00139 CategoryStream& operator<< (cspf);
00140
00144 friend LOG4CPP_EXPORT CategoryStream& eol (CategoryStream& os);
00145
00149 friend LOG4CPP_EXPORT CategoryStream& left (CategoryStream& os);
00150 };
00151 }
00152 #endif // _LOG4CPP_CATEGORYSTREAM_HH