Mbed OS Reference
Loading...
Searching...
No Matches
Duration< Rep, TB, Range, Forever > Struct Template Reference

Model BLE durations. More...

#include <Duration.h>

Public Types

typedef Rep representation_t
 Type of the actual representation. More...
 

Public Member Functions

 Duration ()
 Construct a default Duration. More...
 
 Duration (Rep v)
 Construct a Duration from an integer value. More...
 
template<typename OtherRep , uint32_t OtherTB, typename OtherRange , typename OtherF >
 Duration (Duration< OtherRep, OtherTB, OtherRange, OtherF > other)
 Construct a Duration from another Duration. More...
 
template<typename OtherRep , typename OtherRange , typename OtherF >
 Duration (Duration< OtherRep, 1000, OtherRange, OtherF > other_ms, void *=nullptr)
 Construct a new Duration from a Duration in milliseconds. More...
 
Rep value () const
 Return the duration in TB units. More...
 
uint32_t valueInMs () const
 Return the duration in milliseconds. More...
 
const Rep * storage () const
 Return a pointer to the value of the duration. More...
 
bool isForever () const
 Test if the forever value is being held. More...
 
std::chrono::duration< Rep, typename std::ratio< TB, 1000000 >::type > valueChrono () const
 Convert the duration into an std::chrono one. More...
 

Static Public Member Functions

static Duration min ()
 Return the minimum duration. More...
 
static Duration max ()
 Return the maximum duration. More...
 
static Duration forever ()
 Return the Duration value meaning forever. More...
 

Static Public Attributes

static const uint32_t TIME_BASE = TB
 The time base. More...
 
static const Rep MIN = Range::MIN
 Left-bound of the duration range. More...
 
static const Rep MAX = Range::MAX
 Right bound of the duration range. More...
 

Related Functions

(Note that these are not member functions.)

template<typename DurationOut , typename RepIn , uint32_t TBIn, typename RangeIn , typename FIn >
DurationOut durationCast (Duration< RepIn, TBIn, RangeIn, FIn > duration)
 Cast a duration to another. More...
 
