TimeValue Class Reference

#include <timevalue.h>

Inheritance diagram for TimeValue:

Detailed Description

The TimeValue class encapsulates a timer value.

Classes

class  CurrentTime
 

Public Member Functions

 TimeValue ()
 
 TimeValue (CurrentTime)
 
 TimeValue (ENUM_DONT_INITIALIZE)
 
 TimeValue (const TimeValue &src)
 
 TimeValue (Int frame, Float64 frameRate)
 
template<typename TIMESTAMP >
 TimeValue (TimeValue stampToTime, TIMESTAMP stamp)
 
TimeValueoperator= (const TimeValue &src)
 
 MAXON_OPERATOR_EQUALITY_HASHCODE (TimeValue, _value)
 
Bool operator< (const TimeValue &b) const
 
 MAXON_OPERATOR_INEQUALITY (TimeValue)
 
TimeValue operator+ (const TimeValue &b) const
 
TimeValueoperator+= (const TimeValue &b)
 
TimeValue operator- (const TimeValue &b) const
 
const TimeValueoperator-= (const TimeValue &b)
 
TimeValueoperator*= (const Float64 b)
 
Float64 GetDays () const
 
void SetDays (Float64 days)
 
Float64 GetHours () const
 
void SetHours (Float64 hours)
 
Float64 GetMinutes () const
 
void SetMinutes (Float64 minutes)
 
Float64 GetSeconds () const
 
void SetSeconds (Float64 seconds)
 
Float64 GetMilliseconds () const
 
void SetMilliseconds (Float64 milliseconds)
 
Float64 GetMicroseconds () const
 
void SetMicroseconds (Float64 microseconds)
 
Float64 GetNanoseconds () const
 
void SetNanoseconds (Float64 nanoseconds)
 
Tuple< Int, Int, IntGetHourMinuteSecond () const
 
const TimeValueStop ()
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 
Int GetFrame (Float64 frameRate) const
 
void Quantize (Float64 frameRate)
 
String TimeToString (TIMEFORMAT timeFormat=TIMEFORMAT::SECONDS, Float64 frameRate=1) const
 
Result< void > TimeFromString (const String &str, TIMEFORMAT timeFormat, Float64 frameRate)
 

Static Public Member Functions

static TimeValue GetTime ()
 
static Result< void > DescribeIO (const DataSerializeInterface &stream)
 

Static Public Attributes

static const CurrentTime NOW
 

Protected Member Functions

constexpr TimeValue (Float64 seconds)
 

Private Attributes

Float64 _value
 

Friends

TimeValue operator* (const TimeValue &a, const Float64 &b)
 
Float64 operator/ (const TimeValue &a, const TimeValue &b)
 
TimeValue operator/ (const TimeValue &a, const Float64 b)
 

Constructor & Destructor Documentation

◆ TimeValue() [1/7]

TimeValue ( )

Default constructs with 0.

◆ TimeValue() [2/7]

TimeValue ( CurrentTime  )
explicit

Initializes with the current time stamp.

◆ TimeValue() [3/7]

Don't initializes class (for better speed)

◆ TimeValue() [4/7]

TimeValue ( const TimeValue src)

Copy constructs time.

◆ TimeValue() [5/7]

TimeValue ( Int  frame,
Float64  frameRate 
)
explicit

Constructs a time from an integer frame number and a frame rate.

Note
The frame rate doesn't need to be an integer and can e.g. be FRAMERATE_NTSC (29.97)

◆ TimeValue() [6/7]

TimeValue ( TimeValue  stampToTime,
TIMESTAMP  stamp 
)
explicit

Construct a time from an inverse timer frequency (stampToTime) and an arbitrary time stamp value.

◆ TimeValue() [7/7]

constexpr TimeValue ( Float64  seconds)
explicitconstexprprotected

Member Function Documentation

◆ operator=()

TimeValue& operator= ( const TimeValue src)

Copy Assignment operator.

