// cyCodeBase by Cem Yuksel
// [www.cemyuksel.com]
//-------------------------------------------------------------------------------

#ifndef _TIMER_LIST_H_INCLUDED_
#define _TIMER_LIST_H_INCLUDED_

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

#include "cyTimer.h"
#include <stdio.h>
#include <float.h>

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

// ID of each timer and the number of timers
enum TimerType
{
	TT_PART1=0,
		TT_PART1_SUB1,
		TT_PART1_SUB2,
		TT_PART1_SUB3,

	TT_PART2,
		TT_PART2_SUB1,
		TT_PART2_SUB2,

	TIMER_TYPE_COUNT	// this keeps the number of timers (DO NOT REMOVE)
};

// The name string of each timer
static char TimerTypeNames[][255] = {
	"Part 1                ",
	"  Part 1 algorithm 1  ",
	"  Part 1 algorithm 2  ",
	"  Part 1 algorithm 3  ",

	"Part 2                ",
	"  Part 2 algorithm 1  ",
	"  Part 2 algorithm 2  ",
};

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

class TimerList
{
public:
	// Clears the data of all timers
	void ClearAll() { Clear( 0, TIMER_TYPE_COUNT ); }

	// Clears the data of the timers between from and to
	void Clear( int from, int to ) { for ( int i=from; i<to; i++ ) timers[i].Clear(); }

	// This is how you access each timer
	cyTimerStats& GetTimer( int type ) { return timers[ type ]; }
	cyTimerStats& operator [] ( int type ) { return GetTimer( type ); }

	// Prints the results of all timers
	void PrintResults( int from=0, int to=TIMER_TYPE_COUNT, FILE *fp=stdout ) {
		for ( int i=from; i<to; i++ ) PrintResult( i, fp );
	}

	// Prints the results of one timer
	void PrintResult( int type, FILE *fp=stdout ) {
		double a = timers[ type ].GetAverage();
		if ( _finite(a) ) {
			fprintf(fp, "%s :  avrg=%8.3f\tmin=%8.3f\tmax=%8.3f\n", TimerTypeNames[ type ], a, timers[type].GetMin(), timers[type].GetMax() );
		} else {
			fprintf(fp, "%s :  avrg=   -----\tmin=   -----\tmax=   -----\n", TimerTypeNames[ type ], a, timers[type].GetMin(), timers[type].GetMax() );
		}
	}
	
protected:
	cyTimerStats timers[ TIMER_TYPE_COUNT ];
};

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

extern TimerList TIMER;

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

#endif