template<typename RepLHS , uint32_t TBLHS, typename RangeLHS , typename FLHS , typename RepRHS , uint32_t TBRHS, typename RangeRHS , typename FRHS >
microsecond_t operator+ (Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
 Add two durations together and return the result in microseconds. More...
 
template<typename Rep , uint32_t TB, typename Range , typename F >
Duration< Rep, TB, Range, F > operator+ (Duration< Rep, TB, Range, F > lhs, Duration< Rep, TB, Range, F > rhs)
 Add two durations together. More...
 
template<typename Rep , uint32_t TB, typename Range , typename F >
Duration< Rep, TB, Range, F > operator* (Duration< Rep, TB, Range, F > lhs, uint32_t rhs)
 Multiply a duration and a positive integer. More...
 
template<typename Rep , uint32_t TB, typename Range , typename F >
Duration< Rep, TB, Range, F > operator* (uint32_t lhs, Duration< Rep, TB, Range, F > rhs)
 Multiply a duration and a positive integer. More...
 
template<typename RepLHS , uint32_t TBLHS, typename RangeLHS , typename FLHS , typename RepRHS , uint32_t TBRHS, typename RangeRHS , typename FRHS >
bool operator< (Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
 Indicate if the duration lhs is less than the duration rhs. More...
 
template<typename Rep , uint32_t Us, typename Range , typename F >
bool operator< (Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
 Indicate if the duration lhs is less than the duration rhs. More...
 
template<typename RepLHS , uint32_t TBLHS, typename RangeLHS , typename FLHS , typename RepRHS , uint32_t TBRHS, typename RangeRHS , typename FRHS >
bool operator<= (Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
 Indicate if the duration lhs is less than or equal to the duration rhs. More...
 
template<typename Rep , uint32_t Us, typename Range >
bool operator<= (Duration< Rep, Us, Range > lhs, Duration< Rep, Us, Range > rhs)
 Indicate if the duration lhs is less than or equal to the duration rhs. More...
 
template<typename RepLHS , uint32_t TBLHS, typename RangeLHS , typename FLHS , typename RepRHS , uint32_t TBRHS, typename RangeRHS , typename FRHS >
bool operator== (Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
 Indicate if the duration lhs is equal to the duration rhs. More...
 
template<typename Rep , uint32_t Us, typename Range , typename F >
bool operator== (Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
 Indicate if the duration lhs is equal to the duration rhs. More...
 
template<typename RepLHS , uint32_t TBLHS, typename RangeLHS , typename FLHS , typename RepRHS , uint32_t TBRHS, typename RangeRHS , typename FRHS >
bool operator!= (Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
 Indicate if the duration lhs is not equal to the duration rhs. More...
 
template<typename Rep , uint32_t Us, typename Range , typename F >
bool operator!= (Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
 Indicate if the duration lhs is not equal to the duration rhs. More...
 
template<typename RepLHS , uint32_t TBLHS, typename RangeLHS , typename FLHS , typename RepRHS , uint32_t TBRHS, typename RangeRHS , typename FRHS >
bool operator>= (Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
 Indicate if the duration lhs greater or equal to the duration rhs. More...
 
template<typename Rep , uint32_t Us, typename Range , typename F >
bool operator>= (Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
 Indicate if the duration lhs greater or equal to the duration rhs. More...
 
template<typename RepLHS , uint32_t TBLHS, typename RangeLHS , typename FLHS , typename RepRHS , uint32_t TBRHS, typename RangeRHS , typename FRHS >
bool operator> (Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
 Indicate if the duration lhs greater than the duration rhs. More...
 
template<typename Rep , uint32_t Us, typename Range , typename F >
bool operator> (Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
 Indicate if the duration lhs greater than the duration rhs. More...
 

Detailed Description

template<typename Rep, uint32_t TB, typename Range = typename DefaultRange<Rep>::type, typename Forever = void*>
struct ble::Duration< Rep, TB, Range, Forever >

Model BLE durations.

Template Parameters
RepThe representation type of the duration.
TBThe time base in micro seconds.
RangeClosed interval of the duration
ForeverThe special value (if applicable) that represents a forever duration.

Definition at line 104 of file Duration.h.

Member Typedef Documentation

◆ representation_t

typedef Rep representation_t

Type of the actual representation.

Definition at line 108 of file Duration.h.

Constructor & Destructor Documentation

◆ Duration() [1/4]

Duration ( )

Construct a default Duration.

It is initialized with the minimum value acceptable.

Definition at line 115 of file Duration.h.

◆ Duration() [2/4]

Duration ( Rep  v)
explicit

Construct a Duration from an integer value.

Parameters
vThe value of the duration in TIME_BASE units.

Definition at line 124 of file Duration.h.

◆ Duration() [3/4]

Duration ( Duration< OtherRep, OtherTB, OtherRange, OtherF >  other)

Construct a Duration from another Duration.

Note
The operation fail at compile time if there is a loss of precision.
Template Parameters
OtherRepThe type used to represent the other Duration.
OtherTBThe time base in micro seconds of the other Duration.
OtherRangeThe range of the other Duration.
OtherFThe forever value of the other type.
Parameters
otherThe Duration used to construct this object.

Definition at line 141 of file Duration.h.

◆ Duration() [4/4]

Duration ( Duration< OtherRep, 1000, OtherRange, OtherF >  other_ms,
void *  = nullptr 
)
explicit

Construct a new Duration from a Duration in milliseconds.

Note
The result of the conversion is rounded up.
Template Parameters
OtherRepThe representation type used by other_ms.
OtherRangeThe range used by other_ms.
OtherFThe forever value used by other_ms.
Parameters
other_msThe Duration in millisecond to convert.

Definition at line 159 of file Duration.h.

Member Function Documentation

◆ value()

Rep value ( ) const

Return the duration in TB units.

Returns
The duration in TB units.

Definition at line 169 of file Duration.h.

◆ valueInMs()

uint32_t valueInMs ( ) const

Return the duration in milliseconds.

Returns
The duration in milliseconds.

Definition at line 179 of file Duration.h.

◆ min()

static Duration min ( )
static

Return the minimum duration.

Returns
The minimum duration.

Definition at line 204 of file Duration.h.

◆ max()

static Duration max ( )
static

Return the maximum duration.

Returns
The maximum duration.

Definition at line 214 of file Duration.h.

◆ storage()

const Rep * storage ( ) const

Return a pointer to the value of the duration.

Returns
a pointer to the value of the duration.

Definition at line 224 of file Duration.h.

◆ forever()

static Duration forever ( )
static

Return the Duration value meaning forever.

Returns
the Duration value meaning forever.

Definition at line 233 of file Duration.h.

◆ isForever()

bool isForever ( ) const

Test if the forever value is being held.

Returns
True if the forever value is held False otherwise

◆ valueChrono()

std::chrono::duration< Rep, typename std::ratio< TB, 1000000 >::type > valueChrono ( ) const

Convert the duration into an std::chrono one.

Returns
The duration in the std::chrono format.

Definition at line 273 of file Duration.h.

Friends And Related Function Documentation

◆ durationCast()

DurationOut durationCast ( Duration< RepIn, TBIn, RangeIn, FIn >  duration)
related

Cast a duration to another.

Template Parameters
DurationOutType of the Duration in output.
RepInThe representation type of duration.
TBInThe timebase of duration.
RangeInThe range of duration.
FInThe Forever value of duration.
Parameters
durationThe duration to convert.
Returns
The converted duration. It is rounded up if precision is lost.

Definition at line 324 of file Duration.h.

◆ operator+() [1/2]

microsecond_t operator+ ( Duration< RepLHS, TBLHS, RangeLHS, FLHS >  lhs,
Duration< RepRHS, TBRHS, RangeRHS, FRHS >  rhs 
)
related

Add two durations together and return the result in microseconds.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
The result of the addition of the two durations in microseconds.

Definition at line 340 of file Duration.h.

◆ operator+() [2/2]

Duration< Rep, TB, Range, F > operator+ ( Duration< Rep, TB, Range, F >  lhs,
Duration< Rep, TB, Range, F >  rhs 
)
related

Add two durations together.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
The addition of the two durations in input.

Definition at line 357 of file Duration.h.

◆ operator*() [1/2]

Duration< Rep, TB, Range, F > operator* ( Duration< Rep, TB, Range, F >  lhs,
uint32_t  rhs 
)
related

Multiply a duration and a positive integer.

Parameters
lhsThe duration.
rhsThe integer.
Returns
A duration that represents the multiplication of lhs with rhs.

Definition at line 376 of file Duration.h.

◆ operator*() [2/2]

Duration< Rep, TB, Range, F > operator* ( uint32_t  lhs,
Duration< Rep, TB, Range, F >  rhs 
)
related

Multiply a duration and a positive integer.

Parameters
lhsThe integer.
rhsThe multiplication.
Returns
A duration that represents the multiplication of lhs with rhs.

Definition at line 392 of file Duration.h.

◆ operator<() [1/2]

bool operator< ( Duration< RepLHS, TBLHS, RangeLHS, FLHS >  lhs,
Duration< RepRHS, TBRHS, RangeRHS, FRHS >  rhs 
)
related

Indicate if the duration lhs is less than the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is less than rhs and false otherwise.

Definition at line 409 of file Duration.h.

◆ operator<() [2/2]

bool operator< ( Duration< Rep, Us, Range, F >  lhs,
Duration< Rep, Us, Range, F >  rhs 
)
related

Indicate if the duration lhs is less than the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is less than rhs and false otherwise.

Definition at line 423 of file Duration.h.

◆ operator<=() [1/2]

bool operator<= ( Duration< RepLHS, TBLHS, RangeLHS, FLHS >  lhs,
Duration< RepRHS, TBRHS, RangeRHS, FRHS >  rhs 
)
related

Indicate if the duration lhs is less than or equal to the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is less than or equal to rhs and false otherwise.

Definition at line 440 of file Duration.h.

◆ operator<=() [2/2]

bool operator<= ( Duration< Rep, Us, Range >  lhs,
Duration< Rep, Us, Range >  rhs 
)
related

Indicate if the duration lhs is less than or equal to the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is less than or equal to rhs and false otherwise.

Definition at line 457 of file Duration.h.

◆ operator==() [1/2]

bool operator== ( Duration< RepLHS, TBLHS, RangeLHS, FLHS >  lhs,
Duration< RepRHS, TBRHS, RangeRHS, FRHS >  rhs 
)
related

Indicate if the duration lhs is equal to the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is equal to rhs and false otherwise.

Definition at line 474 of file Duration.h.

◆ operator==() [2/2]

bool operator== ( Duration< Rep, Us, Range, F >  lhs,
Duration< Rep, Us, Range, F >  rhs 
)
related

Indicate if the duration lhs is equal to the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is equal to rhs and false otherwise.

Definition at line 491 of file Duration.h.

◆ operator!=() [1/2]

bool operator!= ( Duration< RepLHS, TBLHS, RangeLHS, FLHS >  lhs,
Duration< RepRHS, TBRHS, RangeRHS, FRHS >  rhs 
)
related

Indicate if the duration lhs is not equal to the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is not equal to rhs and false otherwise.

Definition at line 508 of file Duration.h.

◆ operator!=() [2/2]

bool operator!= ( Duration< Rep, Us, Range, F >  lhs,
Duration< Rep, Us, Range, F >  rhs 
)
related

Indicate if the duration lhs is not equal to the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is not equal to rhs and false otherwise.

Definition at line 525 of file Duration.h.

◆ operator>=() [1/2]

bool operator>= ( Duration< RepLHS, TBLHS, RangeLHS, FLHS >  lhs,
Duration< RepRHS, TBRHS, RangeRHS, FRHS >  rhs 
)
related

Indicate if the duration lhs greater or equal to the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is greater or equal to rhs and false otherwise.

Definition at line 542 of file Duration.h.

◆ operator>=() [2/2]

bool operator>= ( Duration< Rep, Us, Range, F >  lhs,
Duration< Rep, Us, Range, F >  rhs 
)
related

Indicate if the duration lhs greater or equal to the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is greater or equal to rhs and false otherwise.

Definition at line 559 of file Duration.h.

◆ operator>() [1/2]

bool operator> ( Duration< RepLHS, TBLHS, RangeLHS, FLHS >  lhs,
Duration< RepRHS, TBRHS, RangeRHS, FRHS >  rhs 
)
related

Indicate if the duration lhs greater than the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is greater than rhs and false otherwise.

Definition at line 576 of file Duration.h.

◆ operator>() [2/2]

bool operator> ( Duration< Rep, Us, Range, F >  lhs,
Duration< Rep, Us, Range, F >  rhs 
)
related

Indicate if the duration lhs greater than the duration rhs.

Parameters
lhsLeft hand side operand.
rhsRight hand side operand.
Returns
true if lhs is greater than rhs and false otherwise.

Definition at line 593 of file Duration.h.

Field Documentation

◆ TIME_BASE

const uint32_t TIME_BASE = TB
static

The time base.

Definition at line 187 of file Duration.h.

◆ MIN

const Rep MIN = Range::MIN
static

Left-bound of the duration range.

Definition at line 192 of file Duration.h.

◆ MAX

const Rep MAX = Range::MAX
static

Right bound of the duration range.

Definition at line 197 of file Duration.h.