namespace IECore
{

/// A class useful for simple timing of operations.
/// This simply wraps boost::timer with a more flexible interface
/// that allows for starting and stopping while accumulating
/// elapsed time. Time values returned are in seconds.
/// \ingroup utilityGroup
class IECORE_API Timer
{

	public :

		/// Creates a new timer. If startAlready
		/// is true then calls start(), otherwise
		/// the timer is created stopped.
		Timer( bool start = true );

		/// Starts the timer. Throws an Exception if
		/// it's already running.
		void start();
		/// Stops the timer. Throws an Exception if
		/// it's not running. Returns the time elapsed
		/// since the last call to start().
		double stop();
		/// Returns true if the timer is running.
		bool running();
		/// Returns the time elapsed since the last call to
		/// start(), or 0 if timer is not running.
		double currentElapsed() const;
		/// Returns the total time this timer has been running
		/// for. This includes previous start()/stop() time periods
		/// and the current period if running() is true.
		double totalElapsed() const;

	private :

		bool m_running;
		double m_accumulated;
		boost::timer m_timer;

};

} // namespace IECore

#endif // IE_CORE_TIMER_H
