All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::TimeStamp Class Reference

A high-resolution time-stamp object. More...

#include <Radiant/TimeStamp.hpp>

Public Types

enum  : int64_t { FRACTIONS_PER_SECOND = 0x1000000 }
 
typedef int64_t type
 The internal, signed 64-bit integer type.
 

Public Member Functions

QString asString () const
 Converts the time-stamp to a string. More...
 
int64_t days () const
 Returns the number of complete days this timestamp spans. More...
 
double daysD () const
 Returns the number of days (including fractions of a day) this timestamp spans. More...
 
int64_t fractions () const
 Returns the fractions of second that this timestamp includes, in range 0-2^24. More...
 
int64_t hours () const
 Returns the number of complete hours this timestamp spans. More...
 
int64_t milliseconds () const
 Returns the number of full milliseconds that this time-stamp includes. More...
 
int64_t minutes () const
 Returns the number of complete hours this timestamp spans. More...
 
int64_t seconds () const
 Returns the number of full seconds that this time-stamp includes. More...
 
double secondsD () const
 Returns the number of seconds in this time-stamp, as floating point number. More...
 
double secsTo (const TimeStamp &that) const
 Returns the number of seconds to the argument time-stamp. More...
 
template<typename T >
void setSeconds (T s)
 Sets the timestamp to s seconds. More...
 
void setValue (type val)
 Sets the current native timestamp value. More...
 
TimeStamp since () const
 Returns the amount of time passed since this timestamp. More...
 
double sinceSecondsD () const
 Returns the number of seconds passed since this timestamp. More...
 
double subSecondsD () const
 Returns the fraction of a second in this time-stamp, in range 0.0-1.0. More...
 
double subSecondsUS () const
 Returns the fraction part of a second in microseconds (in range 0.0-1000000.0) More...
 
 TimeStamp ()
 Constructs a timestamp dated to 1.1.1970.
 
 TimeStamp (type val)
 Construct timestamp with the given time internal representation. More...
 
double usecsTo (const TimeStamp &that) const
 Returns the number of micro-seconds to the argument time-stamp. More...
 
typevalue ()
 Returns a reference to the current timestamp native value. More...
 
type value () const
 Returns the current timestamp native value. More...
 

Static Public Member Functions

static TimeStamp createDate (const char *date, const char *delim="-", bool yearfirst=true)
 Creates a timestamp from date string. More...
 
static TimeStamp createDateTime (const char *date, const char *delim, bool yearfirst, const char *time, const char *timedelim)
 Creates a timestamp from date and time string. More...
 
template<typename T >
static TimeStamp createDays (T days)
 Create a time-stamp with a given number of days. More...
 
static TimeStamp createDHMS (int days, int hours, int minutes, int seconds)
 Creates a time-stamp consisting of days, hours, minutes, and seconds. More...
 
template<typename T >
static TimeStamp createHours (T hours)
 Create a time-stamp with a given number of hours. More...
 
template<class T >
static TimeStamp createMilliSeconds (T s, typename std::enable_if< std::is_integral< T >::value >::type *=0)
 Create a TimeStamp with the given number of milliseconds. More...
 
template<class T >
static TimeStamp createMilliSeconds (T s, typename std::enable_if< std::is_floating_point< T >::value >::type *=0)
 Create a TimeStamp with the given number of milliseconds. More...
 
template<typename T >
static TimeStamp createMinutes (T s)
 Create a TimeStamp with the given number of minutes. More...
 
template<class T >
static TimeStamp createSeconds (T s, typename std::enable_if< std::is_integral< T >::value >::type *=0)
 Create a TimeStamp with the given number of seconds. More...
 
template<class T >
static TimeStamp createSeconds (T s, typename std::enable_if< std::is_floating_point< T >::value >::type *=0)
 Create a TimeStamp with the given number of seconds. More...
 
static TimeStamp createTime (const char *time, const char *delim=":")
 Creates a timestamp from time string. More...
 
static TimeStamp currentTime ()
 Returns the current time value, by looking at the wall clock. More...
 
static TimeStamp ticksPerDay ()
 The number of ticks that take place during one day. More...
 
static TimeStamp ticksPerHour ()
 The number of ticks that take place during one hour. More...
 
static TimeStamp ticksPerMinute ()
 The number of ticks that take place during one minute. More...
 
static TimeStamp ticksPerSecond ()
 The number of ticks that take place during one second. More...
 

Detailed Description

A high-resolution time-stamp object.

