Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Array_Iterator< T > Class Template Reference

Iterator wrapper for C++ raw arrays. More...

#include <array_it.H>

Inheritance diagram for Aleph::Array_Iterator< T >:
[legend]

Public Types

using Item_Type = T
 The type of elements being iterated.
 

Public Member Functions

Tget_base () noexcept
 Get the base pointer of the array.
 
constexpr const Tget_base () const noexcept
 Get the base pointer of the array (const version).
 
 Array_Iterator ()=default
 Default constructor - creates an invalid iterator.
 
 Array_Iterator (T *p, const size_t sz, const size_t n)
 Construct an iterator over an array.
 
 Array_Iterator (NoExceptionCtor, T *p, const size_t sz, const size_t n)
 Construct an iterator without exception checking.
 
 Array_Iterator (T *p, const size_t sz, const size_t n, const long f, const long l)
 Construct an iterator over a circular array region.
 
 Array_Iterator (NoExceptionCtor, T *p, const size_t sz, const size_t n, const long f, const long l)
 Construct a circular iterator without exception checking.
 
 Array_Iterator (const Array_Container< T > &c)
 Construct an iterator from an Array_Container.
 
bool has_curr () const noexcept
 Check if there is a current valid item.
 
bool is_last () const noexcept
 Check if positioned at the last item.
 
constexpr long get_pos () const noexcept
 Get the current position index.
 
Tget_curr_ne () const noexcept
 Get the current item without bounds checking.
 
Tget_curr () const
 Get the current item with bounds checking.
 
void next_ne () noexcept
 Advance to the next item without bounds checking.
 
void next ()
 Advance to the next item with bounds checking.
 
void prev_ne () noexcept
 Move to the previous item without bounds checking.
 
void prev ()
 Move to the previous item with bounds checking.
 
void reset () noexcept
 Reset the iterator to the first item.
 
void reset_first () noexcept
 Reset the iterator to the first item (alias for reset()).
 
void reset_last () noexcept
 Reset the iterator to the last item.
 
void end () noexcept
 Put the iterator at the end (past the last item).
 

Private Attributes

Tptr = nullptr
 
long dim = 0
 
long num_items = 0
 
long idx = 0
 
long first = 0
 
long last = 0
 
long pos = 0
 

Detailed Description

template<class T>
class Aleph::Array_Iterator< T >

Iterator wrapper for C++ raw arrays.

Provides a full iterator interface for raw C arrays, including support for circular buffers where the logical sequence wraps around the physical array boundaries.

The iterator supports:

  • Forward and backward traversal
  • Bounds checking with exception throwing (or no-exception variants)
  • Circular array regions with arbitrary first/last indices
  • Position tracking
Template Parameters
TElement type.

Definition at line 76 of file array_it.H.

Member Typedef Documentation

◆ Item_Type

template<class T >
using Aleph::Array_Iterator< T >::Item_Type = T

The type of elements being iterated.

Definition at line 114 of file array_it.H.

Constructor & Destructor Documentation

