// 
//  smartTrace.h
//  Scope tracing macros with automatic output indentation
//  
//  Created by Benoit Gagnon on 2007-03-30.
// 

#ifndef _TRACE_
#define _TRACE_

#ifdef DEBUG
#define TRACE_ENTER( msg ) ST::ScopeTrace __trace_enter__( msg );
#define TRACE( msg ) ST::ScopeTrace::trace( msg, 1 );
#else
#define TRACE_ENTER( msg );
#define TRACE( msg );
#endif

namespace ST {

using std::cout;
using std::endl;
using std::string;

//////////////////////////////////////////////////////////////////////////

struct ScopeTrace
{
    static int traceLevel;

    ScopeTrace( const string& msg )
    {
        ++traceLevel;
        trace( "+- " + msg );
    }
    
    ~ScopeTrace()
    {
        trace( "/" );
        --traceLevel;
    }

    static void trace( const string& msg, int offset = 0 )
    {
        int stop = traceLevel + offset;
        for( int i = 0; i < stop; ++i ) {
            cout << "|  ";
        }
        cout << msg << endl;
    }
};

int ScopeTrace::traceLevel = -1;

}

#endif /* _TRACE_ */

