home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / itrace.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  4.6 KB  |  166 lines

  1.  
  2. #ifndef _ITRACE_
  3. #define _ITRACE_
  4. /*******************************************************************************
  5. * FILE NAME: itrace.hpp                                                        *
  6. *                                                                              *
  7. * DESCRIPTION:                                                                 *
  8. *   Declaration of the classes:                                                *
  9. *     ITrace                                                                   *
  10. *                                                                              *
  11. * COPYRIGHT:                                                                   *
  12. *   IBM Open Class Library                                                     *
  13. *   (C) Copyright International Business Machines Corporation 1992, 1996       *
  14. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  15. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #include <ivbase.hpp>
  20.  
  21. #pragma pack(4)
  22.  
  23.  
  24.  
  25. class IString;
  26.  
  27. class ITrace : public IVBase {
  28. typedef IVBase
  29.   Inherited;
  30.  
  31. friend class ITraceSetup;
  32.  
  33. public:
  34. /*------------------------- Constructors -------------------------------------*/
  35.   ITrace                   ( const char* traceName =0,
  36.                              long        lineNumber=0 );
  37.  
  38.  ~ITrace                   ( );
  39.  
  40. /*-------------------------- Output/Location ---------------------------------*/
  41. static void
  42.   write                    ( const IString& text ),
  43.   write                    ( const char*    text );
  44.  
  45. enum Destination           {
  46.   queue,
  47.   standardError,
  48.   standardOutput,
  49.   file
  50.   };
  51.  
  52. static ITrace::Destination
  53.   traceDestination         ( );
  54.  
  55. static void
  56.   writeToQueue             ( ),
  57.   writeToStandardError     ( ),
  58.   writeToStandardOutput    ( ),
  59.   writeToFile              ( );
  60.  
  61. /*------------------------- Enable/Disable -----------------------------------*/
  62. static void
  63.   enableTrace              ( ),
  64.   disableTrace             ( );
  65.  
  66. static Boolean
  67.   isTraceEnabled           ( );
  68.  
  69. /*------------------------- Formatting ---------------------------------------*/
  70. static void
  71.   enableWriteLineNumber    ( ),
  72.   disableWriteLineNumber   ( ),
  73.   enableWritePrefix        ( ),
  74.   disableWritePrefix       ( );
  75.  
  76. static Boolean
  77.   isWriteLineNumberEnabled ( ),
  78.   isWritePrefixEnabled     ( );
  79.  
  80.  
  81. protected:
  82. /*------------------------- Thread ID ----------------------------------------*/
  83. static unsigned long
  84.   threadId                 ( );
  85.  
  86. /*------------------------- Protected Output Operations ----------------------*/
  87. static void
  88.   writeString              ( char*          text   ),
  89.   writeFormattedString     ( const IString& string,
  90.                              char*          marker );
  91.  
  92. private:
  93. /*------------------------- Private ------------------------------------------*/
  94.  
  95. enum State {
  96.   uninitialized=1,
  97.   on=2,
  98.   writeLineNumber=4,
  99.   writePrefix=8
  100.   };
  101. char
  102.  *pszClTraceName;
  103. static int
  104.   iClState;
  105. static ITrace::Destination
  106.   iClTraceLocation;
  107. static unsigned long
  108.   remainingStack ( );
  109.  
  110.  
  111.  
  112.  
  113. };
  114.  
  115.  
  116.  
  117.  
  118. #ifndef __FUNCTION__
  119.   #define __FUNCTION__ "f"
  120. #endif
  121.  
  122. #ifdef IC_TRACE_ALL
  123.    #define IMODTRACE_ALL(modname)  ITrace trc(modname, __LINE__ )
  124.    #define IFUNCTRACE_ALL()        ITrace trc(__FUNCTION__, __LINE__ )
  125.    #define ITRACE_ALL(p1)          ITrace::write(p1)
  126.    #ifndef IC_TRACE_DEVELOP
  127.      #define IC_TRACE_DEVELOP
  128.    #endif
  129. #else
  130.    #define IMODTRACE_ALL(modname)
  131.    #define IFUNCTRACE_ALL()
  132.    #define ITRACE_ALL(p1)
  133. #endif
  134.  
  135. #ifdef IC_TRACE_DEVELOP
  136.    #define IMODTRACE_DEVELOP(modname) ITrace trc(modname,  __LINE__ )
  137.    #define IFUNCTRACE_DEVELOP()       ITrace trc(__FUNCTION__, __LINE__ )
  138.    #define ITRACE_DEVELOP(p1)         ITrace::write(p1)
  139.    #ifndef IC_TRACE_RUNTIME
  140.      #define IC_TRACE_RUNTIME
  141.    #endif
  142. #else
  143.    #define IMODTRACE_DEVELOP(modname)
  144.    #define IFUNCTRACE_DEVELOP()
  145.    #define ITRACE_DEVELOP(p1)
  146. #endif
  147.  
  148. #ifdef IC_TRACE_RUNTIME
  149.    #define IMODTRACE_RUNTIME(modname)  ITrace trc(modname, __LINE__ )
  150.    #define IFUNCTRACE_RUNTIME()        ITrace trc(__FUNCTION__, __LINE__ )
  151.    #define ITRACE_RUNTIME(p1)          ITrace::write(p1)
  152. #else
  153.    #define IMODTRACE_RUNTIME(modname)
  154.    #define IFUNCTRACE_RUNTIME()
  155.    #define ITRACE_RUNTIME(p1)
  156. #endif
  157.  
  158. #pragma pack()
  159.  
  160.   #include <itrace.inl>
  161.  
  162. #endif /* _ITRACE_ */
  163.  
  164.  
  165.  
  166.