Fixposition SDK 0.0.0-heads/main-0-g90a51ff
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
fpsdk::common::time::Duration Class Reference

Time duration. More...

#include <time.hpp>

Public Member Functions

Set duration

These do not throw and instead return true/false.

bool SetSecNSec (const int32_t sec, const int32_t nsec)
 Set duration from seconds and nanoseconds.
 
bool SetNSec (const int64_t nsec)
 Set duration from nanoseconds.
 
bool SetSec (const double sec)
 Set duration from seconds.
 
Get duration
int64_t GetNSec () const
 Get duration as nanoseconds.
 
double GetSec (const int prec=9) const
 Get duration as seconds.
 
std::chrono::milliseconds GetChronoMilli () const
 Get duration as std::chrono::milliseconds.
 
std::chrono::nanoseconds GetChronoNano () const
 Get duration as std::chrono::nanoseconds.
 
Misc
bool IsZero () const
 Check if duration is zero.
 
std::string Stringify (const int prec=3) const
 Stringify duration, for debugging.
 
void Sleep () const
 Sleep for the duration (if > 0)
 
Arithmetic methods

These do not throw and instead return true/false.

bool AddDur (const Duration &dur)
 Add duration to duration.
 
bool AddNSec (const int64_t nsec)
 Add nanoseconds to duration.
 
bool AddSec (const double sec)
 Add seconds to duration.
 
bool SubDur (const Duration &dur)
 Substract duration from duration.
 
bool SubNSec (const int64_t nsec)
 Substract nanoseconds from duration.
 
bool SubSec (const double sec)
 Substract seconds from duration.
 
bool Scale (const double sec)
 Scale (multiply) duration.
 
Arithmetic operators
Note
These throw std::runtime_error if the values are out of range.
Duration operator+ (const Duration &rhs) const
 Sum duration and duration.
 
Duration operator+ (const int64_t nsec) const
 Sum duration and nanoseconds.
 
Duration operator+ (const double sec) const
 Sum duration and seconds.
 
Durationoperator+= (const Duration &rhs)
 Add duration to duration.
 
Durationoperator+= (const int64_t nsec)
 Add nanoseconds to durationn.
 
Durationoperator+= (const double sec)
 Add seconds to duration.
 
Duration operator- (const Duration &rhs) const
 Subtract duration and duration.
 
Duration operator- (const int64_t nsec) const
 Subtract duration and nanoseconds.
 
Duration operator- (const double sec) const
 Subtract duration and seconds.
 
Durationoperator-= (const Duration &rhs)
 Subtract duration from duration.
 
Durationoperator-= (const int64_t nsec)
 Subtract nanoseconds from duration.
 
Durationoperator-= (const double sec)
 Subtract seconds from durationn.
 
Duration operator- () const
 Reverse sign.
 
Duration operator* (double scale) const
 Multiply (scale) duration.
 
Durationoperator*= (double scale)
 Multiply (scale) duration.
 
Logic operators
bool operator== (const Duration &rhs) const
 Equal.
 
bool operator!= (const Duration &rhs) const
 Not equal.
 
bool operator> (const Duration &rhs) const
 Greater than.
 
bool operator< (const Duration &rhs) const
 Smaller than.
 
bool operator>= (const Duration &rhs) const
 Greater or equal than.
 
bool operator<= (const Duration &rhs) const
 Smaller or equal than.
 

Public Attributes

int32_t sec_
 Seconds part of duration.
 
int32_t nsec_
 Nanoseconds part of duration (should be in range 0-999999999)
 

Make Duration object

Note
These throw std::runtime_error if the values are out of range.
 Duration ()
 Constructor, zero duration.
 
static Duration FromSecNSec (const int32_t sec, const int32_t nsec)
 Make Duration from seconds and nanoseconds.
 
static Duration FromNSec (const int64_t nsec)
 Make Duration from nanoseconds.
 
static Duration FromSec (const double sec)
 Make Duration from seconds.
 

Detailed Description

Time duration.

This is similar (and binary compatible) to ros::Duration and rpclpp::Duration. While some of the constructors and operators can throw, it also provides non-throwing methods to manipulate the duration.

Definition at line 153 of file time.hpp.

Member Function Documentation

◆ FromSecNSec()

static Duration fpsdk::common::time::Duration::FromSecNSec ( const int32_t sec,
const int32_t nsec )
static

Make Duration from seconds and nanoseconds.

Parameters
[in]secDuration value seconds
[in]nsecDuration value nanoseconds

◆ FromNSec()

