certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi/libCERTI PrettyDebug.hh PrettyDebug.cc De...


From: certi-cvs
Subject: [certi-cvs] certi/libCERTI PrettyDebug.hh PrettyDebug.cc De...
Date: Wed, 21 Oct 2009 19:51:13 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      09/10/21 19:51:13

Modified files:
        libCERTI       : PrettyDebug.hh PrettyDebug.cc DebugOStream.hh 
                         PrettyDebEx.cc 

Log message:
        Merge in
        patch #6954: Logging system improovements, cleanup
        0002-Rework-PrettyDebug-erk1.patch

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/PrettyDebug.hh?cvsroot=certi&r1=4.6&r2=4.7
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/PrettyDebug.cc?cvsroot=certi&r1=4.9&r2=4.10
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/DebugOStream.hh?cvsroot=certi&r1=4.2&r2=4.3
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/PrettyDebEx.cc?cvsroot=certi&r1=4.6&r2=4.7

Patches:
Index: PrettyDebug.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/PrettyDebug.hh,v
retrieving revision 4.6
retrieving revision 4.7
diff -u -b -r4.6 -r4.7
--- PrettyDebug.hh      21 Oct 2009 18:56:28 -0000      4.6
+++ PrettyDebug.hh      21 Oct 2009 19:51:12 -0000      4.7
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: PrettyDebug.hh,v 4.6 2009/10/21 18:56:28 erk Exp $
+// $Id: PrettyDebug.hh,v 4.7 2009/10/21 19:51:12 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef PRETTYDEBUG_HH
@@ -29,18 +29,10 @@
 #define NDEBUG
 #endif
 
+#include "certi.hh"
 #include "DebugOStream.hh"
+#include <iosfwd>
 #include <string>
-#include "RTI.hh"
-
-#define pdSEmptyMessage "Pretty Debug Server empty Message."
-
-// Pretty Debug Basic types
-typedef unsigned TDebugLevel;
-
-
-// Pretty Debug Constants
-#define pdMaxMessageSize 255  // greater then pdTooLongInitMessage length!
 
 /** Do not use the pdUnused and pdLast Levels!!! Do not also specify
  *  any value for the elements, because order is used and missing
@@ -68,79 +60,82 @@
 // debug level are enabled, and all others are not enabled.
 
 // KEEP THE SAME ORDER AS IN THE pdDebugLevel ENUM!
-#define pdDebugKeysString ":ACDEGIMPRSTWXZ\0"
+#define pdDebugKeysString ":ACDEGIMPRSTWXZ"
+
+// This is the standard way to issue debug messages into the debug streams.
+// Use that as follows:
+//
+// static PrettyDebug D("Name", "Header");
+//
+// [...]
+//
+//   Debug(D, pdDebug) << "This is a usual std::ostream shich could be used 
like that\n";
+//
+// Note that this is about the least runtim overhead you can have with dynamic 
debug messages
+// as the only thing that happens exactly once is the check against the null 
pointer in
+// the stream return. That is even optimized into fast inline path and a more 
expensive part
+// in case we really need the some output.
+// The next thing is that it can be used with *everything* that could be 
output to
+// an std::ostream without the need to maintain an extra debug stream type.
+// In the current case this make certi compile on win64 :)
+#define Debug(pd, level) \
+if (std::ostream* os = pd.getStream(level)) *os
 
 //---------------------------------------------------------------------------
 class CERTI_EXPORT PrettyDebug {
-    
-    public :
-       static void setFederateName( const std::string &inName )
-          { federateName_ = inName ; }
-       static void setFederateName( const char *inName )
-          { federateName_ = inName ; }
-protected :
-       static std::string federateName_ ;
-private:
-    char* LEnvVar;                     /**< Name of the environment variable 
to look for. */
-    char* LMessage;                    /**< The container of all printed debug 
messages. 
-                                       Start with the Header specified at 
construction time */
-    char* HeaderMessage;       /**< The header message specified at 
construction time. */
- 
-    static DebugOStream defaultOutputStream;
-    static DebugOStream* nullOutputStreamPtr;
-    static DebugOStream& nullOutputStream;
-    
-    #ifdef _WIN32                              //Mutex : Print Control
-                static HANDLE  g_hMutex;
-    #endif
- 
-    /** If Level_Map[Level] != &PrettyDebug::nullOutputStream, then the
-       debug message must be printed in the ostream addressed. */
-    DebugOStream* Level_Map [pdLast + 1];
-
-    void Print(DebugOStream& theOutputStream, 
-                      const char* theHeaderMessage, 
-                      const char * Message);
-
-    // Parse the environment variable value to find debug keys and
-    // enable debug levels
-    void ParseEnvString(const char * Name);
-
 public:  
