Main Page   Class Hierarchy   Compound List   File List   Compound Members  

reporter.h

00001 /*
00002     Copyright (C) 2001 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __IVARIA_REPORTER_H__
00020 #define __IVARIA_REPORTER_H__
00021 
00022 #include <stdarg.h>
00023 #include "csutil/scf.h"
00024 #include "cssys/sysfunc.h"
00025 #include "iutil/objreg.h"
00026 
00027 struct iReporter;
00028 
00034 #define CS_REPORTER_SEVERITY_BUG 0
00035 
00041 #define CS_REPORTER_SEVERITY_ERROR 1
00042 
00047 #define CS_REPORTER_SEVERITY_WARNING 2
00048 
00053 #define CS_REPORTER_SEVERITY_NOTIFY 3
00054 
00060 #define CS_REPORTER_SEVERITY_DEBUG 4
00061 
00062 SCF_VERSION (iReporterListener, 0, 0, 1);
00063 
00068 struct iReporterListener : public iBase
00069 {
00075   virtual bool Report (iReporter* reporter, int severity, const char* msgId,
00076         const char* description) = 0;
00077 };
00078 
00079 SCF_VERSION (iReporter, 0, 0, 3);
00080 
00084 struct iReporter : public iBase
00085 {
00091   virtual void Report (int severity, const char* msgId,
00092         const char* description, ...) = 0;
00093 
00097   virtual void ReportV (int severity, const char* msgId,
00098         const char* description, va_list) = 0;
00099 
00105   virtual void Clear (int severity = -1) = 0;
00106 
00113   virtual void Clear (const char* mask) = 0;
00114 
00118   virtual int GetMessageCount () const = 0;
00119 
00123   virtual int GetMessageSeverity (int idx) const = 0;
00124 
00128   virtual const char* GetMessageId (int idx) const = 0;
00129 
00133   virtual const char* GetMessageDescription (int idx) const = 0;
00134 
00141   virtual void AddReporterListener (iReporterListener* listener) = 0;
00142 
00149   virtual void RemoveReporterListener (iReporterListener* listener) = 0;
00150 
00154   virtual bool FindReporterListener (iReporterListener* listener) = 0;
00155 
00156   //----------------------------------------------------------------------
00157   // Conveniance functions, these are not to be implemented.
00158   //----------------------------------------------------------------------
00159 
00163   void ReportError (const char* msgId, const char* description, ...)
00164   {
00165     va_list arg;
00166     va_start (arg, description);
00167     ReportV (CS_REPORTER_SEVERITY_ERROR, msgId, description, arg);
00168     va_end (arg);
00169   }
00170 
00174   void ReportWarning (const char* msgId, const char* description, ...)
00175   {
00176     va_list arg;
00177     va_start (arg, description);
00178     ReportV (CS_REPORTER_SEVERITY_WARNING, msgId, description, arg);
00179     va_end (arg);
00180   }
00181 
00185   void ReportNotify (const char* msgId, const char* description, ...)
00186   {
00187     va_list arg;
00188     va_start (arg, description);
00189     ReportV (CS_REPORTER_SEVERITY_NOTIFY, msgId, description, arg);
00190     va_end (arg);
00191   }
00192 
00196   void ReportBug (const char* msgId, const char* description, ...)
00197   {
00198     va_list arg;
00199     va_start (arg, description);
00200     ReportV (CS_REPORTER_SEVERITY_BUG, msgId, description, arg);
00201     va_end (arg);
00202   }
00203 
00207   void ReportDebug (const char* msgId, const char* description, ...)
00208   {
00209     va_list arg;
00210     va_start (arg, description);
00211     ReportV (CS_REPORTER_SEVERITY_DEBUG, msgId, description, arg);
00212     va_end (arg);
00213   }
00214 };
00215 
00216 
00217 /*
00218  * Helper class for csReport().  Not all compilers allow a bare `vararg'
00219  * function to be inlined, but wrapping the function in a class seems to
00220  * appease such compilers.  The NextStep compiler exhibits this particular
00221  * behavior.
00222  */
00223 class csReporterHelper
00224 {
00225 public:
00226   static void Report(iObjectRegistry* reg, int severity, char const* msgId,
00227     char const* description, ...)
00228   {
00229     va_list arg;
00230     va_start(arg, description);
00231     iReporter* reporter = CS_QUERY_REGISTRY(reg, iReporter);
00232     if (reporter)
00233     {
00234       reporter->ReportV(severity, msgId, description, arg);
00235       reporter->DecRef ();
00236     }
00237     else
00238     {
00239       csPrintfV(description, arg);
00240       csPrintf("\n");
00241     }
00242     va_end (arg);
00243   }
00244 };
00245 
00250 #define csReport csReporterHelper::Report
00251 
00252 #endif // __IVARIA_REPORTER_H__
00253 

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000