log4cpp 1.1

CategoryStream.hh

Go to the documentation of this file.
00001 /*
00002  * CategoryStream.hh
00003  *
00004  * Copyright 2001, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
00005  * Copyright 2001, Bastiaan Bakker. All rights reserved.
00006  *
00007  * See the COPYING file for the terms of usage and distribution.
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     class LOG4CPP_EXPORT CategoryStream;    
00028     LOG4CPP_EXPORT CategoryStream& eol (CategoryStream& os);
00029 
00033     LOG4CPP_EXPORT CategoryStream& left (CategoryStream& os);
00034 
00039     class LOG4CPP_EXPORT CategoryStream {
00040         public:
00041 
00048         CategoryStream(Category& category, Priority::Value priority);
00049 
00053         ~CategoryStream();
00054         
00059         inline Category& getCategory() const { return _category; };
00060 
00065         inline Priority::Value getPriority() const throw() { 
00066             return _priority; 
00067         };
00068 
00073         void flush();
00074 
00080                   template<typename T> 
00081         CategoryStream& operator<<(const T& t) {
00082             if (getPriority() != Priority::NOTSET) {
00083                 if (!_buffer) {
00084                                         if (!(_buffer = new std::ostringstream)) {
00085                         // XXX help help help
00086                     }
00087                 }
00088                 (*_buffer) << t;
00089             }
00090             return *this;
00091         }
00092            
00093         CategoryStream& operator<<(const char* t);
00094 
00095              template<typename T> 
00096              CategoryStream& operator<<(const std::string& t) {
00097             if (getPriority() != Priority::NOTSET) {
00098                 if (!_buffer) {
00099                     if (!(_buffer = new std::ostringstream)) {
00100                         // XXX help help help
00101                     }
00102                 }
00103                 (*_buffer) << t;
00104             }
00105             return *this;
00106         }
00107 #if LOG4CPP_HAS_WCHAR_T != 0
00108         template<typename T> 
00109         CategoryStream& operator<<(const std::wstring& t) {
00110             if (getPriority() != Priority::NOTSET) {
00111                 if (!_wbuffer) {
00112                     if (!(_wbuffer = new std::wostringstream)) {
00113                         // XXX help help help
00114                     }
00115                 }
00116                 (*_wbuffer) << t;
00117             }
00118             return *this;
00119         }
00120 #endif
00121 
00124                   std::streamsize width(std::streamsize wide );
00125 
00126 
00127         private:
00128         Category& _category;
00129         Priority::Value _priority;
00130              union {
00131                  std::ostringstream* _buffer;
00132 #if LOG4CPP_HAS_WCHAR_T != 0
00133             std::wostringstream* _wbuffer;
00134 #endif
00135         };
00136 
00137              public:
00138              typedef CategoryStream& (*cspf) (CategoryStream&);
00139 
00140              CategoryStream& operator << (cspf);
00141         LOG4CPP_EXPORT friend CategoryStream& eol (CategoryStream& os);
00142         LOG4CPP_EXPORT friend CategoryStream& left (CategoryStream& os);
00143    };
00144 }
00145 
00146 #endif // _LOG4CPP_CATEGORYSTREAM_HH
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines