class EE::System::Time¶
Overview¶
Represents a time value
EE::System::Time encapsulates a time value in a flexible way. More…
#include <time.hpp> class Time { public: // fields static const Time Zero; // methods static bool isValid(const std::string& str); static Time fromString(const std::string& str); double asSeconds() const; double asMilliseconds() const; Int64 asMicroseconds() const; std::string toString() const; EE_API Time Minutes(double amount); EE_API Time Seconds(double amount); EE_API Time Milliseconds(double amount); EE_API Time Microseconds(Int64 amount); EE_API bool operator==(Time left, Time right); EE_API bool operator!=(Time left, Time right); EE_API bool operator<(Time left, Time right); EE_API bool operator>(Time left, Time right); EE_API bool operator<=(Time left, Time right); EE_API bool operator>=(Time left, Time right); EE_API Time operator-(Time right); EE_API Time operator+(Time left, Time right); EE_API Time& operator+=(Time& left, Time right); EE_API Time operator-(Time left, Time right); EE_API Time& operator-=(Time& left, Time right); EE_API Time operator*(Time left, Time right); EE_API Time operator*(Time left, double right); EE_API Time operator*(double left, Time right); EE_API Time operator*(Int64 left, Time right); EE_API Time operator*(Time left, Int64 right); EE_API Time& operator*=(Time& left, double right); EE_API Time& operator*=(Time& left, Int64 right); EE_API Time& operator*=(Time& left, Time right); EE_API Time operator/(Time left, Time right); EE_API Time operator/(Time left, double right); EE_API Time operator/(Time left, Int64 right); EE_API Time& operator/=(Time& left, Int64 right); EE_API Time& operator/=(Time& left, Time right); EE_API Time operator%(Time left, Time right); EE_API Time& operator%=(Time& left, Time right); };
Detailed Documentation¶
Represents a time value
EE::System::Time encapsulates a time value in a flexible way. It allows to define a time value either as a number of seconds, milliseconds or microseconds. It also works the other way round: you can read a time value as either a number of seconds, milliseconds or microseconds.
By using such a flexible interface, the API doesn’t impose any fixed type or resolution for time values, and let the user choose its own favorite representation.
Time values support the usual mathematical operations: you can add or subtract two times, multiply or divide a time by a number, compare two times, etc.
Since they represent a time span and not an absolute time value, times can also be negative.
Usage example:
Time t1 = Seconds(0.1f); double milli = t1.asMilliseconds(); // 100 Time t2 = Milliseconds(30); Int64 micro = t2.asMicroseconds(); // 30000 Time t3 = Microseconds(-800000); double sec = t3.asSeconds(); // -0.8
void update(Time elapsed) { position += speed * elapsed; } update(Milliseconds(100));
See also:
Fields¶
static const Time Zero
Predefined “zero” time value.
Methods¶
double asSeconds() const
Return the time value as a number of seconds.
Returns:
Time in seconds
See also:
AsMilliseconds, AsMicroseconds
double asMilliseconds() const
Return the time value as a number of milliseconds.
Returns:
Time in milliseconds
See also:
AsSeconds, AsMicroseconds
Int64 asMicroseconds() const
Return the time value as a number of microseconds.
Returns:
Time in microseconds
See also:
std::string toString() const
Converts the time into a human readable string.
EE_API Time Minutes(double amount)
Construct a time value from a number of minutes.
Parameters:
amount |
Number of minutes |
Returns:
Time value constructed from the amount of seconds
See also:
Milliseconds, Microseconds
EE_API Time Seconds(double amount)
Construct a time value from a number of seconds.
Parameters:
amount |
Number of seconds |
Returns:
Time value constructed from the amount of seconds
See also:
Milliseconds, Microseconds
EE_API Time Milliseconds(double amount)
Construct a time value from a number of milliseconds.
Parameters:
amount |
Number of milliseconds |
Returns:
Time value constructed from the amount of milliseconds
See also:
Seconds, Microseconds
EE_API Time Microseconds(Int64 amount)
Construct a time value from a number of microseconds.
Parameters:
amount |
Number of microseconds |
Returns:
Time value constructed from the amount of microseconds
See also:
Seconds, Milliseconds
EE_API bool operator==(Time left, Time right)
Overload of == operator to compare two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
True if both time values are equal
EE_API bool operator!=(Time left, Time right)
Overload of != operator to compare two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
True if both time values are different
EE_API bool operator<(Time left, Time right)
Overload of < operator to compare two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
True if left is lesser than right
EE_API bool operator>(Time left, Time right)
Overload of > operator to compare two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
True if left is greater than right
EE_API bool operator<=(Time left, Time right)
Overload of <= operator to compare two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
True if left is lesser or equal than right
EE_API bool operator>=(Time left, Time right)
Overload of >= operator to compare two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
True if left is greater or equal than right
EE_API Time operator-(Time right)
Overload of unary - operator to negate a time value.
Parameters:
right |
Right operand (a time) |
Returns:
Opposite of the time value
EE_API Time operator+(Time left, Time right)
Overload of binary + operator to add two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
Sum of the two times values
EE_API Time& operator+=(Time& left, Time right)
Overload of binary += operator to add/assign two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
Sum of the two times values
EE_API Time operator-(Time left, Time right)
Overload of binary - operator to subtract two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
Difference of the two times values
EE_API Time& operator-=(Time& left, Time right)
Overload of binary -= operator to subtract/assign two time values.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
Difference of the two times values
EE_API Time operator*(Time left, Time right)
Overload of binary * operator to scale a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a number) |
Returns:
left multiplied by right
EE_API Time operator*(Time left, double right)
Overload of binary * operator to scale a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a number) |
Returns:
left multiplied by right
EE_API Time operator*(double left, Time right)
Overload of binary * operator to scale a time value.
Parameters:
left |
Left operand (a number) |
right |
Right operand (a time) |
Returns:
left multiplied by right
EE_API Time operator*(Int64 left, Time right)
Overload of binary * operator to scale a time value.
Parameters:
left |
Left operand (a number) |
right |
Right operand (a time) |
Returns:
left multiplied by right
EE_API Time operator*(Time left, Int64 right)
Overload of binary * operator to scale a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a number) |
Returns:
left multiplied by right
EE_API Time& operator*=(Time& left, double right)
Overload of binary *= operator to scale/assign a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a number) |
Returns:
left multiplied by right
EE_API Time& operator*=(Time& left, Int64 right)
Overload of binary *= operator to scale/assign a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a number) |
Returns:
left multiplied by right
EE_API Time& operator*=(Time& left, Time right)
Overload of binary *= operator to scale/assign a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
left multiplied by right
EE_API Time operator/(Time left, Time right)
Overload of binary / operator to scale a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
left divided by right
EE_API Time operator/(Time left, double right)
Overload of binary / operator to scale a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a number) |
Returns:
left divided by right
EE_API Time operator/(Time left, Int64 right)
Overload of binary / operator to scale a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a number) |
Returns:
left divided by right
EE_API Time& operator/=(Time& left, Int64 right)
Overload of binary /= operator to scale/assign a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a number) |
Returns:
left divided by right
EE_API Time& operator/=(Time& left, Time right)
Overload of binary /= operator to scale/assign a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
left divided by right
EE_API Time operator%(Time left, Time right)
Overload of binary % operator to compute remainder of a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
left modulo right
EE_API Time& operator%=(Time& left, Time right)
Overload of binary %= operator to compute/assign remainder of a time value.
Parameters:
left |
Left operand (a time) |
right |
Right operand (a time) |
Returns:
left modulo right