iceoryx_doc  1.0.1
Public Types | Public Member Functions | Static Public Attributes | List of all members
iox::concurrent::CyclicIndex< CycleLength, ValueType > Class Template Reference

index structure that can contain logical values 0, ..., CycleLength-1 but also stores an internal cycle counter to be used in compare_exchange More...

#include <cyclic_index.hpp>

Public Types

using value_t = ValueType
 

Public Member Functions

 CyclicIndex (ValueType value=0U) noexcept
 
 CyclicIndex (ValueType index, ValueType cycle) noexcept
 
 CyclicIndex (const CyclicIndex &)=default
 
 CyclicIndex (CyclicIndex &&)=default
 
CyclicIndexoperator= (const CyclicIndex &)=default
 
CyclicIndexoperator= (CyclicIndex &&)=default
 
ValueType getIndex () const noexcept
 
ValueType getCycle () const noexcept
 
ValueType getValue () const noexcept
 
CyclicIndex operator+ (const ValueType value) const noexcept
 
CyclicIndex next () const noexcept
 
bool isOneCycleBehind (const CyclicIndex &other) const noexcept
 
int64_t operator- (const CyclicIndex< CycleLength, ValueType > &rhs) const
 

Static Public Attributes

static constexpr ValueType MAX_INDEX = CycleLength - 1U
 
static constexpr ValueType MAX_VALUE = std::numeric_limits<ValueType>::max()
 
static constexpr ValueType MAX_CYCLE = MAX_VALUE / CycleLength
 
static constexpr ValueType INDEX_AT_MAX_VALUE = MAX_VALUE % CycleLength
 
static constexpr ValueType OVERFLOW_START_INDEX = (INDEX_AT_MAX_VALUE + 1U) % CycleLength
 

Detailed Description

template<uint64_t CycleLength, typename ValueType = uint64_t>
class iox::concurrent::CyclicIndex< CycleLength, ValueType >

index structure that can contain logical values 0, ..., CycleLength-1 but also stores an internal cycle counter to be used in compare_exchange

Member Function Documentation

◆ operator-()

template<uint64_t CycleLength, typename ValueType >
int64_t iox::concurrent::CyclicIndex< CycleLength, ValueType >::operator- ( const CyclicIndex< CycleLength, ValueType > &  rhs) const
Note
The difference will be negative if lhs < rhs (lhs is this) and its absolute value fits into an int64_t, otherwise it will be positive and follow the rules of modular arithmetic of unsigned types This is intended and includes the case were rhs is "very close to 0" and and lhs is "close" to the MAX of uint64_t (MAX=2^64-1). Here close means that the real absolute difference would be larger than 2^63. This is excactly the right behaviour to deal with a (theoretically possible) overflow of lhs and can be seen as lhs being interpreted as MAX + its actual value. In this case, lhs - rhs is positive even though lhs < rhs.

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