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 _LOG4SHIB_CATEGORYSTREAM_HH
00011 #define _LOG4SHIB_CATEGORYSTREAM_HH
00012 
00013 #include <log4shib/Portability.hh>
00014 #include <log4shib/Priority.hh>
00015 #ifdef LOG4SHIB_HAVE_SSTREAM
00016 #include <sstream>
00017 #endif
00018 
00019 namespace log4shib {
00020 
00021     class LOG4SHIB_EXPORT Category;
00022     class LOG4SHIB_EXPORT CategoryStream;
00023 
00027     LOG4SHIB_EXPORT CategoryStream& eol (CategoryStream& os);
00028 
00033     class LOG4SHIB_EXPORT CategoryStream {
00034         public:
00035 
00042         CategoryStream(Category& category, Priority::Value priority);
00043 
00047         ~CategoryStream();
00048         
00053         inline Category& getCategory() const { return _category; };
00054 
00059         inline Priority::Value getPriority() const throw() { 
00060             return _priority; 
00061         };
00062 
00067         void flush();
00068 
00074         template<typename T> CategoryStream& operator<<(const T& t) {
00075             if (getPriority() != Priority::NOTSET) {
00076                 if (!_buffer) {
00077                     if (!(_buffer = new std::ostringstream)) {
00078                         // XXX help help help
00079                     }
00080                 }
00081                 (*_buffer) << t;
00082             }
00083             return *this;
00084         }
00085         
00086         private:
00087         Category& _category;
00088         Priority::Value _priority;
00089         std::ostringstream* _buffer;
00090 
00091      public:
00092         typedef CategoryStream& (*cspf) (CategoryStream&);
00093         CategoryStream& operator << (cspf);
00094         LOG4SHIB_EXPORT friend CategoryStream& eol (CategoryStream& os);
00095     };
00096 
00097 }
00098 #endif // _LOG4SHIB_CATEGORYSTREAM_HH

Generated on Tue Apr 7 14:36:17 2009 for log4shib by  doxygen 1.4.7