17 #ifndef IOX_UTILS_LOCKFREE_QUEUE_CYCLIC_INDEX_HPP
18 #define IOX_UTILS_LOCKFREE_QUEUE_CYCLIC_INDEX_HPP
22 #include <type_traits>
31 template <u
int64_t CycleLength,
typename ValueType = u
int64_t>
35 static_assert(std::is_unsigned<ValueType>::value,
"ValueType must be an unsigned integral type");
36 static_assert(CycleLength >= 1U,
"CycleLength must be >= 1");
38 using value_t = ValueType;
40 static constexpr ValueType MAX_INDEX = CycleLength - 1U;
41 static constexpr ValueType MAX_VALUE = std::numeric_limits<ValueType>::max();
44 static constexpr ValueType MAX_CYCLE = MAX_VALUE / CycleLength;
46 static constexpr ValueType INDEX_AT_MAX_VALUE = MAX_VALUE % CycleLength;
47 static constexpr ValueType OVERFLOW_START_INDEX = (INDEX_AT_MAX_VALUE + 1U) % CycleLength;
49 static_assert(CycleLength < MAX_VALUE / 2U,
"CycleLength is too large, need at least one bit for cycle");
50 static_assert(CycleLength > 0,
"CycleLength must be > 0");
52 explicit CyclicIndex(ValueType value = 0U) noexcept;
54 CyclicIndex(ValueType index, ValueType cycle) noexcept;
61 ValueType getIndex()
const noexcept;
63 ValueType getCycle()
const noexcept;
65 ValueType getValue()
const noexcept;
67 CyclicIndex operator+(
const ValueType value)
const noexcept;
71 bool isOneCycleBehind(
const CyclicIndex& other)
const noexcept;
85 ValueType m_value{0U};
91 #include "cyclic_index.inl"
index structure that can contain logical values 0, ..., CycleLength-1 but also stores an internal cyc...
Definition: cyclic_index.hpp:33
int64_t operator-(const CyclicIndex< CycleLength, ValueType > &rhs) const
Definition: cyclic_index.inl:94
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28