home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / xpcom / src / nsDebug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.3 KB  |  158 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef nsDebug_h___
  20. #define nsDebug_h___
  21.  
  22. #include "nsCom.h"
  23. #include "prtypes.h"
  24.  
  25. #ifdef DEBUG
  26. #define NS_DEBUG
  27. #endif
  28.  
  29. /**
  30.  * Namespace for debugging methods. Note that your code must use the
  31.  * macros defined later in this file so that the debug code can be
  32.  * conditionally compiled out.
  33.  */
  34. class nsDebug {
  35. public:
  36.   // XXX add in log controls here
  37.   // XXX probably want printf type arguments
  38.  
  39.   /**
  40.    * Abort the executing program. This works on all architectures.
  41.    */
  42.   static NS_COM void Abort(const char* aFile, PRIntn aLine);
  43.  
  44.   /**
  45.    * Log a pre-condition message to the debug log
  46.    */
  47.   static NS_COM void PreCondition(const char* aStr, const char* aExpr,
  48.                   const char* aFile, PRIntn aLine);
  49.  
  50.   /**
  51.    * Log a post-condition message to the debug log
  52.    */
  53.   static NS_COM void PostCondition(const char* aStr, const char* aExpr,
  54.                    const char* aFile, PRIntn aLine);
  55.  
  56.   /**
  57.    * Log an assertion message to the debug log
  58.    */
  59.   static NS_COM void Assertion(const char* aStr, const char* aExpr,
  60.                    const char* aFile, PRIntn aLine);
  61.  
  62.   /**
  63.    * Log a not-yet-implemented message to the debug log
  64.    */
  65.   static NS_COM void NotYetImplemented(const char* aMessage,
  66.                        const char* aFile, PRIntn aLine);
  67.  
  68.   /**
  69.    * Log a not-reached message to the debug log
  70.    */
  71.   static NS_COM void NotReached(const char* aMessage,
  72.                 const char* aFile, PRIntn aLine);
  73.  
  74.   /**
  75.    * Log an error message to the debug log. This call returns.
  76.    */
  77.   static NS_COM void Error(const char* aMessage,
  78.                const char* aFile, PRIntn aLine);
  79.  
  80.   /**
  81.    * Log a warning message to the debug log.
  82.    */
  83.   static NS_COM void Warning(const char* aMessage,
  84.                  const char* aFile, PRIntn aLine);
  85. };
  86.  
  87. #ifdef NS_DEBUG
  88. /**
  89.  * Test a precondition for truth. If the expression is not true then
  90.  * trigger a program failure.
  91.  */
  92. #define NS_PRECONDITION(expr,str) \
  93. if (!(expr))              \
  94.   nsDebug::PreCondition(str, #expr, __FILE__, __LINE__)
  95.  
  96. /**
  97.  * Test an assertion for truth. If the expression is not true then
  98.  * trigger a program failure.
  99.  */
  100. #define NS_ASSERTION(expr,str) \
  101. if (!(expr))               \
  102.   nsDebug::Assertion(str, #expr, __FILE__, __LINE__)
  103.  
  104. /**
  105.  * Test a post-condition for truth. If the expression is not true then
  106.  * trigger a program failure.
  107.  */
  108. #define NS_POSTCONDITION(expr,str) \
  109. if (!(expr))               \
  110.   nsDebug::PostCondition(str, #expr, __FILE__, __LINE__)
  111.  
  112. /**
  113.  * This macros triggers a program failure if executed. It indicates that
  114.  * an attempt was made to execute some unimplimented functionality.
  115.  */
  116. #define NS_NOTYETIMPLEMENTED(str) \
  117.   nsDebug::NotYetImplemented(str, __FILE__, __LINE__)
  118.  
  119. /**
  120.  * This macros triggers a program failure if executed. It indicates that
  121.  * an attempt was made to execute some unimplimented functionality.
  122.  */
  123. #define NS_NOTREACHED(str) \
  124.   nsDebug::NotReached(str, __FILE__, __LINE__)
  125.  
  126. /**
  127.  * Log an error message.
  128.  */
  129. #define NS_ERROR(str) \
  130.   nsDebug::Error(str, __FILE__, __LINE__)
  131.  
  132. /**
  133.  * Log a warning message.
  134.  */
  135. #define NS_WARNING(str) \
  136.   nsDebug::Warning(str, __FILE__, __LINE__)
  137.  
  138. /**
  139.  * Trigger an abort
  140.  */
  141. #define NS_ABORT() \
  142.   nsDebug::Abort(__FILE__, __LINE__)
  143.  
  144. #else /* NS_DEBUG */
  145.  
  146. #define NS_PRECONDITION(expr,str)  {}
  147. #define NS_ASSERTION(expr,str)     {}
  148. #define NS_POSTCONDITION(expr,str) {}
  149. #define NS_NOTYETIMPLEMENTED(str)  {}
  150. #define NS_NOTREACHED(str)         {}
  151. #define NS_ERROR(str)              {}
  152. #define NS_WARNING(str)            {}
  153. #define NS_ABORT()                 {}
  154.  
  155. #endif /* ! NS_DEBUG */
  156.  
  157. #endif /* nsDebug_h___ */
  158.