-    PrettyDebug(const char * Name, const char * Header);
+    PrettyDebug(const char* name, const char* header);
     ~PrettyDebug();
   
-  
-    bool Mode(pdDebugLevel Level);
-
-    void enableDebugLevel(pdDebugLevel Level, 
-                          DebugOStream& theOutputStream = 
PrettyDebug::defaultOutputStream);
+    void enableDebugLevel(pdDebugLevel Level);
+    void enableDebugLevel(pdDebugLevel Level, std::ostream& stream);
     void disableDebugLevel(pdDebugLevel Level);
   
-    DebugOStream& operator[](pdDebugLevel Level) //Inline method
+    // Get the ostream to print debug messages to.
+    // Returns zero if debugging is not enabled for the given level.
+    std::ostream* getStream(pdDebugLevel level)
     {
-        DebugOStream* theReturnedOutputStreamPtr = (Level_Map[Level]);
-        if (theReturnedOutputStreamPtr == PrettyDebug::nullOutputStreamPtr) {
-            return(PrettyDebug::nullOutputStream);
-        }
-        Print( *theReturnedOutputStreamPtr, HeaderMessage, "" );
-        return(*theReturnedOutputStreamPtr);
+        // make sure this is an unsigned value to so just one check is 
sufficient
+        if (unsigned(pdLast) <= unsigned(level))
+            return 0;
+        if (!_streams[level])
+            return 0;
+        return getStreamPrintHeader(level);
     }
  
+    static void setFederateName(const std::string& inName)
+    { _federateName = inName; }
+    static void setFederateName(const char* inName)
+    { if (inName) _federateName = inName; }
+
 #ifdef NDEBUG
-    inline void Out(pdDebugLevel Level, const char *Format, ...) {};
+    void Out(pdDebugLevel level, const char *format, ...) {}
+
+    DebugOStream operator[](pdDebugLevel level)
+    { return DebugOStream(0); }
 #else
-       void Out(pdDebugLevel Level, const char *Format, ...);
-       void Mes(pdDebugLevel Level, const char type, const short testMess, 
const char *context);
+    void Out(pdDebugLevel level, const char *format, ...);
+    void Mes(pdDebugLevel level, const char type, const short testMess, const 
char *context);
 
+    DebugOStream operator[](pdDebugLevel level)
+    { return DebugOStream(getStreamPrintHeader(level)); }
 #endif
 
-};
+private:
+    // Print the message header for the given level and return the apropriate 
stream
+    std::ostream* getStreamPrintHeader(pdDebugLevel level);
 
+    std::string _name;
+    std::string _header;
+    std::ostream* _streams[pdLast];
+
+    static std::ostream _defaultOutputStream;
+    static std::string _federateName;
+};
 
 // Alias
 typedef PrettyDebug PrettyDebug ; ///< \deprecated PrettyDebug replaced by 
PrettyDebug
 
 #endif // PRETTYDEBUG_HH
 
-// $Id: PrettyDebug.hh,v 4.6 2009/10/21 18:56:28 erk Exp $
+// $Id: PrettyDebug.hh,v 4.7 2009/10/21 19:51:12 erk Exp $

Index: PrettyDebug.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/PrettyDebug.cc,v
retrieving revision 4.9
retrieving revision 4.10
diff -u -b -r4.9 -r4.10
--- PrettyDebug.cc      27 May 2008 12:26:54 -0000      4.9
+++ PrettyDebug.cc      21 Oct 2009 19:51:12 -0000      4.10
@@ -19,174 +19,73 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: PrettyDebug.cc,v 4.9 2008/05/27 12:26:54 jmm Exp $
+// $Id: PrettyDebug.cc,v 4.10 2009/10/21 19:51:12 erk Exp $
 // ----------------------------------------------------------------------------
 
