first commit
This commit is contained in:
81
include/platform/time/ntime.h
Normal file
81
include/platform/time/ntime.h
Normal file
@ -0,0 +1,81 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NTIME__
|
||||
#define __NTIME__
|
||||
|
||||
|
||||
#include "nstring/nstring.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
/*!
|
||||
@short Time class.
|
||||
@author Emmanuel Julien (ejulien@gsworks.fr)
|
||||
*/
|
||||
class Time
|
||||
{
|
||||
int sec, nsec; // second, nanosecond (10^9 -> 1 billionth second) (63+ years loop)
|
||||
|
||||
public:
|
||||
|
||||
static Time Inf;
|
||||
|
||||
void operator += (const Time &);
|
||||
void operator -= (const Time &);
|
||||
Time operator + (const Time &) const;
|
||||
Time operator - (const Time &) const;
|
||||
|
||||
template <class T> void operator *= (T k) { sec = int(T(sec) * k); nsec = int(T(nsec) * k); Normalize(); }
|
||||
template <class T> void operator /= (T k) { sec = int(T(sec) / k); nsec = int(T(nsec) / k); Normalize(); }
|
||||
template <class T> Time operator * (T k) const { return Time(int(T(sec) * k), int(T(nsec) * k)); }
|
||||
template <class T> Time operator / (T k) const { return Time(int(T(sec) / k), int(T(nsec) / k)); }
|
||||
|
||||
bool operator > (const Time &) const;
|
||||
bool operator < (const Time &) const;
|
||||
bool operator >= (const Time &) const;
|
||||
bool operator <= (const Time &) const;
|
||||
bool operator == (const Time &) const;
|
||||
bool operator != (const Time &) const;
|
||||
|
||||
Time Abs() const;
|
||||
|
||||
int getSec() const { return sec; }
|
||||
int getNanoSec() const { return nsec; }
|
||||
|
||||
float toDay() const;
|
||||
float toHour() const;
|
||||
float toMin() const;
|
||||
float toSec() const;
|
||||
float toMs() const;
|
||||
float toNs() const;
|
||||
|
||||
String toString() const;
|
||||
|
||||
void setSec(float);
|
||||
void setSec(int);
|
||||
void setMs(int);
|
||||
void setNs(int);
|
||||
|
||||
static Time fromSec(float);
|
||||
static Time fromSec(int);
|
||||
static Time fromMs(int);
|
||||
static Time fromNs(int);
|
||||
|
||||
void Normalize();
|
||||
Time Normalized() const;
|
||||
|
||||
Time(const int sec, const int nsec);
|
||||
|
||||
explicit Time(const int sec = 0);
|
||||
explicit Time(const float sec);
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NTIME__
|
||||
22
include/platform/time/ntime_range.h
Normal file
22
include/platform/time/ntime_range.h
Normal file
@ -0,0 +1,22 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __TIMERANGE__
|
||||
#define __TIMERANGE__
|
||||
|
||||
|
||||
#include "math/nrange.h"
|
||||
#include "time/ntime.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
typedef Range <Time> TimeRange;
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __TIMERANGE__
|
||||
Reference in New Issue
Block a user