A time-stamp has 40 bits for the seconds and 24 bits for fractions of a second. The seconds are as they come from the UNIX clock: 1.1.1970 the counter was zero.

Thus there are 2^24 (16777216) ticks in a second, which works as the basic timing unit. This gives about 16.78 ticks per microsecond, which is good enough to do highly accurate timing with any reasonable media source. At the same time the 40-bit second field is sufficient to store all dates within the current century, and a few forward/backward. The time value is internally stored in a signed 64-bit integer. In most applications time-stamps could be unsigned, but this leads easily to annoying bugs if the unsignedness is not taken into account in various time computations.

TimeStamps can be easily casted to/from integer types.

This design is basically copy of the OSC timing system.

Examples:
PostProcessingExample.cpp.

Constructor & Destructor Documentation

Radiant::TimeStamp::TimeStamp ( type  val)
inlineexplicit

Construct timestamp with the given time internal representation.

Parameters
valinternal time presentation

Member Function Documentation

QString Radiant::TimeStamp::asString ( ) const

Converts the time-stamp to a string.

Returns
time-stamp as string
static TimeStamp Radiant::TimeStamp::createDate ( const char *  date,
const char *  delim = "-",
bool  yearfirst = true 
)
static

Creates a timestamp from date string.

Parameters
dateString for date
delimDelimiter string between fields
Iftrue the date is formatted as YdMdD, where d is the value of delim. If false the date has format DdMdY. Here each field can have arbitrary integer.
Returns
TimeStamp corresponding to given string
static TimeStamp Radiant::TimeStamp::createDateTime ( const char *  date,
const char *  delim,
bool  yearfirst,
const char *  time,
const char *  timedelim 
)
static

Creates a timestamp from date and time string.

Parameters
dateString for date
delimDelimiter string between fields of date
Iftrue the date is formatted as YdMdD. Otherwise date has format DdMdY.
timeString for time formatted as HdMdS.
timedelimDelimiter string between fields of time
Returns
TimeStamp corresponding to given strings
See Also
createDate, createTime
template<typename T >
static TimeStamp Radiant::TimeStamp::createDays ( days)
inlinestatic

Create a time-stamp with a given number of days.

Parameters
daysnumber of days
Returns
specified timestamp
Template Parameters
TType of parameter for days
static TimeStamp Radiant::TimeStamp::createDHMS ( int  days,
int  hours,
int  minutes,
int  seconds 
)
inlinestatic

Creates a time-stamp consisting of days, hours, minutes, and seconds.

Parameters
daysnumber of days
hoursnumber of hours
minutesnumber of minutes
secondsnumber of seconds
Returns
new time-stamp
template<typename T >
static TimeStamp Radiant::TimeStamp::createHours ( hours)
inlinestatic

Create a time-stamp with a given number of hours.

Parameters
hoursnumber of hours
Returns
specified timestamp
Template Parameters
TType of parameter for hours
template<class T >
static TimeStamp Radiant::TimeStamp::createMilliSeconds ( s,
typename std::enable_if< std::is_integral< T >::value >::type = 0 
)
inlinestatic

Create a TimeStamp with the given number of milliseconds.

Parameters
snumber of milliseconds
Returns
specified timestamp
Template Parameters
TType of parameter for milliseconds
template<class T >
static TimeStamp Radiant::TimeStamp::createMilliSeconds ( s,
typename std::enable_if< std::is_floating_point< T >::value >::type = 0 
)
inlinestatic

Create a TimeStamp with the given number of milliseconds.

Parameters
snumber of milliseconds
Returns
specified timestamp
Template Parameters
TType of parameter for milliseconds
template<typename T >
static TimeStamp Radiant::TimeStamp::createMinutes ( s)
inlinestatic

Create a TimeStamp with the given number of minutes.

Parameters
snumber of minutes
Returns
specified timestamp
Template Parameters
TType of parameter for minutes
template<class T >
static TimeStamp Radiant::TimeStamp::createSeconds ( s,
typename std::enable_if< std::is_integral< T >::value >::type = 0 
)
inlinestatic

Create a TimeStamp with the given number of seconds.

Parameters
snumber of seconds
Returns
specified timestamp
Template Parameters
TType of parameter for seconds
Examples:
PostProcessingExample.cpp.
template<class T >
static TimeStamp Radiant::TimeStamp::createSeconds ( s,
typename std::enable_if< std::is_floating_point< T >::value >::type = 0 
)
inlinestatic

Create a TimeStamp with the given number of seconds.