static Duration fpsdk::common::time::Duration::FromNSec ( const int64_t nsec)
static

Make Duration from nanoseconds.

Parameters
[in]nsecDuration value nanoseconds

◆ FromSec()

static Duration fpsdk::common::time::Duration::FromSec ( const double sec)
static

Make Duration from seconds.

Parameters
[in]secDuration value seconds

◆ SetSecNSec()

bool fpsdk::common::time::Duration::SetSecNSec ( const int32_t sec,
const int32_t nsec )

Set duration from seconds and nanoseconds.

Parameters
[in]secDuration value seconds
[in]nsecDuration value nanoseconds
Returns
true if successful (values in range), false otherwise (bad values)

◆ SetNSec()

bool fpsdk::common::time::Duration::SetNSec ( const int64_t nsec)

Set duration from nanoseconds.

Parameters
[in]nsecDuration value nanoseconds
Returns
true if successful (sec value in range), false otherwise (bad sec value)

◆ SetSec()

bool fpsdk::common::time::Duration::SetSec ( const double sec)

Set duration from seconds.

Parameters
[in]secDuration value seconds
Returns
true if successful (sec value in range), false otherwise (bad sec value)

◆ GetNSec()

int64_t fpsdk::common::time::Duration::GetNSec ( ) const

Get duration as nanoseconds.

Returns
the duration as nanoseconds

◆ GetSec()

double fpsdk::common::time::Duration::GetSec ( const int prec = 9) const

Get duration as seconds.

Parameters
[in]precRound the seconds to this many fractional digits (0-9)
Returns
the duration as seconds

◆ GetChronoMilli()

std::chrono::milliseconds fpsdk::common::time::Duration::GetChronoMilli ( ) const

Get duration as std::chrono::milliseconds.

Returns
the duration as std::chrono::milliseconds

◆ GetChronoNano()

std::chrono::nanoseconds fpsdk::common::time::Duration::GetChronoNano ( ) const

Get duration as std::chrono::nanoseconds.

Returns
the duration as std::chrono::nanoseconds

◆ IsZero()

bool fpsdk::common::time::Duration::IsZero ( ) const

Check if duration is zero.

Returns
true if duration is exactly zero

◆ Stringify()

std::string fpsdk::common::time::Duration::Stringify ( const int prec = 3) const

Stringify duration, for debugging.

Parameters
[in]precNumber of fractional digits for the seconds (0-9)
Returns
The stringified duration ("HH:MM:SS.SSS", resp. "DDd HH:MM:SS.SSS" if duration > 1d)

◆ AddDur()

bool fpsdk::common::time::Duration::AddDur ( const Duration & dur)

Add duration to duration.

Parameters
[in]durDuration to add
Returns
true if successful (dur value in range), false otherwise (bad sec value)

◆ AddNSec()

bool fpsdk::common::time::Duration::AddNSec ( const int64_t nsec)

Add nanoseconds to duration.

Parameters
[in]nsecNanoseconds to add
Returns
true if successful (sec value in range), false otherwise (bad sec value)

◆ AddSec()

bool fpsdk::common::time::Duration::AddSec ( const double sec)

Add seconds to duration.

Parameters
[in]secSeconds to add
Returns
true if successful (sec value in range), false otherwise (bad sec value)

◆ SubDur()

bool fpsdk::common::time::Duration::SubDur ( const Duration & dur)

Substract duration from duration.

Parameters
[in]durDuration to substract
Returns
true if successful (dur value in range), false otherwise (bad sec value)

◆ SubNSec()

bool fpsdk::common::time::Duration::SubNSec ( const int64_t nsec)

Substract nanoseconds from duration.

Parameters
[in]nsecNanoseconds to substract
Returns
true if successful (sec value in range), false otherwise (bad sec value)

◆ SubSec()

bool fpsdk::common::time::Duration::SubSec ( const double sec)

Substract seconds from duration.

Parameters
[in]secSeconds to substract
Returns
true if successful (sec value in range), false otherwise (bad sec value)

◆ Scale()

bool fpsdk::common::time::Duration::Scale ( const double sec)

Scale (multiply) duration.

Parameters
[in]secScale factor
Returns
true if successful (scale value in range), false otherwise (bad scale value)

Member Data Documentation

◆ sec_

int32_t fpsdk::common::time::Duration::sec_

Seconds part of duration.

Definition at line 408 of file time.hpp.

◆ nsec_

int32_t fpsdk::common::time::Duration::nsec_

Nanoseconds part of duration (should be in range 0-999999999)

Definition at line 409 of file time.hpp.


The documentation for this class was generated from the following file: