/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/ers/ers-00-00-03/ers/StreamFactory.h

Go to the documentation of this file.
00001 /*
00002  *  StreamFactory.h
00003  *  ers
00004  *
00005  *  Created by Matthias Wiesmann on 21.01.05.
00006  *  Copyright 2005 CERN. All rights reserved.
00007  *
00008  */
00009 
00010 #ifndef ERS_STREAM_FACTORY
00011 #define ERS_STREAM_FACTORY
00012 
00013 #include "ers/Core.h"
00014 #include "ers/Context.h"
00015 
00016 #include <map>
00017 
00018 namespace ers {
00019     
00020     class Stream ; 
00021     class Issue ; 
00022     
00119     class StreamFactory {
00120         
00121 public:
00122         typedef Stream* (*create_stream_callback)(const std::string &, const std::string &);
00123         typedef std::map<std::string, create_stream_callback> stream_factory_collection ; 
00124 protected:
00125         static StreamFactory *s_instance ;                                      
00126         static const char* DEFAULT_STREAMS[] ;                                  
00127         static const char *key_for_severity(severity_t s) ;                     
00128         static Stream *get_default_stream(severity_t s) ;                       
00130         StreamFactory();
00131         StreamFactory(const StreamFactory &other); 
00132         
00133         Stream *m_streams[severity_max] ;                                       
00134         stream_factory_collection m_factories ;                                 
00136         Stream *create_stream(severity_t s) ;                                   
00137 public:
00138         static StreamFactory *instance();                                       
00139         static void print_registered(); 
00140         static void fatal(Issue *i) ;                                           
00141         static void error(Issue *i) ;                                           
00142         static void warning(Issue *i);                                          
00143         static void warning(const Context &c, const std::string &message);      
00144         static void debug(Issue *i, severity_t) ;                               
00145         static void debug(const Context &c, const std::string &message, severity_t s);  
00146         static void dispatch(Issue *i, bool throw_error = false) ;                
00147         static void dispatch(Issue &i, bool throw_error = false) ;      
00148         static void set_stream(severity_t, const std::string &key) ;
00149         ~StreamFactory() ; 
00150         Stream *create_stream(const std::string &key) const ;                   
00151         Stream *get_stream(severity_t s) ;                                      
00152         void set(severity_t severity, Stream *s) ;                              
00153         void set(severity_t severity, const char* key) ;                        
00154         Stream *fatal() ;                                                       
00155         Stream *error()  ;                                                      
00156         Stream *warning()  ;                                                    
00157         Stream* debug(severity_t s)  ;                                          
00158         bool register_factory(const std::string &name, create_stream_callback callback); 
00159         void write_to(std::ostream& stream) const ;                               
00160     } ; 
00161     std::ostream& operator<<(std::ostream&, const ers::StreamFactory& factory);        
00162 } // ers 
00163 
00164 #ifndef DEBUG_LEVEL
00165 
00166 #define DEBUG_LEVEL 3
00167 #endif
00168 
00169     
00172 #if ! defined(ERS_FAST_DEBUG)
00173 #define ERS_DEBUG_0(...) { char ers_debug_buf[256] ; snprintf(ers_debug_buf,sizeof(ers_debug_buf),__VA_ARGS__) ; ers::StreamFactory::debug(ERS_HERE,ers_debug_buf,ers::debug_0) ; }
00174 #else 
00175 #define ERS_DEBUG_0(...) { fprintf(stderr,"debug-0 ") ; fprintf(stderr,__VA_ARGS__) ; fprintf(stderr,"\n") ; }
00176 #endif
00177     
00178     
00180 #if (DEBUG_LEVEL>0) 
00181 #if (! defined(ERS_FAST_DEBUG))
00182 #define ERS_DEBUG_1(...) { char ers_debug_buf[256] ; snprintf(ers_debug_buf,sizeof(ers_debug_buf),__VA_ARGS__) ; ers::StreamFactory::debug(ERS_HERE,ers_debug_buf,ers::debug_1) ; }
00183 #else 
00184 #define ERS_DEBUG_1(...) { fprintf(stderr,"debug-1 ") ; fprintf(stderr,__VA_ARGS__) ; fprintf(stderr,"\n") ; }
00185 #endif
00186 #else 
00187 #define ERS_DEBUG_1(...) 
00188 #endif
00189     
00191 #if DEBUG_LEVEL>1
00192 #define ERS_DEBUG_2(...) { char ers_debug_buf[256] ; snprintf(ers_debug_buf,sizeof(ers_debug_buf),__VA_ARGS__) ; ers::StreamFactory::debug(ERS_HERE,ers_debug_buf,ers::debug_2) ; }
00193 #else 
00194 #define ERS_DEBUG_2(...)
00195 #endif
00196     
00198 #if DEBUG_LEVEL>2
00199 #define ERS_DEBUG_3(...) { char ers_debug_buf[256] ; snprintf(ers_debug_buf,sizeof(ers_debug_buf),__VA_ARGS__) ; ers::StreamFactory::debug(ERS_HERE,ers_debug_buf,ers::debug_3) ; }
00200 #else 
00201 #define ERS_DEBUG_3(...) 
00202 #endif
00203 
00205 #define ERS_WARN(...)    { char ers_warn_buf[256] ; snprintf(ers_warn_buf,sizeof(ers_warn_buf),__VA_ARGS__)    ; ers::StreamFactory::warning(ERS_HERE,ers_warn_buf) ; }
00206     
00207 
00208 #endif
00209 

Generated on Tue Nov 29 22:58:26 2016 for BOSS_7.0.2 by  doxygen 1.4.7