◆ MAXON_OPERATOR_EQUALITY_HASHCODE()

MAXON_OPERATOR_EQUALITY_HASHCODE ( TimeValue  ,
_value   
)

◆ operator<()

Bool operator< ( const TimeValue b) const

Compares two TimeValues.

◆ MAXON_OPERATOR_INEQUALITY()

MAXON_OPERATOR_INEQUALITY ( TimeValue  )

◆ operator+()

TimeValue operator+ ( const TimeValue b) const

Adds two TimeValues.

◆ operator+=()

TimeValue& operator+= ( const TimeValue b)

Adds to this TimeValue.

◆ operator-()

TimeValue operator- ( const TimeValue b) const

Subtracts two TimeValues.

◆ operator-=()

const TimeValue& operator-= ( const TimeValue b)

@briefSubtracts from this TimeValue.

◆ operator*=()

TimeValue& operator*= ( const Float64  b)

Multiplies this TimeValue with a factor.

Parameters
[in]bThe factor.
Returns
The result of this * b.

◆ GetDays()

Float64 GetDays ( ) const

Get the TimerValue

Returns
Time value in days.

◆ SetDays()

void SetDays ( Float64  days)

Set the TimeValue

Parameters
[in]daysTime value in days.

◆ GetHours()

Float64 GetHours ( ) const

Gets the value in hours.

Returns
Time value in hours.

◆ SetHours()

void SetHours ( Float64  hours)

Sets the TimeValue in hours.

Parameters
[in]hoursTime value in hours.

◆ GetMinutes()

Float64 GetMinutes ( ) const

Gets the TimeValue in minutes.

Returns
Time value in minutes.

◆ SetMinutes()

void SetMinutes ( Float64  minutes)

Sets the TimeValue in minutes.

Parameters
[in]minutesTime value in minutes.

◆ GetSeconds()

Float64 GetSeconds ( ) const

Gets the TimeValue in seconds.

Returns
Time value in seconds.

◆ SetSeconds()

void SetSeconds ( Float64  seconds)

Sets the TimeValue in seconds.

Parameters
[in]secondsTime value in seconds.

◆ GetMilliseconds()

Float64 GetMilliseconds ( ) const

Gets the TimeValue in milliseconds.

Returns
Time value in milliseconds.

◆ SetMilliseconds()

void SetMilliseconds ( Float64  milliseconds)

Sets the TimeValue in milliseconds.

Parameters
[in]millisecondsTime value in milliseconds.

◆ GetMicroseconds()

Float64 GetMicroseconds ( ) const

Gets the TimeValue in microseconds.

Returns
Time value in microseconds.

◆ SetMicroseconds()

void SetMicroseconds ( Float64  microseconds)

Sets the TimeValue in microseconds.

Parameters
[in]microsecondsTime value in microseconds.

◆ GetNanoseconds()

Float64 GetNanoseconds ( ) const

Gets the TimeValue in nanoseconds.

Returns
Time value in nanoseconds.

◆ SetNanoseconds()

void SetNanoseconds ( Float64  nanoseconds)

Sets the TimeValue in nanoseconds.

Parameters
[in]nanosecondsTime value in nanoseconds.

◆ GetHourMinuteSecond()

Tuple<Int, Int, Int> GetHourMinuteSecond ( ) const

Gets the TimeValue in hour, minute and second.

Returns
Time value as hour, minute and second.

◆ GetTime()

static TimeValue GetTime ( )
static

Returns the current time stamp. You can use this value for benchmarking/profiling. The resolution is much higher than milliseconds.

Note
You must not use these values derived from a cpu clock for longer durations and compare them to the real time clock.
See also
UniversalDateTime::GetNow LocalDateTime::GetNow
Returns
Current time stamp.

◆ Stop()

const TimeValue& Stop ( )

Substracts the current time, subtracts it from the value stored in the TimeValue and returns this duration.