-
 #include "PrettyDebug.hh"
-#include "Message.hh"
-#include "NetworkMessage.hh"
 
-#include <stdlib.h>
-#include <stdarg.h>
 #include <iostream>
-#include <cstring>
-#ifdef _WIN32
-       #include <time.h>
-       #include <sys/timeb.h>
-#else
-       #include <sys/types.h>
-       #include <sys/time.h>
-       #include <unistd.h>
-       #include <string>
-       #include <libgen.h>
-#endif
+#include <iomanip>
 
-using std::cout ;
-using std::cerr ;
-using std::endl ;
-
-DebugOStream DebugOStream::nullOutputStream(cout);
-DebugOStream PrettyDebug::defaultOutputStream(cerr);
-
-//Fix this pointer to the default initialisation of pointers for your compiler
-DebugOStream* PrettyDebug::nullOutputStreamPtr = 0 ; 
-DebugOStream& PrettyDebug::nullOutputStream = DebugOStream::nullOutputStream;
-
-#ifdef _WIN32          //Mutex switch ON
-       HANDLE PrettyDebug::g_hMutex= CreateMutex(NULL,FALSE,"HLA");    
-#endif
-
-std::string PrettyDebug::federateName_ = "" ;
-
-// ----------------------------------------------------------------------------
-/** Print the message to the default output ostream.
- *  This function does NOT add any trailing \n. */
-void
-PrettyDebug::Print(DebugOStream& theOutputStream,
-                   const char* theHeaderMessage, const char * Message)
-{
-char buffer[256] ;
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #ifdef _WIN32
-       if (WaitForSingleObject(g_hMutex,INFINITE) == WAIT_OBJECT_0)
-               {//Wait for Mutex
-               struct _timeb timebuffer;_ftime(&timebuffer );
-               sprintf(buffer,"HLALOG - %I64d.%03hd s - %s", 
timebuffer.time,timebuffer.millitm,federateName_.c_str());
-
-               if (Message != NULL)
-                       theOutputStream << buffer << " - " << theHeaderMessage 
<< "> " << Message;
-               else
-                       theOutputStream << buffer << " - " << theHeaderMessage 
<< pdSEmptyMessage;
-                       
-               theOutputStream.flush();
-               ReleaseMutex(g_hMutex);
-               }
+# include <time.h>
+# include <sys/timeb.h>
 #else
-       struct timeval tv;
-       gettimeofday( &tv, NULL );
-       sprintf( buffer, "HLALOG - %ld.%06ld - 
%s",tv.tv_sec,tv.tv_usec,federateName_.c_str() ) ;
-
-       if (Message != NULL)
-               theOutputStream << buffer << " - " << basename((char 
*)theHeaderMessage) << "> " << Message;
-       else
-               theOutputStream << buffer << " - " << basename((char 
*)theHeaderMessage) << pdSEmptyMessage;
-       theOutputStream.flush();        
+# include <sys/time.h>
 #endif
-}
 
-// ----------------------------------------------------------------------------
-/** Parse the environment variable value to find debug keys and enable
- *  debug levels.  The internal LEnvVar and LMessage variables must
- *  already have been set. */
-void
-PrettyDebug::ParseEnvString(const char *Name)
-{
-unsigned int i;
-char *Value = getenv(Name); // The value of the variable Name
-char  Key; // A character from the value compared to keys.
-char *Pos; // The position of Key in pdDebugKeys
-char *DebugKeys = (char *) pdDebugKeysString ; // needs a non const string
-
-for (i = pdUnused; i < pdLast + 1; i++) // Clear current level map
-       Level_Map[i] = PrettyDebug::nullOutputStreamPtr;
-
-if (Value != 0) 
-       { // Print Debug Init Message
-       const char *pdInitMessage = " variable read, content = ";
-       const char *pdTooLongInitMessage = "Env Var read(string too long).";
-       
-       int length = strlen(LEnvVar) + strlen(pdInitMessage) + strlen(Value);
-       if (length < pdMaxMessageSize)
-               cout << LEnvVar << pdInitMessage << Value << endl;
-       else
-               cout << LEnvVar << pdTooLongInitMessage << endl;
-
-       // Compare each char of Value to content of the pgDebugKeys 
-       // string, to enable matching debug levels.
-       for (i = 0; i < strlen(Value); i++) 
-               {
-               Key = Value[i];
-               Pos = strchr(DebugKeys, Key);
-               if (Pos != 0)
-                        Level_Map[Pos - DebugKeys] = 
&(PrettyDebug::defaultOutputStream);
-               }
-       }
-return;
-}
+std::ostream PrettyDebug::_defaultOutputStream(std::cerr.rdbuf());
+std::string PrettyDebug::_federateName;
 
 // 
---------------------------------------------------------------------------- 
 /** Constructor. Initialize the debug process according to the value
- *  of the 'Name' environment variable.  The 'Header' message is put
+ *  of the 'name' environment variable.  The 'header' message is put
  *  in front of all printed debug messages. It can be a module name or
  *  whatever you need. */
-PrettyDebug::PrettyDebug(const char *Name, const char *Header)
+PrettyDebug::PrettyDebug(const char* name, const char* header)
 {
-if (NULL == Name) 
-       {
-       PrettyDebug::Print(PrettyDebug::defaultOutputStream, "", 
-       "Error in pgCDebug constructor, no Name specified.\n");
-        Name = "NoName";
-       }
+    if (header)
+        _header = header;
 
-LEnvVar = strdup(Name);
-if (Header != 0)
-       HeaderMessage = strdup(Header);
-else
-       HeaderMessage = strdup("");
-
-//Initialisation de LMessage a 0. Il est alloue la premiere fois
-//dans la methode Out.
-LMessage = 0;
-
-if ((LEnvVar == 0) || (HeaderMessage == 0)) 
-       {
-       PrettyDebug::Print(PrettyDebug::defaultOutputStream, "", 
-       "Error in pgCDebug constructor memory allocation.\n");
-       exit(EXIT_FAILURE);
+    for (unsigned i = pdUnused; i < unsigned(pdLast); ++i)
+       _streams[i] = 0;
+
+    // note that if we do not have a name, we cannot enable any debug message 
...
+    if (name) {
+        const char *value = getenv(name);
+        if (value) {
+            // Compare each char of Value to content of the pgDebugKeys
+            // string, to enable matching debug levels.
+            char debugKeys[] = pdDebugKeysString;
+            unsigned valueLen = strlen(value);
+            for (unsigned i = 0; i < valueLen; ++i) {
+               const char* pos = strchr(debugKeys, value[i]);
+               if (pos)
+                    _streams[pos - debugKeys] = &_defaultOutputStream;
+            }
+        }
        }
-ParseEnvString(Name);
 }
 
 // ----------------------------------------------------------------------------
 /** Destructor. */
 PrettyDebug::~PrettyDebug()
 {
-    free(LEnvVar);
-    if (LMessage != 0) {
-        free(LMessage);
-    }
-    if (HeaderMessage != 0) {
-        free(HeaderMessage);
-    }
 }
 
 // ----------------------------------------------------------------------------
-/** Return true if Level is enabled, else return false. */
-bool
-PrettyDebug::Mode(pdDebugLevel Level)
+/** Enable the echoing of the given debug level with the default
+ *  ostream or modify the ostream if the debug level was already
+ *  enabled. */
+void
+PrettyDebug::enableDebugLevel(pdDebugLevel level)
 {
-    return (Level_Map[Level] != PrettyDebug::nullOutputStreamPtr);
+    enableDebugLevel(level, std::cerr);
 }
 
 // ----------------------------------------------------------------------------
@@ -196,83 +95,85 @@
  *  stored, it is not copied so the ostream MUST exist until the
  *  destruction of the PrettyDebug or until the level is disabled */
 void
-PrettyDebug::enableDebugLevel(pdDebugLevel Level, DebugOStream& 
theOutputStream)
+PrettyDebug::enableDebugLevel(pdDebugLevel level, std::ostream& stream)
 {
-    Level_Map[Level] = &(theOutputStream);
+    if (unsigned(pdLast) <= unsigned(level))
     return;
+    _streams[level] = &stream;
 }
 
 // ----------------------------------------------------------------------------
 /** Disable the echoing of the given debug level. */
 void
-PrettyDebug::disableDebugLevel(pdDebugLevel Level)
+PrettyDebug::disableDebugLevel(pdDebugLevel level)
 {
-    Level_Map[Level] = PrettyDebug::nullOutputStreamPtr;
+    if (unsigned(pdLast) <= unsigned(level))
     return;
+    _streams[level] = 0;
 }
      
-// ----------------------------------------------------------------------------
 #ifndef NDEBUG
-/** If Level is enabled, Message is sent to the DebugServer, preceded
+// ----------------------------------------------------------------------------
+/** If level is enabled, Message is sent to the DebugServer, preceded
    with the Header specified in the Constructor.  If the NDEBUG
    constant is defined, the Out method has beed declared inline, and
    its body set to {} (see PrettyDebug.hh).
-
-   \attention: Probleme, rien ne garantit qu'on ne depassera pas le
-   nombre max de char dans le vsprintf. Mieux vaut utiliser la syntaxe C++ 
 */
 void
-PrettyDebug::Out(pdDebugLevel Level, const char * Format, ...)
+PrettyDebug::Out(pdDebugLevel level, const char *format, ...)
 {
-DebugOStream* theOutputStreamPtr = Level_Map[Level];
+    // Fast return if streams are not enabled for this level.
+    std::ostream* stream = getStreamPrintHeader(level);
+    if (!stream)
+        return;
 
-//Warnings messages
-//if (LEnvVar == 0) cout << endl << "ENV VAR NULL CALLING OUT METHOD ";
-//if (HeaderMessage == 0) cout << "HEADER NULL CALLING OUT METHOD" << endl;
-
-if (theOutputStreamPtr != PrettyDebug::nullOutputStreamPtr) 
-       {
-       if (Format != 0) 
-               { // Cat Header and Message strings 
-               if (LMessage == 0) 
-                       { // A final printed message is
-                                               // Header+Message+\n(+\0) 
-                       //Optimisation, on pourrait peut-etre mettre LMessage
-                       //en static.  Mais il ne faudra pas que dans un D.Out
-                       //qu'on appelle un autre D.Out car autrement, seul un
-                       //message serait affiche.
-
-                       LMessage = (char *) malloc((pdMaxMessageSize+2) * 
sizeof(char));
-
-                       if (LMessage == 0)
-                               { 
-                               
PrettyDebug::Print(PrettyDebug::defaultOutputStream,
-                                                               HeaderMessage, 
-                                                               "Error in 
pgCDebug Out method while "
-                                                               "allocating 
initial memory for messages\n");
-                               exit(EXIT_FAILURE);
-                               }
-               //                else
-               //                    
PrettyDebug::Print(PrettyDebug::defaultOutputStream, 
-               //                                    HeaderMessage, "Allocated 
initial memory "
-               //                                    "for Message buffer.\n");
-                       }
-               va_list argptr; // Variable Argument list, see stdarg.h
-               va_start(argptr, Format);
-               //Probleme, rien ne garantit qu'on ne depassera pas le
-               //nombre max de char dans le vsprintf.
-               vsprintf(LMessage, Format, argptr); 
+    if (!format) {
+        *stream << "Pretty Debug received an empty Message.\n";
+    } else {
+        char buffer[512];
+
+        va_list argptr;
+        va_start(argptr, format);
+        vsnprintf(buffer, sizeof(buffer), format, argptr);
                va_end(argptr);
-               }
-       else
-               strcpy(LMessage, "Pretty Debug received an empty Message.");
                
-       strcat(LMessage, "\n"); // Add trailing \n
-       PrettyDebug::Print(*theOutputStreamPtr, HeaderMessage, LMessage);
+        *stream << buffer << '\n';
        }
-return;
 }
+#endif
+
+// ----------------------------------------------------------------------------
+/** If level is enabled, print the debug header for this level and return
+    a std::ostream pointer to print debug messates to. If the given level is 
not
+    active returns a null pointer.
+*/
+std::ostream*
+PrettyDebug::getStreamPrintHeader(pdDebugLevel level)
+{
+    // Print a standard message header and return the stream where the rest 
should go.
+
+    std::ostream* stream = _streams[level];
+    if (!stream)
+        return 0;
+
+    *stream << "HLALOG - ";
 
-#endif // NDEBUG
+    // System dependent timestamp
+#ifdef _WIN32
+    struct _timeb timebuffer;
+    _ftime(&timebuffer);
+    *stream << timebuffer.time << '.' << std::setw(3) << std::right
+            << std::setfill('0') << timebuffer.millitm;
+#else
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    *stream << tv.tv_sec << '.' << std::setw(6) << std::right
+            << std::setfill('0') << tv.tv_usec;
+#endif
+
+    *stream << ' ' << _federateName << " - " << _header << "> ";
+
+    return stream;
+}
 
-// $Id: PrettyDebug.cc,v 4.9 2008/05/27 12:26:54 jmm Exp $
+// $Id: PrettyDebug.cc,v 4.10 2009/10/21 19:51:12 erk Exp $

Index: DebugOStream.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/DebugOStream.hh,v
retrieving revision 4.2
retrieving revision 4.3
diff -u -b -r4.2 -r4.3
--- DebugOStream.hh     10 Dec 2008 16:53:23 -0000      4.2
+++ DebugOStream.hh     21 Oct 2009 19:51:13 -0000      4.3
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: DebugOStream.hh,v 4.2 2008/12/10 16:53:23 erk Exp $
+// $Id: DebugOStream.hh,v 4.3 2009/10/21 19:51:13 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef _CERTI_DEBUGOSTREAM_HH
@@ -33,53 +33,51 @@
 class CERTI_EXPORT DebugOStream
 {
 private:
-    std::ostream& ostr;
+    std::ostream* ostr;
 
 public:
-    static DebugOStream nullOutputStream;
-
-    DebugOStream(std::ostream& theostr) : ostr(theostr) {}
+    DebugOStream(std::ostream* theostr) : ostr(theostr) {}
 
     int isNullOstream(void) {
-        return(this != &(nullOutputStream));
+        return ostr == 0;
     }
 
     // Global insertors on strings and characters are defined as
     // members of DebugOStream.
     DebugOStream& operator<<(const char* thestr)
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr << thestr;
+        if (ostr)
+            *ostr << thestr;
         return *this ;
     }
 
     DebugOStream& operator<<(const signed char* thestr)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << thestr;
+        if (ostr) *ostr << thestr;
         return *this ;
     }
 
     DebugOStream& operator<<(const unsigned char* thestr)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << thestr;
+        if (ostr) *ostr << thestr;
         return *this ;
     }
 
     DebugOStream& operator<<(char ch)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << ch;
+        if (ostr) *ostr << ch;
         return *this ;
     }
 
     DebugOStream& operator<<(signed char ch)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << ch;
+        if (ostr) *ostr << ch;
         return *this ;
     }
 
     DebugOStream& operator<<(unsigned char ch)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << ch;
+        if (ostr) *ostr << ch;
         return *this ;
     }
 
