//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Reflection;
using System.Runtime.CompilerServices;

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

/// <summary>
/// Automatic code-block trace implementation (internal instance class)
/// </summary>
class CodeBlockTracer {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public CodeBlockTracer( bool debug, string blockName )
{
   _tracer = debug ? u.debug.Tracer : u.trace.Tracer;
   _tracer.Print( _category,
      "[[ In “{0}”:",
      blockName );
   _blockName = blockName;
}

public CodeBlockTracer( bool debug, string blockNameFmt, params object?[] args )
: this( debug, u.str.FMT( blockNameFmt, args ) )
{}

//--------------------------------------------------------------------------------------------------

public CodeBlockTracer( bool debug, MethodBase method, bool expanded=true )
: this( debug, expanded ?
   u.str.FMT( "[{0}] {1}", method.DeclaringType, method ) :
   u.code_fmt.MethodName( method ) )
{}

/// <exception cref="ArgumentException" />
public CodeBlockTracer( bool debug, Type objectType, [CallerMemberName] string memberName="" )
: this( debug, u.code_fmt.MemberName( objectType, memberName ) )
{}

//==================================================================================================

public void DoDispose() =>
   _tracer.Print( _category,
      "-- Out of “{0}”. ]]",
      _blockName );

//==================================================================================================

const u.TraceMessageCategory
   _category = u.TraceMessageCategory.Neutral;

Tracer _tracer;
string _blockName;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // CodeBlockTracer

} // user_rtx (.wasm)
