home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / LIBMAT.ZIP / MATFUNC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-16  |  4.0 KB  |  153 lines

  1. /*****************************************************/
  2. /*        matfunc.c source for matFunc class         */
  3. /*****************************************************/
  4.  
  5.  
  6. /**************************************************/
  7. /*            MatClass Source File                */
  8. /*       Copyright of C. R. Birchenhall           */
  9. /*       University of Manchester, UK.            */
  10. /*   MatClass is freeware. This file should be    */
  11. /* made freely available to users of any software */
  12. /* whose creation is wholly or partly dependent   */
  13. /*                on this file.                   */
  14. /**************************************************/
  15.  
  16. #include "matbox.hpp"
  17.  
  18. #ifndef NO_STATIC_DEC
  19. #ifdef __cplusplus
  20. INDEX matFunc::count ;
  21. INDEX matFunc::debug ;
  22. #endif
  23. #endif
  24.  
  25. outFile *matTraceFile = &out ;
  26.  
  27. static matList matFuncCalls ;
  28.  
  29. void matFuncInitial( void )
  30. {
  31.    matFunc::count = 0 ;
  32.    matFunc::debug = 0 ;
  33. } // matFuncInitial
  34.  
  35. void traceFile( outFile& newTrace )
  36. {
  37.    if ( newTrace.fileType() != OUTPUT )
  38.       matErrNumExit( "traceFile", BDARG ) ;
  39.    matTraceFile = &newTrace ;
  40.    return ;
  41. } // traceFile
  42.  
  43. matFunc::matFunc( char *func )
  44. {
  45.    static char *mName = "matFunc" ;
  46.    count++ ;
  47.    if ( debug >= 1024 ) {
  48.       matTraceFile->write( "#" ).put( mName, 14 ) ;
  49.       matTraceFile->write( " [" ).putIndex( count, 2 ) ;
  50.       matTraceFile->write( "]" ).newLine() ;
  51.    } // if
  52.    name = func ;
  53.    if ( matFuncCalls.store( this ) ) {
  54.       matFuncList() ;
  55.       matErrNumExit( mName, BDLST ) ;
  56.    } // if
  57. } // matFunc
  58.  
  59. matFunc::matFunc( const matFunc& f )
  60. {
  61.    static char *mName = "matFunc(&F)" ;
  62.    count++ ;
  63.    if ( debug >= 1024 ) {
  64.       matTraceFile->write( "#" ).put( mName, 14 ) ;
  65.       matTraceFile->write( " [" ).putIndex( count, 2 ) ;
  66.       matTraceFile->write( "]" ).newLine() ;
  67.    } // if
  68.    name = f.name ;
  69.    if ( matFuncCalls.store( this ) ) {
  70.       matFuncList() ;
  71.       matErrNumExit( mName, BDLST ) ;
  72.    } // if
  73. } // matFunc
  74.  
  75. matFunc& matFunc::operator = ( const matFunc& f )
  76. {
  77.    name = f.name ;
  78.    matErrNumExit( "matFunc =", NIMPL ) ;
  79.    return *this ;
  80. } // matFunc
  81.  
  82. matFunc::~matFunc( void )
  83. {
  84.    static char *mName = "~matFunc" ;
  85.    if ( debug >= 1024 ) {
  86.       matTraceFile->write( "#" ).put( "~matFunc", 14 ) ;
  87.       matTraceFile->write( " [" ).putIndex( count, 2 ) ;
  88.       matTraceFile->write( "]" ).newLine() ;
  89.    } // if
  90.    count-- ;
  91.    int err = matFuncCalls.remove( this ) ;
  92.    if ( err ) {
  93.       matFuncList() ;
  94.       if ( err == 1 )
  95.          matErrNumExit( mName, NULST ) ;
  96.       else
  97.          matErrNumExit( mName, BDLST ) ;
  98.    } // if
  99. } // ~matFunc
  100.  
  101. INDEX setMatDebug( INDEX dbg )
  102. {
  103.    int old = matFunc::debug ;
  104.    matFunc::debug = dbg ;
  105.    return old ;
  106. } // setMatDebug
  107.  
  108. void matFunc::info( outFile& f ) M_CONST
  109. {
  110.    f.write( "#" ) ;
  111.    f.put( name.array(), 14 ) ;
  112.    f.write( " [" ).putIndex( count, 2 ).write( "]" ) ;
  113. } // matFunc::info
  114.  
  115. int matFunc::trace( INDEX lineFeed ) M_CONST
  116. {
  117.    if ( count <= debug ) {
  118.       info( *matTraceFile ) ;
  119.       if ( lineFeed )
  120.          matTraceFile->newLine() ;
  121.       return 1 ;
  122.    } else
  123.       return 0 ;
  124. } // matFunc::trace
  125.  
  126. void matFuncList( void )
  127. {
  128.    matFunc* funcPtr ;
  129.    INDEX    n = matFunc::count ;
  130.  
  131.    matTraceFile->newLine().write( "Stack of Function Calls" ) ;
  132.    matTraceFile->newLine(2) ;
  133.    matFuncCalls.gotoHead() ;
  134.    if ( matFuncCalls.endOfList() ) {
  135.       matTraceFile->write( "Stack Empty" ).newLine() ;
  136.    } else while ( !matFuncCalls.endOfList() ) {
  137.       funcPtr = (matFunc *) matFuncCalls.examine() ;
  138.       matFuncCalls.gotoNext() ;
  139.       matTraceFile->write( "# " ) ;
  140.       matTraceFile->put( funcPtr->name.array(), 14 ) ;
  141.       matTraceFile->write( "[" ).putIndex( n--, 2 ).write( "]" ) ;
  142.       matTraceFile->newLine() ;
  143.    } // while
  144. } // matFuncList
  145.  
  146. void matObject::debugInfo( const matFunc& func ) M_CONST
  147. {
  148.    if ( func.trace() ) {
  149.       info( *matTraceFile ) ;
  150.       matTraceFile->flush() ;
  151.    } // if
  152. } // matFunc::debugInfo
  153.