@@ -87,68 +85,68 @@
     //Arithmetic Inserters
     DebugOStream& operator<<(bool n)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << n;
+        if (ostr) *ostr << n;
         return(*this);
     }
 
     DebugOStream& operator<<(short n)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << n;
+        if (ostr) *ostr << n;
         return(*this);
     }
 
     DebugOStream& operator<<(unsigned short n)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << n;
+        if (ostr) *ostr << n;
         return(*this);
     }
 
     DebugOStream& operator<<(int n)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << n;
+        if (ostr) *ostr << n;
         return(*this);
     }
 
     DebugOStream& operator<<(unsigned int n)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << n;
+        if (ostr) *ostr << n;
         return(*this);
     }
 
     DebugOStream& operator<<(long n)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << n;
+        if (ostr) *ostr << n;
         return(*this);
     }
 
     DebugOStream& operator<<(unsigned long n)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << n;
+        if (ostr) *ostr << n;
         return(*this);
     }
 
     DebugOStream& operator<<(float f)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << f;
+        if (ostr) *ostr << f;
         return(*this);
     }
 
     DebugOStream& operator<<(double f)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << f;
+        if (ostr) *ostr << f;
         return(*this);
     }
 
     DebugOStream& operator<<(long double f)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << f;
