testTrace.cpp

Description of class 'Trace'

Aim: implementation of basic methods to trace out messages with indentation levels.

Trace objects use a TraceWriter to switch between terminal and file outputs. Methods postfixed with "Debug" contain no code if the compilation flag DEBUG is not set.

For usage examples, see the testtrace.cpp file.

Todo:
Create a default constructor on TraceWriterTerm(std::cerr)
#include <cstdio>
#include <cmath>
#include <iostream>
#include <fstream>

#include "DGtal/base/Config.h"
#include "DGtal/base/Common.h"


using namespace DGtal;
using namespace std;


void testSimple()
{
    trace.info()<< "This is an Info trace"<<endl;
    trace.warning()<< "This is an warning trace"<<endl;
    trace.error()<< "This is an Error trace"<<endl;
    trace.emphase()<< "This is an Emphased trace"<<endl;
    cerr<<endl;
}

void testIndent()
{
    long tmp=0;

    trace.info()<< "This is an Info trace, level 0"<<endl;
    trace.beginBlock("FirstMethod");
    trace.info()<< "This is an Info trace, level 1"<<endl;
    trace.info()<< "This is an Info trace, level 1"<<endl;
    trace.beginBlock("SecondMethod");
    trace.warning()<< "This is an Warning trace, level 2"<<endl;
    trace.warning()<< "This is an Warning trace, level 2"<<endl;
    trace.info()<< "This is an Info trace, level 2"<<endl;
    trace.error()<< "This is an Error trace, level 2 (followed by a loop)"<<endl;

    for (unsigned int i=0 ; i< 4334450; i++)
        tmp = (long)cos((double)tmp+i);

    trace.endBlock();
    trace.info()<< "This is an Info trace, level 1 (followed by another loop)"<<endl;

    for (unsigned int i=0 ; i< 4334450; i++)
        tmp = (long)cos((double)tmp+i);

    trace.endBlock();
    trace.info()<< "This is an Info trace, level 0"<<endl<<endl;
}

void testFileStream()
{
    trace.beginBlock("testFileStream");
    trace.info() << "Checking the filestream output.. Please check the 'example.txt' file"<<endl;

    ofstream myfile;
    myfile.open ("example.txt");

    TraceWriterFile traceWriterFile(myfile);
    Trace t2(traceWriterFile);

    t2.info()<< "This is an Info trace"<<endl;
    t2.warning()<< "This is an warning trace"<<endl;

    t2.error()<< "This is an Error trace"<<endl;
    t2.emphase()<< "This is an Emphased trace"<<endl;

    t2.beginBlock("FirstMethod");
    t2.info()<< "This is an Info trace, level 1"<<endl;
    t2.info()<< "This is an Info trace, level 1"<<endl;
    t2.endBlock();

    myfile.close();

    trace.endBlock();
}


int main()
{
    testSimple();
    testIndent();
    testFileStream();
    return 0;
}
Generated on Wed Sep 29 15:53:45 2010 for DGtal by  doxygen 1.6.3