... do anything ...
t1.Stop();
DiagnosticOutput("Duration: @", t1);
static TimeValue GetTime()
Returns the current time stamp. You can use this value for benchmarking/profiling....
TimeValue()
Default constructs with 0.
Definition: timevalue.h:42
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:170
Returns
Returns the timer difference.

◆ ToString()

String ToString ( const FormatStatement formatStatement = nullptr) const

Converts the value into a string.

Parameters
[in]formatStatementNullptr or an additional formatting instruction. See also Formatting Timer values.
Returns
The converted result.

◆ GetFrame()

Int GetFrame ( Float64  frameRate) const

Retrieves the frame number for a given frame rate.

Note
Frame numbers are integer and therefore quantized.

◆ Quantize()

void Quantize ( Float64  frameRate)

Quantizes the time for a given frame rate, so that its frame value is a multiple of the specified frame rate.

◆ TimeToString()

String TimeToString ( TIMEFORMAT  timeFormat = TIMEFORMAT::SECONDS,
Float64  frameRate = 1 
) const

Converts TimeValue into String.

Parameters
[in]timeFormatSpecifies the display format. In case of TIMEFORMAT::SECONDS the string will contain a floating point number with two digits after the comma.
In case of TIMEFORMAT::FRAMES the string will contain an integer frame number or -if the time does not fall on frame boundaries- a floating point number with two digits after the comma.
In case of TIMEFORMAT::SMPTE the return will have the format HH:MM:SS:FF. Frames are always integer values.
In case of TIMEFORMAT::SMPTE_DROPFRAMES the return will have the format HH;MM;SS;FF. Note the semicolons instead of the colons. Read more about drop frames here. A TimeValue(3600.0) equals a drop frame time code of 01:00:03:18 (3600 * 30 frames take roughly 1 hour and 3.6 seconds to play back at NTSC frame rate). If the passed frame rate does not match FRAMERATE_NTSC or FRAMERATE_FILM_NTSC the result will be as if TIMEFORMAT::SMPTE was passed.
[in]frameRateThe used frame rate, does not need to be provided if TIMEFORMAT::SECONDS is set.
Returns
The time as a readable string.

◆ TimeFromString()

Result<void> TimeFromString ( const String str,
TIMEFORMAT  timeFormat,
Float64  frameRate 
)

Converts String into TimeValue.

Parameters
[in]strThe string to be converted.
[in]timeFormatSpecifies the format of the passed string. See also TimeValue::ToString. In case of a SMPTE format drop frame or non-drop frame style is determined by this value and both colons or semicolons are allowed.
[in]frameRateThe used frame rate, does not need to be provided if TIMEFORMAT::SECONDS is set.
Returns
OK on success.

◆ DescribeIO()

static Result<void> DescribeIO ( const DataSerializeInterface stream)
static

Describes all elements of this class for I/O operations.

Parameters
[in]streamThe stream that is used to register the class members.
Returns
OK on success.

Friends And Related Function Documentation

◆ operator*

TimeValue operator* ( const TimeValue a,
const Float64 b 
)
friend

Multiplies a TimeValue with a factor.

Parameters
[in]aThe TimeValue to multiply.
[in]bThe factor.
Returns
The result of a * b.

◆ operator/ [1/2]

Float64 operator/ ( const TimeValue a,
const TimeValue b 
)
friend

Divides two TimeValues and returns the quotient.

Parameters
[in]aThe dividend.
[in]bThe divisor. If the divisor is 0, the result will be undefined (floating point exception).
Returns
The result of a / b, the quotient has no unit therefore it is returned as Float64.

◆ operator/ [2/2]

TimeValue operator/ ( const TimeValue a,
const Float64  b 
)
friend

Divides a TimeValues by a scalar and returns the quotient.

Parameters
[in]aThe dividend.
[in]bThe divisor. If the divisor is 0, the result will be undefined (floating point exception).
Returns
The result of a / b.

Member Data Documentation

◆ NOW

const CurrentTime NOW
static

◆ _value

Float64 _value
private