+        if (ostr) *ostr << f;
         return(*this);
     }
 
     //Specifique gcc, dans la norme le pointeur n'est pas constant.
     DebugOStream& operator<<(const void* p)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << p;
+        if (ostr) *ostr << p;
         return(*this);
     }
 
@@ -171,7 +169,7 @@
     //Specifique gcc
     DebugOStream& operator<<(std::streambuf* sb)
     {
-        if (this != &(DebugOStream::nullOutputStream)) ostr << sb;
+        if (ostr) *ostr << sb;
         return(*this);
     }
 
@@ -186,66 +184,66 @@
 
     DebugOStream& operator<<(std::ostream& (*pf)(std::ostream&))
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr << pf;
+        if (ostr)
+            *ostr << pf;
         return(*this);
     }
 
     DebugOStream& operator<<(std::ios& (*pf)(std::ios&))
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr << pf;
+        if (ostr)
+            *ostr << pf;
         return(*this);
     }
 
     DebugOStream& operator<<(std::ios_base& (*pf)(std::ios_base&))
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr << pf;
+        if (ostr)
+            *ostr << pf;
         return(*this);
     }
 
     // Unformatted output:
     DebugOStream& put(char c)
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr.put(c);
+        if (ostr)
+            ostr->put(c);
         return(*this);
     }
 
     DebugOStream& write(const char* str, std::streamsize n)
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr.write(str, n);
+        if (ostr)
+            ostr->write(str, n);
         return(*this);
     }
 
     // Other methods
     DebugOStream& flush(void)
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr.flush();
+        if (ostr)
+            ostr->flush();
         return(*this);
     }
 
     DebugOStream& seekp(std::streampos pos)
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr.seekp(pos);
+        if (ostr)
+            ostr->seekp(pos);
         return(*this);
     }
 
     DebugOStream& seekp(std::streamoff off, std::ios_base::seekdir dir)
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            ostr.seekp(off, dir);
+        if (ostr)
+            ostr->seekp(off, dir);
         return(*this);
     }
 
     std::streampos tellp(void)
     {
-        if (this != &(DebugOStream::nullOutputStream))
-            return(ostr.tellp());
+        if (ostr)
+            return(ostr->tellp());
         else return(0);
     }
 
