RAVENNAKIT
Loading...
Searching...
No Matches
rav::WrappingUint< T > Class Template Reference

Represents sequence numbers with rollover (wraparound) semantics. More...

#include <wrapping_uint.hpp>

Public Member Functions

 WrappingUint ()=default
 Default construct a sequence number with the value 0.
 WrappingUint (const T value)
 Construct a sequence number with the given value.
std::optional< T > update (const T value)
 Updates the value in the sequence.
 operator T () const
T value () const
WrappingUint & operator= (const T value)
 Assigns a new value to the sequence number.
WrappingUint & operator+= (const T value)
 Increments the sequence number by 1 using modulo arithmetic.
WrappingUint & operator-= (const T value)
 Decrements the sequence number by 1 using modulo arithmetic.
WrappingUint operator+ (const T value) const
 Increments the sequence number by the given value.
WrappingUint operator- (const T value) const
 Decrements the sequence number by the given value.
bool operator== (T other)
 Compares the sequence number with the given value.
bool operator!= (T other)
 Compares the sequence number with the given value.
std::make_signed_t< T > diff (const WrappingUint &other) const
 Calculates the difference between two sequence numbers, taking into account wraparound.
std::make_signed_t< T > diff (T other) const
 Calculates the difference between two sequence numbers, taking into account wraparound.

Friends

bool operator== (const WrappingUint &lhs, const WrappingUint &rhs)
 Compares the sequence number with the given value.
bool operator!= (const WrappingUint &lhs, const WrappingUint &rhs)
 Compares the sequence number with the given value.
bool operator< (const WrappingUint &lhs, const WrappingUint &rhs)
 Compares the sequence number with the given value.
bool operator<= (const WrappingUint &lhs, const WrappingUint &rhs)
 Compares the sequence number with the given value.
bool operator> (const WrappingUint &lhs, const WrappingUint &rhs)
 Compares the sequence number with the given value.
bool operator>= (const WrappingUint &lhs, const WrappingUint &rhs)
 Compares the sequence number with the given value.

Detailed Description

template<class T>
class rav::WrappingUint< T >

Represents sequence numbers with rollover (wraparound) semantics.

This class is designed to work with any unsigned integer type that wraps around to 0 after reaching its maximum value. It also supports handling gaps, making it suitable for scenarios involving packet loss. Use this class for the sequence id in PTP, sequence number in RTP, timestamp in RTP, etc.

Definition at line 41 of file wrapping_uint.hpp.

Constructor & Destructor Documentation

◆ WrappingUint() [1/2]

template<class T>
rav::WrappingUint< T >::WrappingUint ( )
default

Default construct a sequence number with the value 0.

◆ WrappingUint() [2/2]

template<class T>
rav::WrappingUint< T >::WrappingUint ( const T value)
inlineexplicit

Construct a sequence number with the given value.

Parameters
valueThe initial value of the sequence number.

Definition at line 55 of file wrapping_uint.hpp.

Member Function Documentation

◆ diff() [1/2]

template<class T>
std::make_signed_t< T > rav::WrappingUint< T >::diff ( const WrappingUint< T > & other) const
inlinenodiscard

Calculates the difference between two sequence numbers, taking into account wraparound.

The value will be positive if the other sequence number is newer than this one, and negative if this one is newer.

Parameters
otherThe other sequence number.
Returns
The difference between the two sequence numbers.

Definition at line 224 of file wrapping_uint.hpp.

◆ diff() [2/2]

template<class T>
std::make_signed_t< T > rav::WrappingUint< T >::diff ( T other) const
inlinenodiscard

Calculates the difference between two sequence numbers, taking into account wraparound.

The value will be positive if the other sequence number is newer than this one, and negative if this one is newer.

Parameters
otherThe other sequence number.
Returns
The difference between the two sequence numbers.

Definition at line 235 of file wrapping_uint.hpp.

◆ operator T()

template<class T>
rav::WrappingUint< T >::operator T ( ) const
inlineexplicitnodiscard
Returns
The value of the sequence number.

Definition at line 80 of file wrapping_uint.hpp.

◆ operator!=()

template<class T>
bool rav::WrappingUint< T >::operator!= ( T other)
inlinenodiscard

Compares the sequence number with the given value.

Parameters
otherThe value to compare with.
Returns
True if the sequence number is not equal to the given value, false otherwise.

Definition at line 153 of file wrapping_uint.hpp.

◆ operator+()

template<class T>
WrappingUint rav::WrappingUint< T >::operator+ ( const T value) const
inlinenodiscard

Increments the sequence number by the given value.

