SuperTinyKernel™ RTOS 1.08.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>

Collaboration diagram for stk::ArrayView< T >:

Public Types

typedef T value_type

Public Member Functions

 ArrayView ()
 Construct an empty ArrayView with a null pointer and zero size.
 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.
T * GetPtr ()
 Get pointer to the beginning of elements in the view.
const T * GetPtr () const
 Get constant pointer to the beginning of elements in the view.
size_t GetSize () const
 Get number of elements in the view.

Private Member Functions

T & UncheckedAt (size_t index) const
 Deviation MISRA-CPP-2008-5-0-15 \reason Array indexing on a base pointer is required for a dynamic-size non-owning view. The pointer and size are externally supplied. Bounds are enforced by the public API (STK_ASSERT / operator[]).

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
Provides a safe encapsulation over raw pointers without copying the underlying data. Includes binary serialization methods for compact state transfer on 32-bit platforms.

Usage example:

stk::ITask *tasks[TASKS_MAX];
ArrayView<stk::ITask *> view(tasks, TASKS_MAX);
ArrayView()
Construct an empty ArrayView with a null pointer and zero size.
Definition stk_common.h:329
Interface for a user task.
Definition stk_common.h:886

Definition at line 322 of file stk_common.h.

Member Typedef Documentation

◆ value_type

template<typename T>
typedef T stk::ArrayView< T >::value_type

Definition at line 325 of file stk_common.h.

Constructor & Destructor Documentation

◆ ArrayView() [1/2]

template<typename T>
stk::ArrayView< T >::ArrayView ( )
inline

Construct an empty ArrayView with a null pointer and zero size.

Definition at line 329 of file stk_common.h.

329 : m_ptr(nullptr), m_size(0U)
330 {}
Lightweight, non-owning view over a contiguous sequence of elements.
Definition stk_common.h:323
T * m_ptr
Pointer to the underlying memory block.
Definition stk_common.h:376
size_t m_size
Total number of elements in the view.
Definition stk_common.h:377

References m_ptr, and m_size.

◆ ArrayView() [2/2]

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 336 of file stk_common.h.

336 : m_ptr(ptr), m_size(size)
337 {}

References m_ptr, and m_size.

Member Function Documentation

◆ GetPtr() [1/2]

template<typename T>
T * stk::ArrayView< T >::GetPtr ( )
inline

Get pointer to the beginning of elements in the view.

Returns
Pointer to the elements of array.

Definition at line 353 of file stk_common.h.

353{ return m_ptr; }

References m_ptr.

◆ GetPtr() [2/2]

template<typename T>
const T * stk::ArrayView< T >::GetPtr ( ) const
inline

Get constant pointer to the beginning of elements in the view.

Returns
Constant pointer to the elements of array.

Definition at line 358 of file stk_common.h.

358{ return m_ptr; }

References m_ptr.

◆ GetSize()

template<typename T>
size_t stk::ArrayView< T >::GetSize ( ) const
inline

Get number of elements in the view.

Returns
The size of the array view.

Definition at line 363 of file stk_common.h.

363{ return m_size; }

References m_size.

Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::EnumerateKernelTasks(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::EnumerateTasks(), stk::IStackMemory::GetStackSpace(), and stk::PlatformContext::InitStackMemory().

Here is the caller graph for this function:

◆ operator[]()

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

Subscript operator for element access.

Parameters
[in]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 344 of file stk_common.h.

345 {
346 STK_ASSERT(index < m_size); // enforces MISRA Rule 5-0-16
347 return UncheckedAt(index); // MISRA Rule 5-0-15 deviation centralized
348 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:532
T & UncheckedAt(size_t index) const
Deviation MISRA-CPP-2008-5-0-15 \reason Array indexing on a base pointer is required for a dynamic-si...
Definition stk_common.h:371

References m_size, STK_ASSERT, and UncheckedAt().

Here is the call graph for this function:

◆ UncheckedAt()

template<typename T>
T & stk::ArrayView< T >::UncheckedAt ( size_t index) const
inlineprivate

Deviation MISRA-CPP-2008-5-0-15 \reason Array indexing on a base pointer is required for a dynamic-size non-owning view. The pointer and size are externally supplied. Bounds are enforced by the public API (STK_ASSERT / operator[]).

Definition at line 371 of file stk_common.h.

372 {
373 return m_ptr[index]; // deviation: indexing non-array pointer
374 }

References __stk_forceinline, and m_ptr.

Referenced by operator[]().

Here is the caller graph for this function:

Member Data Documentation

◆ m_ptr

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

Pointer to the underlying memory block.

Definition at line 376 of file stk_common.h.

Referenced by ArrayView(), ArrayView(), GetPtr(), GetPtr(), and UncheckedAt().

◆ m_size

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

Total number of elements in the view.

Definition at line 377 of file stk_common.h.

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


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