RTI Connext Modern C++ API  Version 7.0.0
dds::core::Duration Class Reference

<<value-type>> Represents a time interval More...

#include <Duration.hpp>

Public Member Functions

 Duration ()
 Create a Duration elapsing zero seconds. More...
 
 Duration (int32_t sec, uint32_t nanosec=0)
 Create a duration elapsing a specific amount of time. More...
 
template<typename Rep , typename Period >
 Duration (const std::chrono::duration< Rep, Period > &duration)
 <<C++11>> <<extension>> Allow implicit creation from std::chrono::duration More...
 
int32_t sec () const
 Get the number of seconds represented by this Duration object. More...
 
void sec (int32_t s)
 Set the number of seconds represented by this Duration object. More...
 
uint32_t nanosec () const
 Get the number of nanoseconds represented by this Duration object. More...
 
void nanosec (uint32_t ns)
 Set the number of nanoseconds represented by this Duration object. More...
 
int compare (const Duration &that) const
 Compare two Duration objects. More...
 
bool operator> (const Duration &that) const
 Check if this Duration is greater than another. More...
 
bool operator>= (const Duration &that) const
 Check if this Duration is greater than or equal another. More...
 
bool operator== (const Duration &that) const
 Check if this Duration is equal to another. More...
 
bool operator!= (const Duration &other) const
 Check if this Duration is not equal to another. More...
 
bool operator<= (const Duration &that) const
 Check if this Duration is less than or equal another. More...
 
bool operator< (const Duration &that) const
 Check if this Duration is less than another. More...
 
Durationoperator+= (const Duration &a_ti)
 Add a Duration to this Duration. More...
 
Durationoperator-= (const Duration &a_ti)
 Subtract a Duration from this Duration. More...
 
Duration operator+ (const Duration &other) const
 Add two Duration objects. More...
 
Duration operator- (const Duration &other) const
 Subtract a Duration. More...
 
uint64_t to_millisecs () const
 Returns this Duration in milliseconds. More...
 
uint64_t to_microsecs () const
 Returns this Duration in microseconds. More...
 
double to_secs () const
 Returns this Duration in seconds. More...
 
std::chrono::nanoseconds to_chrono () const
 <<C++11>> <<extension>> Converts to std::chrono::nanoseconds More...
 

Static Public Member Functions

static Duration zero ()
 Returns a zero duration. More...
 
static Duration infinite ()
 Special value that represents an infinite Duration. More...
 
static Duration automatic ()
 Special value that indicates that RTI Connext will automatically assign a value. More...
 
static Duration from_microsecs (uint64_t microseconds)
 Create a Duration elapsing a specific number of microseconds. More...
 
static Duration from_millisecs (uint64_t milliseconds)
 Create a Duration elapsing a specific number of milliseconds. More...
 
static Duration from_secs (double seconds)
 Create a Duration elapsing a specific number of seconds. More...
 

Related Functions

(Note that these are not member functions.)

Duration operator* (uint32_t lhs, const Duration &rhs)
 Multiply a Duration object by an unsigned integer. More...
 
Duration operator* (const Duration &lhs, uint32_t rhs)
 Multiply a Duration object by an unsigned integer. More...
 
Duration operator/ (const Duration &lhs, uint32_t rhs)
 Divide a Duration object by an unsigned integer. More...
 
void swap (Duration &lhs, Duration &rhs) OMG_NOEXCEPT
 Swap the contents of two Duration objects. More...
 

Detailed Description

<<value-type>> Represents a time interval

Examples:
Foo_publisher.cxx, and Foo_subscriber.cxx.

Constructor & Destructor Documentation

◆ Duration() [1/3]

dds::core::Duration::Duration ( )

Create a Duration elapsing zero seconds.

◆ Duration() [2/3]

dds::core::Duration::Duration ( int32_t  sec,
uint32_t  nanosec = 0 
)
explicit

Create a duration elapsing a specific amount of time.

Parameters
secThe number of seconds to represent
nanosecThe number of nanoseconds to represent

◆ Duration() [3/3]

template<typename Rep , typename Period >
dds::core::Duration::Duration ( const std::chrono::duration< Rep, Period > &  duration)
inline

<<C++11>> <<extension>> Allow implicit creation from std::chrono::duration

For example:

// ...
waitset.wait(std::chrono::seconds(1) + std::chrono::milliseconds(250));

References dds::core::operator+(), and dds::core::operator-().

Member Function Documentation

◆ zero()

static Duration dds::core::Duration::zero ( )
static

Returns a zero duration.

Returns
Duration()

◆ infinite()

static Duration dds::core::Duration::infinite ( )
static

◆ automatic()

static Duration dds::core::Duration::automatic ( )
static

Special value that indicates that RTI Connext will automatically assign a value.

◆ from_microsecs()

static Duration dds::core::Duration::from_microsecs ( uint64_t  microseconds)
static

Create a Duration elapsing a specific number of microseconds.

Parameters
microsecondsThe number of microseconds to construct the object from
Returns
A newly constructed Duration object

◆ from_millisecs()

static Duration dds::core::Duration::from_millisecs ( uint64_t  milliseconds)
static

Create a Duration elapsing a specific number of milliseconds.

Parameters
millisecondsThe number of milliseconds to construct the object from
Returns
A newly constructed Duration object