Parameters
valueThe value to increment by.
Returns
A new sequence number instance.

Definition at line 126 of file wrapping_uint.hpp.

◆ operator+=()

template<class T>
WrappingUint & rav::WrappingUint< T >::operator+= ( const T value)
inline

Increments the sequence number by 1 using modulo arithmetic.

Parameters
valueThe value to increment by.
Returns
This instance.

Definition at line 106 of file wrapping_uint.hpp.

◆ operator-()

template<class T>
WrappingUint rav::WrappingUint< T >::operator- ( const T value) const
inlinenodiscard

Decrements the sequence number by the given value.

Parameters
valueThe value to decrement by.
Returns
A new sequence number instance.

Definition at line 135 of file wrapping_uint.hpp.

◆ operator-=()

template<class T>
WrappingUint & rav::WrappingUint< T >::operator-= ( const T value)
inline

Decrements the sequence number by 1 using modulo arithmetic.

Parameters
valueThe value to decrement by.
Returns
This instance.

Definition at line 116 of file wrapping_uint.hpp.

◆ operator=()

template<class T>
WrappingUint & rav::WrappingUint< T >::operator= ( const T value)
inline

Assigns a new value to the sequence number.

Parameters
valueThe new value of the sequence number.
Returns
This instance.

Definition at line 96 of file wrapping_uint.hpp.

◆ operator==()

template<class T>
bool rav::WrappingUint< T >::operator== ( T other)
inlinenodiscard

Compares the sequence number with the given value.

Parameters
otherThe value to compare with.
Returns
True if the sequence number is equal to the given value, false otherwise.

Definition at line 144 of file wrapping_uint.hpp.

◆ update()

template<class T>
std::optional< T > rav::WrappingUint< T >::update ( const T value)
inline

Updates the value in the sequence.

The number of steps taken from the previous value to given value will be returned, taking into account wraparound. The current (internal) value will only progress forward, if the value is older than the current value, it will return std::nullopt. The returned value can be used to detect gaps (when value > 1).

Parameters
valueThe value to set.
Returns
The difference between the given value and the current value, taking into account wraparound. If the value is older than the current value, std::nullopt will be returned.

Definition at line 67 of file wrapping_uint.hpp.

◆ value()

template<class T>
T rav::WrappingUint< T >::value ( ) const
inlinenodiscard
Returns
The value of the sequence number.

Definition at line 87 of file wrapping_uint.hpp.

◆ operator!=

template<class T>
bool operator!= ( const WrappingUint< T > & lhs,
const WrappingUint< T > & rhs )
friend

Compares the sequence number with the given value.

Parameters
lhsLeft hand side.
rhsRight hand side.
Returns
True if the sequence number is not equal to the given value, false otherwise.

Definition at line 173 of file wrapping_uint.hpp.

◆ operator<

template<class T>
bool operator< ( const WrappingUint< T > & lhs,
const WrappingUint< T > & rhs )
friend

Compares the sequence number with the given value.

Parameters
lhsLeft hand side.
rhsRight hand side.
Returns
True if the sequence number is less than the given value, false otherwise.

Definition at line 183 of file wrapping_uint.hpp.

◆ operator<=

template<class T>
bool operator<= ( const WrappingUint< T > & lhs,
const WrappingUint< T > & rhs )
friend

Compares the sequence number with the given value.

Parameters
lhsLeft hand side.
rhsRight hand side.
Returns
True if the sequence number is less than or equal to the given value, false otherwise.

Definition at line 193 of file wrapping_uint.hpp.

◆ operator==

template<class T>
bool operator== ( const WrappingUint< T > & lhs,
const WrappingUint< T > & rhs )
friend

Compares the sequence number with the given value.

Parameters
lhsLeft hand side.
rhsRight hand side.
Returns
True if the sequence number is less than the given value, false otherwise.

Definition at line 163 of file wrapping_uint.hpp.

◆ operator>

template<class T>
bool operator> ( const WrappingUint< T > & lhs,
const WrappingUint< T > & rhs )
friend

Compares the sequence number with the given value.

Parameters
lhsLeft hand side.
rhsRight hand side.
Returns
True if the sequence number is greater than the given value, false otherwise.

Definition at line 203 of file wrapping_uint.hpp.

◆ operator>=

template<class T>
bool operator>= ( const WrappingUint< T > & lhs,
const WrappingUint< T > & rhs )
friend

Compares the sequence number with the given value.

Parameters
lhsLeft hand side.
rhsRight hand side.
Returns
True if the sequence number is greater than or equal to the given value, false otherwise.

Definition at line 213 of file wrapping_uint.hpp.


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