Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

Reporter.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2000 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell Reporter
00006 
00007    File     : Reporter.h
00008    Version  : $Revision: 1.9 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/Reporter.h,v $
00011    
00012    Copyright notice:
00013 
00014     This program is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU General Public License  
00016     as published by the Free Software Foundation; either version 2
00017     of the License, or (at your option) any later version.
00018    
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00022     GNU General Public License for more details.
00023    
00024     You should have received a copy of the GNU General Public License
00025     along with this program; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 /* ============================================================ include files */
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 /* ================================================================ constants */
00063 
00064 
00065 /* =================================================================== macros */
00066 
00067 
00068 /* =============================================================== data types */
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 /* ================================================= external data structures */
00298 
00299 
00300 /* ====================================================== function prototypes */
00301 
00302 
00303 
00304 #endif  /* REPORTER_H */
00305 
00306 
00307 /*------------------------------------------------------------------------------
00308  
00309   $Source: /cvsroot/darkice/darkice/src/Reporter.h,v $
00310 
00311   $Log: Reporter.h,v $
00312   Revision 1.9  2005/04/04 08:36:17  darkeye
00313   commited changes to enable Jack support
00314   thanks to Nicholas J. Humfrey, njh@ecs.soton.ac.uk
00315 
00316   Revision 1.8  2005/04/03 05:14:07  jbebel
00317   Changed timestamp on reported events to include date in addition to time.
00318 
00319   Revision 1.7  2004/02/15 12:06:30  darkeye
00320   added ALSA support, thanks to Christian Forster
00321 
00322   Revision 1.6  2002/05/28 12:35:41  darkeye
00323   code cleanup: compiles under gcc-c++ 3.1, using -pedantic option
00324 
00325   Revision 1.5  2001/09/05 20:11:15  darkeye
00326   removed dependency on locally stored SGI STL header files
00327   now compiler-supplied C++ library STL header files are used
00328   compiles under GNU C++ 3
00329   hash_map (an SGI extension to STL) replaced with map
00330   std:: namespace prefix added to all STL class references
00331 
00332   Revision 1.4  2001/08/30 17:25:56  darkeye
00333   renamed configure.h to config.h
00334 
00335   Revision 1.3  2000/12/20 12:47:40  darkeye
00336   added prefixVerbosity value. in a low verbosity setting no time-stamp
00337   prefix is displayed
00338 
00339   Revision 1.2  2000/11/18 11:12:01  darkeye
00340   added timestamp display, removed process id display in reports
00341   changed reportEvent functions to template functions
00342 
00343   Revision 1.1  2000/11/16 08:48:43  darkeye
00344   added multiple verbosity-level event reporting and verbosity command
00345   line option
00346 
00347 
00348   
00349 ------------------------------------------------------------------------------*/
00350 

Generated on Fri May 19 15:36:48 2006 for DarkIce by  doxygen 1.4.4