⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmtrace.cpp

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 CPP
字号:
/*****************************************************************************/
/*                             SOURCE FILE                                   */
/*****************************************************************************/
/*
       $Archive: $

      $Revision: $
          $Date: $
        $Author: $

   Description: class that wraps the TRACE functionality

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/


#include "../../../stdafx.h"
#include "../APIClasses/VMString.h"
#include "VMTrace.h"
#include "VMWatcherOutput.h"

int  VMTrace::m_iIndent  = 0;
bool VMTrace::m_bTracing = true;


/*****************************************************************************/
/*
     FUNCTION NAME:	VMTrace

       DESCRIPTION:	ctor. sets up class locals

             INPUT: function - the name of the function being traced
           RETURNS:	void
*/
VMTrace::VMTrace( const VMString& function )
{
  m_oFunctionName = function;

  if ( true == m_bTracing )
  {
    VMString oOutput;
    oOutput.Format( "Entering: %s \r\n", m_oFunctionName );
    Indent();
    DEBUGOUT( oOutput );
  }
  m_iIndent += 2;
}
/*	end of function "VMTrace" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	~VMTrace

       DESCRIPTION:	dtor. changes the static value for m_iIndent and puts out
                    the last gasp for this instance of the class

             INPUT: void
           RETURNS:	void
*/
VMTrace::~VMTrace()
{
  m_iIndent -= 2;

  if ( true == m_bTracing )
  {
    VMString oOutput;
    oOutput.Format( "Leaving: %s \r\n", m_oFunctionName );
    Indent();
    DEBUGOUT( oOutput );
  }
  m_oFunctionName.Empty();
}
/*	end of function "~VMTrace" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Indent

       DESCRIPTION:	provides for spaces-padded output

             INPUT: void
           RETURNS:	void
*/
void VMTrace::Indent( void ) const
{
  if ( true == m_bTracing )
  {
    if ( 0 < m_iIndent )
    {
      VMString spaces( _T("") );

      int index = 0;

      while( index < m_iIndent )
      {
         spaces += _T(" ");
         index++;
      }
      DEBUGOUT( spaces );
    }
  }
}
/*	end of function "Indent" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Output

       DESCRIPTION:	provides TRACE output for VMStrings

             INPUT: roMessage - the string to output
           RETURNS:	void
*/
void VMTrace::Output( VMString& roMessage ) const
{
  if ( true == m_bTracing )
  {
    Indent();

    VMString oOutput( m_oFunctionName );

    oOutput += " : ";
    oOutput += roMessage;

    if ( oOutput.GetLength() > 510 )
    {
      oOutput = oOutput.Left( 510 );
    }

    oOutput += "\n";

    DEBUGOUT( oOutput );
  }
}
/*	end of function "Output" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Output

       DESCRIPTION:	provides output for a string and an integer

             INPUT: roMessage - the text component
                    integer - the numeric component
           RETURNS:	void
*/
void VMTrace::Output( VMString& roMessage, const int integer ) const
{
  char achtemp[ 11 ];

  ::ZeroMemory( achtemp, sizeof( achtemp ) );
  ::itoa( integer, achtemp, 10 );
  roMessage.Append( achtemp );
  Output( roMessage );
}
/*	end of function "Output" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Output

       DESCRIPTION: provides output for a string and an unsigned integer.
                    calls on subordinates to do the real work	

             INPUT: roMessage - the string component
                    integer - the numeric component
           RETURNS:	void
*/
void VMTrace::Output( VMString& roMessage, const UINT integer ) const
{
  Output( roMessage, (ULONG) integer );
}
/*	end of function "Output" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Output

       DESCRIPTION:	provides output for a string and a long. calls on subord-
                    inates to the real work

             INPUT: roMessage - the string component
                     a_long - the numerice component
           RETURNS:	void
*/
void VMTrace::Output( VMString& roMessage, const long a_long ) const
{
  char achtemp[ 11 ];

  ::ZeroMemory( achtemp, sizeof( achtemp ) );
  ::ltoa( a_long, achtemp, 10 );

  roMessage.Append( achtemp );
  Output( roMessage );
}
/*	end of function "Output" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Output

       DESCRIPTION:	provides output for a string and an unsigned long. calls
                    on subordinates to the work

             INPUT: roMessage - the text component
                     a_long - the numerice component
           RETURNS:	void
*/
void VMTrace::Output( VMString& roMessage, const ULONG a_long ) const
{
  char achtemp[ 11 ];

  ::ZeroMemory( achtemp, sizeof( achtemp ) );
  ::ultoa( a_long, achtemp, 10 );

  roMessage.Append( achtemp );
  Output( roMessage );
}
/*	end of function "Output" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Output

       DESCRIPTION:	provides output for a string and a double

             INPUT: roMessage - the string component
                    a_double - the numeric component
           RETURNS:	void
*/
void VMTrace::Output( VMString& roMessage, const double a_double ) const
{
  int decimal = 0;
  int sign    = 0;

  char *pstring = (char *) NULL;

  pstring = ::_fcvt( a_double, 7, &decimal, &sign );

  VMString oString( _T("") );

  if ( 0 != sign )
  {
    oString = "-";
  }

  if ( decimal < 1 )
  {
    oString += ".";

    int index = 0;
    while( index > decimal )
    {
      oString += "0";
      index--;
    }
    oString += pstring;
  }
  else 
  if ( decimal >= (int) ::strlen( pstring ) )
  {
    oString += pstring;
    oString += ".";
  }
  else
  {
    int index = 0;

    while( index < decimal )
    {
      oString += pstring[ index ];
      index++;
    }

    oString += ".";

    index = decimal;

    while( index < (int) ::strlen( pstring ) )
    {
      oString += pstring[ index ];
      index++;
    }
  }
  roMessage.Append( oString );
  Output( roMessage );
}
/*	end of function "Output" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Output

       DESCRIPTION:	provides output for two strings

             INPUT: roMessage - the first string component
                    string  - the second string component
           RETURNS:	
*/
void VMTrace::Output( VMString& roMessage, const VMString& roString ) const
{
  roMessage.Append( roString );
  Output( roMessage );
}
/*	end of function "Output" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	Output

       DESCRIPTION:	provides output for a string and a pointer

             INPUT: roMessage - the string component
                    pointer - the pointer to display
           RETURNS:	
*/
void VMTrace::Output( VMString& roMessage, const VOID* pointer ) const
{
  VMString oString;
  oString.Format( "%p", pointer );
  roMessage.Append( oString );
  Output( roMessage );
}
/*	end of function "Output" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	OutputBinary

       DESCRIPTION:	provides output for a string and an unsigned long

             INPUT: roMessage - the string component
                     a_long - the numeric component
           RETURNS:	void
*/
void VMTrace::OutputBinary( VMString& roMessage, const ULONG a_long ) const
{
  int index = 31;

  VMString oBitString( _T("") );

  while( index >= 0 )
  {
    if ( BIT_TEST( a_long, index ) == 1 )
    {
      oBitString += "1";
    }
    else
    {
      oBitString += "0";
    }

    if ( index == 24 || index == 16 || index ==  8 )
    {
      oBitString += " ";
    }
    index--;
  }
  roMessage.Append( oBitString );
  Output( roMessage );
}
/*	end of function "OutputBinary" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	TraceOff

       DESCRIPTION:	turns tracing off

             INPUT: void
           RETURNS:	void
*/
void VMTrace::TraceOff( void )
{
   m_bTracing = false;
}
/*	end of function "TraceOff" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	TraceOn

       DESCRIPTION:	turns tracing on

             INPUT: void
           RETURNS:	void
*/
void VMTrace::TraceOn( void )
{
   m_bTracing = true;
}
/*	end of function "TraceOn" */
/*****************************************************************************/





/*****************************************************************************/
/* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -