00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef REPORTER_H
00030 #define REPORTER_H
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #ifdef HAVE_CONFIG_H
00040 #include "config.h"
00041 #endif
00042
00043 #ifdef HAVE_UNISTD_H
00044 #include <unistd.h>
00045 #else
00046 #error need unistd.h
00047 #endif
00048
00049 #ifdef HAVE_TIME_H
00050 #include <time.h>
00051 #else
00052 #error need time.h
00053 #endif
00054
00055
00056 #include <iostream>
00057
00058
00059 #include "Exception.h"
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00083 class Reporter
00084 {
00085
00086 private:
00087
00091 static unsigned int verbosity;
00092
00096 static std::ostream * os;
00097
00102 static const unsigned int prefixVerbosity = 3;
00103
00107 static void
00108 printPrefix( void ) throw ()
00109 {
00110 if ( verbosity > prefixVerbosity ) {
00111 char str[32];
00112 time_t now;
00113
00114 now = time(NULL);
00115 strftime( str, 32, "%d-%b-%Y %H:%M:%S ", localtime(&now) );
00116 (*(Reporter::os)) << str;
00117 }
00118 }
00119
00120
00121 protected:
00122
00123
00124 public:
00125
00131 inline virtual
00132 ~Reporter ( void ) throw ( Exception )
00133 {
00134 (Reporter::os)->flush();
00135 }
00136
00143 static inline void
00144 setReportVerbosity ( unsigned int verbosity ) throw ()
00145 {
00146 Reporter::verbosity = verbosity;
00147 }
00148
00154 static inline unsigned int
00155 getReportVerbosity ( void ) throw ()
00156 {
00157 return Reporter::verbosity;
00158 }
00159
00166 static inline void
00167 setReportOutputStream ( std::ostream & os ) throw ()
00168 {
00169 Reporter::os = &os;
00170 }
00171
00177 static inline std::ostream &
00178 getReportOutputStream ( void ) throw ()
00179 {
00180 return *(Reporter::os);
00181 }
00182
00192 template<class T>
00193 static inline void
00194 reportEvent ( unsigned int verbosity,
00195 const T t ) throw ()
00196 {
00197 if ( Reporter::verbosity >= verbosity ) {
00198 printPrefix();
00199 (*(Reporter::os)) << t << std::endl;
00200 }
00201 }
00202
00215 template<class T, class U>
00216 inline void
00217 static reportEvent ( unsigned int verbosity,
00218 const T t,
00219 const U u ) throw ()
00220 {
00221 if ( Reporter::verbosity >= verbosity ) {
00222 printPrefix();
00223 (*(Reporter::os)) << t << " "
00224 << u << std::endl;
00225 }
00226 }
00227
00243 template<class T, class U, class V>
00244 static inline void
00245 reportEvent ( unsigned int verbosity,
00246 const T t,
00247 const U u,
00248 const V v ) throw ()
00249 {
00250 if ( Reporter::verbosity >= verbosity ) {
00251 printPrefix();
00252 (*(Reporter::os)) << t << " "
00253 << u << " "
00254 << v << std::endl;
00255 }
00256 }
00257
00276 template<class T, class U, class V, class W>
00277 static inline void
00278 reportEvent ( unsigned int verbosity,
00279 const T t,
00280 const U u,
00281 const V v,
00282 const W w ) throw ()
00283 {
00284 if ( Reporter::verbosity >= verbosity ) {
00285 printPrefix();
00286 (*(Reporter::os)) << t << " "
00287 << u << " "
00288 << v << " "
00289 << w << std::endl;
00290 }
00291 }
00292 };
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 #endif
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350