CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 #ifndef ZMEXLOGGER_H 00002 #define ZMEXLOGGER_H 00003 00004 00005 // ---------------------------------------------------------------------- 00006 // 00007 // ZMexLogger.h - class declaration for the ZOOM Exception Logger base class 00008 // and the basic logger ZMexLogger, the base class 00009 // ZMexLogBehavior, and behaviors supplied with the package: 00010 // ZMexLogNever 00011 // ZMexLogAlways 00012 // ZMexLogTwice 00013 // ZMexLogViaParent 00014 // ZMexValidationStyle 00015 // 00016 // Revision History: 00017 // 970917 WEB Updated per code review 2 00018 // 970919 WEB Updated per code review 4 00019 // 971007 WEB Removed limiting logger; all loggers now 00020 // optionally limit by exception severity 00021 // 971008 WEB ZMutility is the new name for the Utility package 00022 // 971112 WEB Updated for conformance to standard and the zoom 00023 // compatability headers 00024 // 971211 WEB Updated per code walkthrough 00025 // 971215 WEB Removed unused 2nd parm to ZMexLogger constructor 00026 // 980615 WEB Added namespace support 00027 // 010410 MF Added ZMexValidationStyle 00028 // 00029 // ---------------------------------------------------------------------- 00030 00031 #ifndef STRING_INCLUDED 00032 #define STRING_INCLUDED 00033 #include <string> 00034 #endif 00035 00036 #include <iostream> 00037 00038 #ifndef ZMEXLOGRESULT_H 00039 #include "CLHEP/Exceptions/ZMexLogResult.h" 00040 #endif 00041 00042 #ifndef ZMHANDLETO_H 00043 #include "CLHEP/RefCount/ZMhandleTo.h" 00044 #endif 00045 00046 00047 // ---------------------------------------------------------------------- 00048 00049 00050 namespace zmex { 00051 00052 00053 // ---------------------------------------------------------------------- 00054 00055 00056 class ZMexLogger; 00057 class ZMexception; 00058 00059 00060 // ---------------------------------------------------------------------- 00061 00062 00063 // --------------- 00064 // ZMexLogBehavior 00065 // --------------- 00066 00067 class ZMexLogBehavior { 00068 // Logger behavior interface class 00069 00070 public: 00071 00072 ZMexLogBehavior(); 00073 // Construct this behavior 00074 00075 virtual ~ZMexLogBehavior(); 00076 // Destroy this behavior 00077 00078 virtual ZMexLogBehavior * clone() const; 00079 // Duplicate this logger object 00080 00081 virtual ZMexLogResult emit( const ZMexception & x ); 00082 // Extract the formatted message, then 00083 // carry out this logger's basic logging behavior 00084 00085 virtual ZMexLogResult emit( const std::string & s ); 00086 // Carry out this logger's basic logging behavior 00087 // Do nothing with s; this base class function ought never be called 00088 00089 virtual bool isTimeDesired() const; 00090 virtual bool isFilePathDesired() const; 00091 00092 }; // ZMexLogBehavior 00093 00094 00095 00096 // ------------ 00097 // ZMexLogNever 00098 // ------------ 00099 00100 class ZMexLogNever : public ZMexLogBehavior { 00101 00102 public: 00103 00104 ZMexLogNever(); 00105 // Construct this behavior 00106 00107 virtual ~ZMexLogNever(); 00108 // Destroy this behavior 00109 00110 virtual ZMexLogResult emit( const ZMexception & x ); 00111 // Extract the formatted message, then 00112 // carry out this logger's basic logging behavior 00113 00114 virtual ZMexLogNever * clone() const; 00115 // Duplicate this logger object 00116 00117 virtual ZMexLogResult emit( const std::string & s ); 00118 // Carry out this logger's basic logging behavior: do nothing with s 00119 00120 }; // ZMexLogNever 00121 00122 00123 // ------------- 00124 // ZMexLogAlways 00125 // ------------- 00126 00127 class ZMexLogAlways : public ZMexLogBehavior { 00128 00129 public: 00130 00131 ZMexLogAlways(); 00132 ZMexLogAlways( std::ostream & os ); 00133 // Construct this behavior with given destination 00134 00135 virtual ~ZMexLogAlways(); 00136 // Destroy this behavior 00137 00138 virtual ZMexLogAlways * clone() const; 00139 // Duplicate this logger object 00140 00141 virtual ZMexLogResult emit( const ZMexception & x ); 00142 // Extract the formatted message, then 00143 // carry out this logger's basic logging behavior 00144 00145 virtual ZMexLogResult emit( const std::string & s ); 00146 // Carry out this logger's basic logging behavior: myOs << s 00147 00148 private: 00149 00150 std::ostream & myOs; 00151 // This logger's destination for messages to be logged 00152 00153 }; // ZMexLogAlways 00154 00155 00156 // ------------- 00157 // ZMexLogTwice 00158 // ------------- 00159 00160 class ZMexLogTwice : public ZMexLogBehavior { 00161 00162 public: 00163 00164 ZMexLogTwice( std::ostream & os1 ); 00165 ZMexLogTwice( std::ostream & os1, std::ostream & os2 ); 00166 // Construct this behavior with given destinations 00167 00168 virtual ~ZMexLogTwice(); 00169 // Destroy this behavior 00170 00171 virtual ZMexLogTwice * clone() const; 00172 // Duplicate this logger object 00173 00174 virtual ZMexLogResult emit( const ZMexception & x ); 00175 // Extract the formatted message, then 00176 // carry out this logger's basic logging behavior 00177 00178 virtual ZMexLogResult emit( const std::string & s ); 00179 // Carry out this logger's basic logging behavior: os_ << s, os2_ << s 00180 00181 private: 00182 00183 std::ostream & myOs1; 00184 std::ostream & myOs2; 00185 00186 }; // ZMexLogTwice 00187 00188 00189 // ---------------- 00190 // ZMexLogViaParent 00191 // ---------------- 00192 00193 class ZMexLogViaParent : public ZMexLogBehavior { 00194 00195 public: 00196 00197 ZMexLogViaParent(); 00198 // Construct this behavior 00199 00200 virtual ~ZMexLogViaParent(); 00201 // Destroy this behavior 00202 00203 virtual ZMexLogViaParent * clone() const; 00204 // Duplicate this logger object 00205 00206 virtual ZMexLogResult emit( const ZMexception & x ); 00207 // Extract the formatted message, then 00208 // carry out this logger's basic logging behavior 00209 00210 virtual ZMexLogResult emit( const std::string & s ); 00211 // Carry out this logger's basic logging behavior: defer elsewhere 00212 00213 }; // ZMexLogViaParent 00214 00215 00216 // ----------------- 00217 // ZMexValidationStyle 00218 // ----------------- 00219 00220 class ZMexValidationStyle : public ZMexLogBehavior { 00221 00222 public: 00223 00224 ZMexValidationStyle(); 00225 ZMexValidationStyle( std::ostream & os ); 00226 // Construct this behavior with given destination 00227 00228 virtual ~ZMexValidationStyle(); 00229 // Destroy this behavior 00230 00231 virtual ZMexValidationStyle * clone() const; 00232 // Duplicate this logger object 00233 00234 virtual ZMexLogResult emit( const ZMexception & x ); 00235 // Extract the formatted message, then 00236 // carry out this logger's basic logging behavior 00237 00238 virtual ZMexLogResult emit( const std::string & s ); 00239 // Carry out this logger's basic logging behavior: myOs << s 00240 00241 virtual bool isTimeDesired() const; 00242 virtual bool isFilePathDesired() const; 00243 00244 private: 00245 00246 std::ostream & myOs; 00247 // This logger's destination for messages to be logged 00248 00249 }; // ZMexValidationStyle 00250 00251 //************ 00252 // ZMexLogger 00253 //************ 00254 00255 00256 class ZMexLogger : public ZMhandleTo< ZMexLogBehavior > { 00257 // Class defining logger interface 00258 00259 public: 00260 00261 ZMexLogger( const ZMexLogBehavior & desiredBehavior ); 00262 // Construct logger with specified behavior 00263 00264 ~ZMexLogger(); 00265 // Destroy logger with its behavior 00266 00267 ZMexLogResult emit( const ZMexception & exc ); 00268 // Hand over the exception for formatting and log entry 00269 00270 ZMexLogResult emit( const std::string & message ); 00271 // Hand over the given string (or char*) for log entry 00272 00273 ZMexLogBehavior * control(); 00274 // Grant access to the representation 00275 // to permit calling specialized behavior functions 00276 00277 }; // ZMexLogger 00278 00279 00280 // ---------------------------------------------------------------------- 00281 00282 00283 } // namespace zmex 00284 00285 00286 // ---------------------------------------------------------------------- 00287 00288 00289 #endif // ZMEXLOGGER_H