◆ Array_Iterator() [1/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( )
default

Default constructor - creates an invalid iterator.

◆ Array_Iterator() [2/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( T p,
const size_t  sz,
const size_t  n 
)
inline

Construct an iterator over an array.

Creates an iterator for elements [0, n) in an array of size sz.

Parameters
pPointer to the array.
szPhysical size of the array.
nNumber of valid items (logical size).
Exceptions
std::invalid_argumentif p is null but sz > 0.
std::domain_errorif n > sz.

Definition at line 140 of file array_it.H.

References Aleph::maps(), and Aleph::Array_Iterator< T >::ptr.

◆ Array_Iterator() [3/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( NoExceptionCtor  ,
T p,
const size_t  sz,
const size_t  n 
)
inline

Construct an iterator without exception checking.

Same as the regular constructor but performs assertions instead of throwing exceptions. Use only when you are certain the parameters are valid.

Parameters
pPointer to the array.
szPhysical size of the array.
nNumber of valid items.

Definition at line 157 of file array_it.H.

References Aleph::Array_Iterator< T >::dim, Aleph::maps(), Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::ptr.

◆ Array_Iterator() [4/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( T p,
const size_t  sz,
const size_t  n,
const long  f,
const long  l 
)
inline

Construct an iterator over a circular array region.

Creates an iterator for a circular array where the logical sequence starts at index f and ends at index l, possibly wrapping around the array boundaries.

Parameters
pPointer to the array.
szPhysical size of the array.
nNumber of valid items.
fFirst index (starting position).
lLast index (ending position).
Exceptions
std::invalid_argumentif p is null but sz > 0.
std::domain_errorif parameters are inconsistent.

Definition at line 179 of file array_it.H.

References ah_domain_error_if, Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::first, Aleph::Array_Iterator< T >::last, Aleph::maps(), Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::ptr.

◆ Array_Iterator() [5/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( NoExceptionCtor  ,
T p,
const size_t  sz,
const size_t  n,
const long  f,
const long  l 
)
inline

Construct a circular iterator without exception checking.

Parameters
pPointer to the array.
szPhysical size of the array.
nNumber of valid items.
fFirst index.
lLast index.

Definition at line 201 of file array_it.H.

References Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::first, Aleph::Array_Iterator< T >::last, Aleph::maps(), Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::ptr.

◆ Array_Iterator() [6/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( const Array_Container< T > &  c)
inline

Construct an iterator from an Array_Container.

Parameters
cContainer to iterate over.

Definition at line 213 of file array_it.H.

Member Function Documentation

◆ end()

template<class T >
void Aleph::Array_Iterator< T >::end ( )
inlinenoexcept

Put the iterator at the end (past the last item).

Definition at line 314 of file array_it.H.

References put_itor_at_the_end().

◆ get_base() [1/2]

template<class T >
constexpr const T * Aleph::Array_Iterator< T >::get_base ( ) const
inlineconstexprnoexcept

Get the base pointer of the array (const version).

Returns
Const pointer to the underlying array.

Definition at line 124 of file array_it.H.

References Aleph::Array_Iterator< T >::ptr.

◆ get_base() [2/2]

template<class T >
T * Aleph::Array_Iterator< T >::get_base ( )
inlinenoexcept

Get the base pointer of the array.

Returns
Pointer to the underlying array.

Definition at line 119 of file array_it.H.

References Aleph::Array_Iterator< T >::ptr.

◆ get_curr()

template<class T >
T & Aleph::Array_Iterator< T >::get_curr ( ) const
inline

Get the current item with bounds checking.

Returns
Reference to the current item.
Exceptions
std::underflow_errorif positioned before the first item.
std::overflow_errorif positioned past the last item.

Definition at line 245 of file array_it.H.

References ah_overflow_error_if, ah_underflow_error_if, Aleph::Array_Iterator< T >::idx, Aleph::Array_Iterator< T >::num_items, Aleph::Array_Iterator< T >::pos, and Aleph::Array_Iterator< T >::ptr.

Referenced by TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ get_curr_ne()

template<class T >
T & Aleph::Array_Iterator< T >::get_curr_ne ( ) const
inlinenoexcept

Get the current item without bounds checking.

Returns
Reference to the current item.
Warning
Does not check bounds - use only when you know the iterator is valid.

Definition at line 235 of file array_it.H.

References Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::ptr.

◆ get_pos()

template<class T >
constexpr long Aleph::Array_Iterator< T >::get_pos ( ) const
inlineconstexprnoexcept

Get the current position index.

Returns
Logical position (0 to num_items-1).

Definition at line 229 of file array_it.H.

References Aleph::Array_Iterator< T >::pos.

◆ has_curr()

◆ is_last()

template<class T >
bool Aleph::Array_Iterator< T >::is_last ( ) const
inlinenoexcept

Check if positioned at the last item.

Returns
true if at the last item.

Definition at line 224 of file array_it.H.

References Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::pos.

◆ next()

template<class T >
void Aleph::Array_Iterator< T >::next ( )
inline

Advance to the next item with bounds checking.

Exceptions
std::overflow_errorif already at or past the end.

Definition at line 269 of file array_it.H.

References ah_overflow_error_if, Aleph::maps(), Aleph::Array_Iterator< T >::next_ne(), Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::pos.

Referenced by TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ next_ne()

template<class T >
void Aleph::Array_Iterator< T >::next_ne ( )
inlinenoexcept

Advance to the next item without bounds checking.

Warning
Does not check bounds.

Definition at line 259 of file array_it.H.

References Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::pos.

Referenced by Aleph::Array_Iterator< T >::next().

◆ prev()

template<class T >
void Aleph::Array_Iterator< T >::prev ( )
inline

Move to the previous item with bounds checking.

Exceptions
std::underflow_errorif already at or before the beginning.

Definition at line 289 of file array_it.H.

References ah_underflow_error_if, Aleph::maps(), Aleph::Array_Iterator< T >::num_items, Aleph::Array_Iterator< T >::pos, and Aleph::Array_Iterator< T >::prev_ne().

Referenced by TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ prev_ne()

template<class T >
void Aleph::Array_Iterator< T >::prev_ne ( )
inlinenoexcept

Move to the previous item without bounds checking.

Warning
Does not check bounds.

Definition at line 279 of file array_it.H.

References Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::pos.

Referenced by Aleph::Array_Iterator< T >::prev().

◆ reset()

template<class T >
void Aleph::Array_Iterator< T >::reset ( )
inlinenoexcept

Reset the iterator to the first item.

Definition at line 297 of file array_it.H.

References Aleph::Array_Iterator< T >::first, Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::pos.

Referenced by Aleph::Array_Iterator< T >::reset_first(), TEST(), TEST(), and TEST_F().

◆ reset_first()

template<class T >
void Aleph::Array_Iterator< T >::reset_first ( )
inlinenoexcept

Reset the iterator to the first item (alias for reset()).

Definition at line 304 of file array_it.H.

References Aleph::Array_Iterator< T >::reset().

Referenced by TEST_F().

◆ reset_last()

template<class T >
void Aleph::Array_Iterator< T >::reset_last ( )
inlinenoexcept

Member Data Documentation

◆ dim

◆ first

◆ idx

◆ last

◆ num_items

◆ pos

◆ ptr


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