Referenced by dds::core::policy::DestinationOrder::ReceptionTimestamp().

◆ from_secs()

static Duration dds::core::Duration::from_secs ( double  seconds)
static

Create a Duration elapsing a specific number of seconds.

Parameters
secondsThe number of seconds to construct the object from
Returns
A newly constructed Duration object

◆ sec() [1/2]

int32_t dds::core::Duration::sec ( ) const

Get the number of seconds represented by this Duration object.

Returns
The number of seconds (excluding the nanoseconds)

◆ sec() [2/2]

void dds::core::Duration::sec ( int32_t  s)

Set the number of seconds represented by this Duration object.

Parameters
sThe number of seconds to set

◆ nanosec() [1/2]

uint32_t dds::core::Duration::nanosec ( ) const

Get the number of nanoseconds represented by this Duration object.

Returns
The number of nanoseconds (excluding the seconds)

◆ nanosec() [2/2]

void dds::core::Duration::nanosec ( uint32_t  ns)

Set the number of nanoseconds represented by this Duration object.

Parameters
nsThe number of nanoseconds to set

◆ compare()

int dds::core::Duration::compare ( const Duration that) const

Compare two Duration objects.

Parameters
thatThe Duration object to compare with this Duration.
Returns
int The result of the comparison can be: -1 if this Duration is less than other; 0 if they are equal; 1 if this Duration is greater than other

◆ operator>()

bool dds::core::Duration::operator> ( const Duration that) const

Check if this Duration is greater than another.

Parameters
thatThe Duration to compare with this Duration.
Returns
bool false if this Duration is less than or equal to the other object, true otherwise.

◆ operator>=()

bool dds::core::Duration::operator>= ( const Duration that) const

Check if this Duration is greater than or equal another.

Parameters
thatThe Duration to compare with this Duration.
Returns
bool false if this Duration is less than to the other object, true otherwise.

◆ operator==()

bool dds::core::Duration::operator== ( const Duration that) const

Check if this Duration is equal to another.

Parameters
thatThe Duration to compare with this Duration.
Returns
bool false if this Duration is not equal to the other object, true otherwise.

◆ operator!=()

bool dds::core::Duration::operator!= ( const Duration other) const

Check if this Duration is not equal to another.

Parameters
otherThe Duration to compare with this Duration.
Returns
bool false if this Duration is equal to the other object, true otherwise.

◆ operator<=()

bool dds::core::Duration::operator<= ( const Duration that) const

Check if this Duration is less than or equal another.

Parameters
thatThe Duration to compare with this Duration.
Returns
bool false if this Duration is greater than to the other object, true otherwise.

◆ operator<()

bool dds::core::Duration::operator< ( const Duration that) const

Check if this Duration is less than another.

Parameters
thatThe Duration to compare with this Duration.
Returns
bool false if this Duration is greater than or equal to the other object, true otherwise.

◆ operator+=()

Duration& dds::core::Duration::operator+= ( const Duration a_ti)

Add a Duration to this Duration.

Parameters
a_tiThe Duration to add
Returns
Duration& This Duration, with the added Duration

◆ operator-=()

Duration& dds::core::Duration::operator-= ( const Duration a_ti)

Subtract a Duration from this Duration.

Parameters
a_tiThe Duration to subtract
Returns
Duration& This Duration, after the subtraction

◆ operator+()

Duration dds::core::Duration::operator+ ( const Duration other) const

Add two Duration objects.

Parameters
otherThe other Duration to add to this one
Returns
The result of the addition

◆ operator-()

Duration dds::core::Duration::operator- ( const Duration other) const

Subtract a Duration.

Parameters
otherThe Duration to subract from this one
Returns
The result of the subtraction

◆ to_millisecs()

uint64_t dds::core::Duration::to_millisecs ( ) const

Returns this Duration in milliseconds.

Returns
the Duration in milliseconds

◆ to_microsecs()

uint64_t dds::core::Duration::to_microsecs ( ) const

Returns this Duration in microseconds.

Returns
the Duration in microseconds

◆ to_secs()

double dds::core::Duration::to_secs ( ) const

Returns this Duration in seconds.

Returns
the Duration in seconds

◆ to_chrono()

std::chrono::nanoseconds dds::core::Duration::to_chrono ( ) const
inline

<<C++11>> <<extension>> Converts to std::chrono::nanoseconds

Returns
The Duration in nanoseconds.

References dds::core::operator*(), dds::core::operator/(), and dds::core::swap().

Friends And Related Function Documentation

◆ operator*() [1/2]

Duration operator* ( uint32_t  lhs,
const Duration rhs 
)
related

Multiply a Duration object by an unsigned integer.

Parameters
lhsThe unsigned integer to multiply the Duration object by
rhsThe Duration object to multiply
Returns
Duration The result of the multiplication

◆ operator*() [2/2]

Duration operator* ( const Duration lhs,
uint32_t  rhs 
)
related

Multiply a Duration object by an unsigned integer.

Parameters
lhsThe Duration object to multiply
rhsThe unsigned integer to multiply the Duration object by
Returns
Duration The result of the multiplication

◆ operator/()

Duration operator/ ( const Duration lhs,
uint32_t  rhs 
)
related

Divide a Duration object by an unsigned integer.

Parameters
lhsThe dividend
rhsThe divisor
Returns
Duration The result of dividing the two Duration objects

◆ swap()