iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
iox2::bb::Slice< T > Class Template Reference

A class representing a slice of contiguous elements of type T. More...

#include <slice.hpp>

Public Types

using Iterator = T *
 
using ConstIterator = const T *
 
using ValueType = std::remove_const_t< T >
 

Public Member Functions

 Slice (T *data, uint64_t number_of_elements)
 Constructs a Slice object.
 
auto number_of_bytes () const -> uint64_t
 Returns the total number of bytes occupied by the slice.
 
auto number_of_elements () const -> uint64_t
 Returns the number of elements in the slice.
 
auto operator[] (uint64_t n) const -> const ValueType &
 Accesses the element at the specified index (const version).
 
auto operator[] (uint64_t n) -> std::conditional_t< std::is_const< T >::value, const ValueType &, ValueType & >
 Accesses the element at the specified index (non-const version).
 
auto begin () const -> ConstIterator
 Returns an iterator to the beginning of the slice (const version).
 
auto begin () -> Iterator
 Returns an iterator to the beginning of the slice (non-const version).
 
auto end () const -> ConstIterator
 Returns an iterator to the end of the slice (const version).
 
auto end () -> Iterator
 Returns an iterator to the end of the slice (non-const version).
 
auto data () const -> ConstIterator
 Returns a pointer to the underlying data of the slice (const version).
 
auto data () -> Iterator
 Returns a pointer to the underlying data of the slice (non-const version).
 

Detailed Description

template<typename T>
class iox2::bb::Slice< T >

A class representing a slice of contiguous elements of type T.

A Slice provides a view into a contiguous sequence of elements without owning the memory. It allows for efficient access and iteration over a portion of a contiguous data structure.

Template Parameters
TThe type of elements in the slice. Can be const-qualified for read-only slices.

Definition at line 31 of file slice.hpp.

Member Typedef Documentation

◆ ConstIterator

template<typename T >
using iox2::bb::Slice< T >::ConstIterator = const T*

Definition at line 34 of file slice.hpp.

◆ Iterator

template<typename T >
using iox2::bb::Slice< T >::Iterator = T*

Definition at line 33 of file slice.hpp.

◆ ValueType

template<typename T >
using iox2::bb::Slice< T >::ValueType = std::remove_const_t<T>

Definition at line 35 of file slice.hpp.

Constructor & Destructor Documentation

◆ Slice()

template<typename T >
iox2::bb::Slice< T >::Slice ( T *  data,
uint64_t  number_of_elements 
)

Constructs a Slice object.

Parameters
[in]dataPointer to the beginning of the data.
[in]number_of_elementsThe number of elements in the slice.

Definition at line 98 of file slice.hpp.

References iox2::bb::Slice< T >::data().

Member Function Documentation

◆ begin() [1/2]

template<typename T >
auto iox2::bb::Slice< T >::begin ( ) -> Iterator

Returns an iterator to the beginning of the slice (non-const version).

Returns
An iterator pointing to the first element of the slice.

Definition at line 128 of file slice.hpp.

◆ begin() [2/2]

template<typename T >
auto iox2::bb::Slice< T >::begin ( ) const -> ConstIterator

Returns an iterator to the beginning of the slice (const version).

Returns
An iterator pointing to the first element of the slice.

Definition at line 133 of file slice.hpp.

◆ data() [1/2]

template<typename T >
auto iox2::bb::Slice< T >::data ( ) -> Iterator

Returns a pointer to the underlying data of the slice (non-const version).

Returns
A pointer to the first element of the slice.

Definition at line 148 of file slice.hpp.

◆ data() [2/2]

template<typename T >
auto iox2::bb::Slice< T >::data ( ) const -> ConstIterator

Returns a pointer to the underlying data of the slice (const version).

Returns
A pointer to the first element of the slice.

Definition at line 153 of file slice.hpp.

Referenced by iox2::bb::Slice< T >::Slice().

◆ end() [1/2]

template<typename T >
auto iox2::bb::Slice< T >::end ( ) -> Iterator

Returns an iterator to the end of the slice (non-const version).

Returns
An iterator pointing one past the last element of the slice.

Definition at line 138 of file slice.hpp.

◆ end() [2/2]

template<typename T >
auto iox2::bb::Slice< T >::end ( ) const -> ConstIterator

Returns an iterator to the end of the slice (const version).

Returns
An iterator pointing one past the last element of the slice.

Definition at line 143 of file slice.hpp.

◆ number_of_bytes()

template<typename T >
auto iox2::bb::Slice< T >::number_of_bytes ( ) const -> uint64_t

Returns the total number of bytes occupied by the slice.

Returns
The number of bytes occupied by the slice, rounded up to the nearest alignment boundary.

Definition at line 105 of file slice.hpp.

◆ number_of_elements()

template<typename T >
auto iox2::bb::Slice< T >::number_of_elements ( ) const -> uint64_t

Returns the number of elements in the slice.

Returns
The number of elements in the slice.

Definition at line 110 of file slice.hpp.

◆ operator[]() [1/2]

template<typename T >
auto iox2::bb::Slice< T >::operator[] ( uint64_t  n) -> std::conditional_t<std::is_const<T>::value, const ValueType&, ValueType&>

Accesses the element at the specified index (non-const version).

Parameters
[in]nThe index of the element to access.
Returns
A reference to the element at the specified index.
Precondition
The index must be less than the number of elements in the slice.

Definition at line 121 of file slice.hpp.

References IOX2_ASSERT.

◆ operator[]() [2/2]

template<typename T >
auto iox2::bb::Slice< T >::operator[] ( uint64_t  n) const -> const ValueType&

Accesses the element at the specified index (const version).

Parameters
[in]nThe index of the element to access.
Returns
A const reference to the element at the specified index.
Precondition
The index must be less than the number of elements in the slice.

Definition at line 115 of file slice.hpp.

References IOX2_ASSERT.


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