// <clock> -*- C++ -*-
/*! ========================================================================
** Extended Template and Library
** Clock Abstraction
** $Id$
**
** Copyright (c) 2002 Robert B. Quattlebaum Jr.
**
** This package 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 package 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.
**
** === N O T E S ===========================================================
**
** ========================================================================= */

/* === S T A R T =========================================================== */

#ifndef __ETL__CLOCK__
#define __ETL__CLOCK__

/* === H E A D E R S ======================================================= */

#include <chrono>

namespace etl {

	class clock {
		std::chrono::time_point<std::chrono::steady_clock> base_time_;
	public:

		clock() {
			reset();
		}

		void reset() {
			base_time_ = std::chrono::steady_clock::now();
		}
		//{ get_current_time(base_time); }

		float operator()() const {
			return std::chrono::duration<float>(std::chrono::steady_clock::now() - base_time_).count();
		}
		//{ return this->timestamp_to_seconds(get_current_time()-base_time); }

		float pop_time() {
			// Grab the old base time
			std::chrono::time_point<std::chrono::steady_clock> old_time = base_time_;

			// Put the current time into base_time
			base_time_ = std::chrono::steady_clock::now();

			return std::chrono::duration<float>(base_time_ - old_time).count();
		}
	};
}

//using etl::clock;

/* === E N D =============================================================== */

#endif