Parameters
snumber of seconds
Returns
specified timestamp
Template Parameters
TType of parameter for seconds
static TimeStamp Radiant::TimeStamp::createTime ( const char *  time,
const char *  delim = ":" 
)
static

Creates a timestamp from time string.

Parameters
timeString for time formatted as HdMdS, where d stands for the value of delim, H for hours, M for minutes and S for seconds. Each field can contain arbitrary integer.
delimDelimiter string between fields
Returns
TimeStamp corresponding to given string
static TimeStamp Radiant::TimeStamp::currentTime ( )
static

Returns the current time value, by looking at the wall clock.

Returns
current time
Examples:
AnimatorExample.cpp, and PostProcessingExample.cpp.
int64_t Radiant::TimeStamp::days ( ) const
inline

Returns the number of complete days this timestamp spans.

Returns
Complete days from 1.1.1970
double Radiant::TimeStamp::daysD ( ) const
inline

Returns the number of days (including fractions of a day) this timestamp spans.

Returns
Days (including fractions) from 1.1.1970
int64_t Radiant::TimeStamp::fractions ( ) const
inline

Returns the fractions of second that this timestamp includes, in range 0-2^24.

Returns
Fraction of seconds part from the internal representation (24 lowest bits)
int64_t Radiant::TimeStamp::hours ( ) const
inline

Returns the number of complete hours this timestamp spans.

Returns
Complete hours from 1.1.1970
int64_t Radiant::TimeStamp::milliseconds ( ) const
inline

Returns the number of full milliseconds that this time-stamp includes.

Returns
Complete milliseconds from 1.1.1970
int64_t Radiant::TimeStamp::minutes ( ) const
inline

Returns the number of complete hours this timestamp spans.

Returns
Complete minutes from 1.1.1970
int64_t Radiant::TimeStamp::seconds ( ) const
inline

Returns the number of full seconds that this time-stamp includes.

Returns
Complete seconds from 1.1.1970
double Radiant::TimeStamp::secondsD ( ) const
inline

Returns the number of seconds in this time-stamp, as floating point number.

Returns
Seconds (including fractions) from 1.1.1970
double Radiant::TimeStamp::secsTo ( const TimeStamp that) const
inline

Returns the number of seconds to the argument time-stamp.

Returns
How many seconds that is ahead of this
template<typename T >
void Radiant::TimeStamp::setSeconds ( s)
inline

Sets the timestamp to s seconds.

Parameters
snumber of seconds
Template Parameters
TType of parameter for seconds
void Radiant::TimeStamp::setValue ( type  val)
inline

Sets the current native timestamp value.

Parameters
valNew value of the timestamp
TimeStamp Radiant::TimeStamp::since ( ) const
inline

Returns the amount of time passed since this timestamp.

Computes the difference between currentTime and this time-stamp

Returns
amount of time passed since this time-stamp
double Radiant::TimeStamp::sinceSecondsD ( ) const
inline

Returns the number of seconds passed since this timestamp.

Returns
seconds passed since this time-stamp
double Radiant::TimeStamp::subSecondsD ( ) const
inline

Returns the fraction of a second in this time-stamp, in range 0.0-1.0.

Returns
The non-integral part of the seconds from 1.1.1970 normalized to unit interval
double Radiant::TimeStamp::subSecondsUS ( ) const
inline

Returns the fraction part of a second in microseconds (in range 0.0-1000000.0)

Returns
The non-integral part of the seconds from 1.1.1970 as milliseconds
static TimeStamp Radiant::TimeStamp::ticksPerDay ( )
inlinestatic

The number of ticks that take place during one day.

Returns
Number of ticks per day
static TimeStamp Radiant::TimeStamp::ticksPerHour ( )
inlinestatic

The number of ticks that take place during one hour.

Returns
Number of ticks per hour
static TimeStamp Radiant::TimeStamp::ticksPerMinute ( )
inlinestatic

The number of ticks that take place during one minute.

Returns
Number of ticks per minute
static TimeStamp Radiant::TimeStamp::ticksPerSecond ( )
inlinestatic

The number of ticks that take place during one second.

Returns
Number of ticks per second
double Radiant::TimeStamp::usecsTo ( const TimeStamp that) const
inline

Returns the number of micro-seconds to the argument time-stamp.

Returns
How many microseconds that is ahead of this
type& Radiant::TimeStamp::value ( )
inline

Returns a reference to the current timestamp native value.

Returns
Reference to the timestamp value
type Radiant::TimeStamp::value ( ) const
inline

Returns the current timestamp native value.

Returns
Value of the timestamp