SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::ArrayView< T > Class Template Reference

Lightweight, non-owning view over a contiguous sequence of elements. More...

#include <stk_common.h>

Public Member Functions

 ArrayView (T *ptr, size_t size)
 Construct an ArrayView from a raw pointer and size.
T & operator[] (size_t index) const
 Subscript operator for element access.
size_t GetSize () const
 Get number of elements in the view.

Private Attributes

T * m_ptr
 Pointer to the underlying memory block.
size_t m_size
 Total number of elements in the view.

Detailed Description

template<typename T>
class stk::ArrayView< T >

Lightweight, non-owning view over a contiguous sequence of elements.

Note
This descriptor provides a safe encapsulation over raw pointers without copying the underlying data.

Usage example:

stk::ITask *tasks[TASKS_MAX];
ArrayView<stk::ITask *> view(tasks, TASKS_MAX);
ArrayView(T *ptr, size_t size)
Construct an ArrayView from a raw pointer and size.
Definition stk_common.h:253
Interface for a user task.
Definition stk_common.h:670

Definition at line 246 of file stk_common.h.

Constructor & Destructor Documentation

◆ ArrayView()

template<typename T>
stk::ArrayView< T >::ArrayView ( T * ptr,
size_t size )
inline

Construct an ArrayView from a raw pointer and size.

Parameters
[in]ptrPointer to the first element of the contiguous memory block.
[in]sizeNumber of elements available in the memory block.

Definition at line 253 of file stk_common.h.

253 : m_ptr(ptr), m_size(size)
254 {}
Lightweight, non-owning view over a contiguous sequence of elements.
Definition stk_common.h:247
T * m_ptr
Pointer to the underlying memory block.
Definition stk_common.h:274
size_t m_size
Total number of elements in the view.
Definition stk_common.h:275

References m_ptr, and m_size.

Member Function Documentation

◆ GetSize()

◆ operator[]()

template<typename T>
T & stk::ArrayView< T >::operator[] ( size_t index) const
inline

Subscript operator for element access.

Parameters
indexElement index to access.
Returns
Reference to the element at the specified index.
Warning
Triggers STK_ASSERT if index is out of bounds in a Debug build.

Definition at line 261 of file stk_common.h.

262 {
264 //MISRA 5-0-15 deviation: bounds are checked via STK_ASSERT
265 return m_ptr[index];
266 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:409

References m_ptr, m_size, and STK_ASSERT.

Member Data Documentation

◆ m_ptr

template<typename T>
T* stk::ArrayView< T >::m_ptr
private

Pointer to the underlying memory block.

Definition at line 274 of file stk_common.h.

Referenced by ArrayView(), and operator[]().

◆ m_size

template<typename T>
size_t stk::ArrayView< T >::m_size
private

Total number of elements in the view.

Definition at line 275 of file stk_common.h.

Referenced by ArrayView(), GetSize(), and operator[]().


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