@@ -258,4 +256,4 @@
 
 #endif // _CERTI_DEBUGOSTREAM_HH
 
-// $Id: DebugOStream.hh,v 4.2 2008/12/10 16:53:23 erk Exp $
+// $Id: DebugOStream.hh,v 4.3 2009/10/21 19:51:13 erk Exp $

Index: PrettyDebEx.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/PrettyDebEx.cc,v
retrieving revision 4.6
retrieving revision 4.7
diff -u -b -r4.6 -r4.7
--- PrettyDebEx.cc      20 Nov 2008 18:21:56 -0000      4.6
+++ PrettyDebEx.cc      21 Oct 2009 19:51:13 -0000      4.7
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: PrettyDebEx.cc,v 4.6 2008/11/20 18:21:56 approx Exp $
+// $Id: PrettyDebEx.cc,v 4.7 2009/10/21 19:51:13 erk Exp $
 // ----------------------------------------------------------------------------
 
 
@@ -51,10 +51,11 @@
 //type: 'N'    NetWork Message 
 void PrettyDebug::Mes(pdDebugLevel Level, const char type, const short 
testMess, const char *context)
 {
-char theMessage[100];
+    std::ostream* stream = getStreamPrintHeader(Level);
+    if (!stream)
+        return;
 
-DebugOStream* theOutputStreamPtr = Level_Map[Level];
-if (theOutputStreamPtr == PrettyDebug::nullOutputStreamPtr) return;    
//----------------->>
+char theMessage[100];
 
 strcpy(theMessage,context);
        
@@ -313,8 +314,8 @@
                }
        }
 strcat(theMessage, "\n"); // Add trailing \n
-PrettyDebug::Print(*theOutputStreamPtr, HeaderMessage, theMessage);
+ *stream << theMessage;
 }
 #endif // NDEBUG
 
-// $Id: PrettyDebEx.cc,v 4.6 2008/11/20 18:21:56 approx Exp $
+// $Id: PrettyDebEx.cc,v 4.7 2009/10/21 19:51:13 erk Exp $




reply via email to

[Prev in Thread] Current Thread [Next in Thread]