/*
 * Copyright (C) 2003 Clemens Fuchslocher
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 *
 */

#include <time.h>
#include <math.h>

#include "Utility.h"


namespace nsUtility {

const double PI = 3.1415926535898;


// StopWatch
StopWatch::StopWatch(void)
{
	this->reset();
}


void StopWatch::start(void)
{
	this->startTicks = clock();
	this->started = true;
	this->stopped = false;
}


void StopWatch::stop(void)
{
	if (this->stopped == true)
	{
		return;
	}
	this->stopTicks = clock();
	this->stopped = true;
}


void StopWatch::reset(void)
{
	this->startTicks = 0;
	this->stopTicks = 0;
	this->started = false;
	this->stopped = false;
}


long StopWatch::getElapsedSeconds(void)
{
	return this->getElapsedMilliseconds() * 1000;
}


long StopWatch::getElapsedMilliseconds(void)
{
	if (this->started == false)
	{
		return 0;
	}

	if (this->stopped == true)
	{
		return (this->stopTicks - this->startTicks) / (CLOCKS_PER_SEC / 1000);
	}

	return (clock() - this->startTicks) / (CLOCKS_PER_SEC / 1000);
}

}

