/* Metrowerks Standard Library
 * Copyright  1995-2004 Metrowerks Corporation.  All rights reserved.
 *
 * $Date: 2004/06/15 14:16:41 $
 * $Revision: 1.7.2.1 $
 */

// msl_time

/*  msl_time synopsis

namespace Metrowerks
{

class universal_time
{
public:
	universal_time();  // current time
	universal_time& operator += (const elapsed_time& dt);
	universal_time& operator -= (const elapsed_time& dt);

	std::time_t  sec_;
	std::int32_t nsec_;
};

class elapsed_time
{
public:
	explicit elapsed_time(std::time_t sec = 0, std::int32_t nsec = 0);

	elapsed_time& operator += (const elapsed_time& dt);
	elapsed_time& operator -= (const elapsed_time& dt);
	elapsed_time operator - () const;
	elapsed_time operator + () const;

	std::time_t  sec_;
	std::int32_t nsec_;
};

elapsed_time   operator-(const universal_time& t1, const universal_time& t2);
universal_time operator-(const universal_time& t1, const elapsed_time& dt);
elapsed_time   operator-(const elapsed_time& dt1, const elapsed_time& dt2);

universal_time operator+(const universal_time& t1, const elapsed_time& dt);
universal_time operator+(const elapsed_time& dt, const universal_time& t1);
elapsed_time   operator+(const elapsed_time& dt1, const elapsed_time& dt2);

bool operator == (const universal_time& x, const universal_time& y);
bool operator != (const universal_time& x, const universal_time& y);
bool operator <  (const universal_time& x, const universal_time& y);
bool operator <= (const universal_time& x, const universal_time& y);
bool operator >  (const universal_time& x, const universal_time& y);
bool operator >= (const universal_time& x, const universal_time& y);

bool operator == (const elapsed_time& x, const elapsed_time& y);
bool operator != (const elapsed_time& x, const elapsed_time& y);
bool operator <  (const elapsed_time& x, const elapsed_time& y);
bool operator <= (const elapsed_time& x, const elapsed_time& y);
bool operator >  (const elapsed_time& x, const elapsed_time& y);
bool operator >= (const elapsed_time& x, const elapsed_time& y);

}  // Metrowerks

*/

#ifndef _MSL_TIME
#define _MSL_TIME

#include <mslconfig>

#ifndef _MSL_NO_TIME_SUPPORT

#include <ctime>
#include <cstdint>

#ifndef RC_INVOKED

#ifdef __MWERKS__
#pragma options align=native
#endif

#ifdef _MSL_FORCE_ENUMS_ALWAYS_INT
	#if _MSL_FORCE_ENUMS_ALWAYS_INT
		#pragma enumsalwaysint on
	#else
		#pragma enumsalwaysint off
	#endif
#endif  // _MSL_FORCE_ENUMS_ALWAYS_INT

#ifdef _MSL_FORCE_ENABLE_BOOL_SUPPORT
	#if _MSL_FORCE_ENABLE_BOOL_SUPPORT
		#pragma bool on
	#else
		#pragma bool off
	#endif
#endif  // _MSL_FORCE_ENABLE_BOOL_SUPPORT

#ifndef _MSL_NO_CPP_NAMESPACE
	namespace Metrowerks {
#else
	#ifndef Metrowerks
		#define Metrowerks
	#endif
#endif  // _MSL_NO_CPP_NAMESPACE

class elapsed_time;

class _MSL_IMP_EXP_CPP universal_time
{
public:
	universal_time();  // current time
	universal_time& operator += (const elapsed_time& dt);
	universal_time& operator -= (const elapsed_time& dt);

	_CSTD::time_t  sec_;
	_CSTD::int32_t nsec_;
};

class _MSL_IMP_EXP_CPP elapsed_time
{
public:
	explicit elapsed_time(_CSTD::time_t sec = 0, _CSTD::int32_t nsec = 0)
		: sec_(sec), nsec_(nsec) {}
	elapsed_time& operator += (const elapsed_time& dt);
	elapsed_time& operator -= (const elapsed_time& dt);
	elapsed_time operator - () const {return elapsed_time(-sec_, -nsec_);}
	elapsed_time operator + () const {return *this;}

	_CSTD::time_t  sec_;
	_CSTD::int32_t nsec_;
};

inline
elapsed_time
operator-(const universal_time& t1, const universal_time& t2)
{
	elapsed_time t(t1.sec_, t1.nsec_);
	t -= (const elapsed_time&)t2;
	return t;
}

inline
universal_time
operator-(const universal_time& t1, const elapsed_time& dt)
{
	universal_time t(t1);
	t -= dt;
	return t;

}

inline
elapsed_time
operator-(const elapsed_time& dt1, const elapsed_time& dt2)
{
	elapsed_time t(dt1);
	t -= dt2;
	return t;
}

inline
universal_time
operator+(const universal_time& t1, const elapsed_time& dt)
{
	universal_time t(t1);
	t += dt;
	return t;
}

inline
universal_time
operator+(const elapsed_time& dt, const universal_time& t1)
{
	universal_time t(t1);
	t += dt;
	return t;
}

inline
elapsed_time
operator+(const elapsed_time& dt1, const elapsed_time& dt2)
{
	elapsed_time t(dt1);
	t += dt2;
	return t;
}

inline
bool
operator == (const universal_time& x, const universal_time& y)
{
	return x.sec_ == y.sec_ && x.nsec_ == y.nsec_;
}

inline
bool
operator != (const universal_time& x, const universal_time& y)
{
	return !(x == y);
}

inline
bool
operator <  (const universal_time& x, const universal_time& y)
{
	return x.sec_ < y.sec_ || (x.sec_ == y.sec_ && x.nsec_ < y.nsec_);
}

inline
bool
operator <= (const universal_time& x, const universal_time& y)
{
	return !(y < x);
}

inline
bool
operator >  (const universal_time& x, const universal_time& y)
{
	return y < x;
}

inline
bool
operator >= (const universal_time& x, const universal_time& y)
{
	return !(x < y);
}

inline
bool
operator == (const elapsed_time& x, const elapsed_time& y)
{
	return x.sec_ == y.sec_ && x.nsec_ == y.nsec_;
}

inline
bool
operator != (const elapsed_time& x, const elapsed_time& y)
{
	return !(x == y);
}

inline
bool
operator <  (const elapsed_time& x, const elapsed_time& y)
{
	return x.sec_ < y.sec_ || (x.sec_ == y.sec_ && x.nsec_ < y.nsec_);
}

inline
bool
operator <= (const elapsed_time& x, const elapsed_time& y)
{
	return !(y < x);
}

inline
bool
operator >  (const elapsed_time& x, const elapsed_time& y)
{
	return y < x;
}

inline
bool
operator >= (const elapsed_time& x, const elapsed_time& y)
{
	return !(x < y);
}

#ifndef _MSL_NO_CPP_NAMESPACE
	} // namespace Metrowerks
#endif

#ifdef _MSL_FORCE_ENUMS_ALWAYS_INT
	#pragma enumsalwaysint reset
#endif

#ifdef _MSL_FORCE_ENABLE_BOOL_SUPPORT
	#pragma bool reset
#endif

#ifdef __MWERKS__
#pragma options align=reset
#endif

#endif // RC_INVOKED

#endif  // _MSL_NO_TIME_SUPPORT

#endif  // _MSL_TIME

// hh 030616 Created
// hh 030711 Ported to gcc
