LdsGen 1.2.6
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Friends | List of all members
ldsgen::GeneratorBase< Derived, Value > Class Template Reference

CRTP base implementing the sequence generator protocol. More...

#include <lds.hpp>

Inheritance diagram for ldsgen::GeneratorBase< Derived, Value >:
[legend]

Public Member Functions

auto pop () -> Value
 Generate the next value in the sequence (advances state).
 
auto peek () -> Value
 Peek at the next value without advancing state.
 
auto skip (unsigned int n) -> void
 Skip n values in the sequence.
 
auto reseed (const unsigned long &seed) -> void
 Reset the generator to a specific seed value.
 
auto get_index () const -> unsigned long
 Get current index in the sequence.
 

Protected Attributes

std::atomic< unsigned long > count_ {0}
 Current sequence index (single source of state)
 

Friends

template<typename , typename >
class GeneratorIterable
 

Detailed Description

template<typename Derived, typename Value>
class ldsgen::GeneratorBase< Derived, Value >

CRTP base implementing the sequence generator protocol.

Implements the shared stateful protocol (pop/peek/skip/reseed/get_index) in terms of a single pure computation value_at(n) supplied by the derived class. The sequence counter is a std::atomic<unsigned long> so the protocol stays thread-safe: pop() claims a unique index with a relaxed fetch_add and evaluates value_at on immutable generator data.

Note
Template Method pattern via CRTP: the base fixes the protocol skeleton — pop() evaluates value_at(fetch_add(1) + 1) and peek() evaluates value_at(load() + 1) — while the derived class supplies only the pure index-to-value computation. This guarantees pop/peek consistency by construction, centralizes the sequence state in one atomic counter (making composite pop() atomic as a point), and removes the duplicated protocol from every concrete generator.
Template Parameters
DerivedThe CRTP-derived generator class.
ValueThe value type produced by pop()/peek().

Member Function Documentation

◆ get_index()

template<typename Derived , typename Value >
auto ldsgen::GeneratorBase< Derived, Value >::get_index ( ) const -> unsigned long
inline

Get current index in the sequence.

Returns
unsigned long current index in the sequence

◆ peek()

template<typename Derived , typename Value >
auto ldsgen::GeneratorBase< Derived, Value >::peek ( ) -> Value
inline

Peek at the next value without advancing state.

Returns
The value at the next sequence index.

◆ pop()

template<typename Derived , typename Value >
auto ldsgen::GeneratorBase< Derived, Value >::pop ( ) -> Value
inline

Generate the next value in the sequence (advances state).

Atomically claims the next index and evaluates the pure value_at computation.

Returns
The value at the incremented sequence index.

◆ reseed()

template<typename Derived , typename Value >
auto ldsgen::GeneratorBase< Derived, Value >::reseed ( const unsigned long &  seed) -> void
inline

Reset the generator to a specific seed value.

Parameters
[in]seedthe seed value to reset the sequence generator to

◆ skip()

template<typename Derived , typename Value >
auto ldsgen::GeneratorBase< Derived, Value >::skip ( unsigned int  n) -> void
inline

Skip n values in the sequence.

Parameters
[in]nnumber of values to skip

Friends And Related Symbol Documentation

◆ GeneratorIterable

template<typename Derived , typename Value >
template<typename , typename >
friend class GeneratorIterable
friend

Member Data Documentation

◆ count_

template<typename Derived , typename Value >
std::atomic<unsigned long> ldsgen::GeneratorBase< Derived, Value >::count_ {0}
protected

Current sequence index (single source of state)


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