Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
GroupAggregator< SRC, AGG, GRP > Class Template Reference

#include "lib/iter-explorer.hpp"

Description

template<class SRC, typename AGG, class GRP>
class lib::iter_explorer::GroupAggregator< SRC, AGG, GRP >

Decorator for IterExplorer to group consecutive elements controlled by some grouping value GRP and compute an aggregate value AGG for each such group as iterator yield. The first group is consumed eagerly, each further group on iteration; thus when the aggregate for the last group appears as result, the source iterator has already been exhausted. The aggregate is default-initialised at start of each group and then the computation functor FAGG is invoked for each consecutive element marked with the same grouping value — and this grouping value itself is obtained by invoking the functor FGRP on each source value. All computation are performed on-the-fly. No capturing or reordering of the source elements takes place, rather groups are formed based on the changes of the grouping value over the source iterator's result sequence.

Template Parameters
AGGdata type to collect the aggregate; must be default constructible and assignable
GRPvalue type to indicate a group
Note
while groupFun is adapted, the aggFun is not adapted to the source iterator, but expected always to take the value type of the preceding iterator, i.e. *srcIter. This limitation was deemed acceptable (adapting a function with several arguments would require quite some nasty technicalities). The first argument of this aggFun refers to the accumulator by value, and thereby also implicitly defines the aggregate result type.
Warning
the Aggregator AGG must not capture references to upstream internal state, because the overall pipeline will be moved into final location after the initial ctor call.

Definition at line 1025 of file iter-explorer.hpp.

Public Types

using value_type = meta::RefTraits< AGG >::Value
 
using reference = meta::RefTraits< AGG >::Reference
 
using pointer = meta::RefTraits< AGG >::Pointer
 

Public Member Functions

 GroupAggregator ()=default
 
template<class FGRP , class FAGG >
 GroupAggregator (SRC &&dataSrc, FGRP &&groupFun, FAGG &&aggFun)
 
bool checkPoint () const
 
reference yield () const
 
void iterNext ()
 

Protected Types

using SrcValue = meta::ValueTypeBinding< SRC >::value_type
 
using Grouping = function< GRP(SRC &)>
 
using Aggregator = function< void(AGG &, SrcValue &)>
 

Protected Member Functions

SRC & srcIter () const
 
void pullGroup ()
 

Protected Attributes

std::optional< AGG > agg_ {}
 
Grouping grouping_
 
Aggregator aggregate_
 

Constructor & Destructor Documentation

◆ GroupAggregator() [1/2]

template<class SRC , typename AGG , class GRP >
GroupAggregator ( )
default

◆ GroupAggregator() [2/2]

template<class SRC , typename AGG , class GRP >
template<class FGRP , class FAGG >
GroupAggregator ( SRC &&  dataSrc,
FGRP &&  groupFun,
FAGG &&  aggFun 
)
inline

Definition at line 1049 of file iter-explorer.hpp.

References GroupAggregator< SRC, AGG, GRP >::pullGroup().

+ Here is the call graph for this function:

Member Typedef Documentation

◆ SrcValue

template<class SRC , typename AGG , class GRP >
using SrcValue = meta::ValueTypeBinding<SRC>::value_type
protected

Definition at line 1031 of file iter-explorer.hpp.

◆ Grouping

template<class SRC , typename AGG , class GRP >
using Grouping = function<GRP(SRC&)>
protected

Definition at line 1032 of file iter-explorer.hpp.

◆ Aggregator

template<class SRC , typename AGG , class GRP >
using Aggregator = function<void(AGG&, SrcValue&)>
protected

Definition at line 1033 of file iter-explorer.hpp.

◆ value_type

template<class SRC , typename AGG , class GRP >
using value_type = meta::RefTraits<AGG>::Value

Definition at line 1041 of file iter-explorer.hpp.

◆ reference

template<class SRC , typename AGG , class GRP >
using reference = meta::RefTraits<AGG>::Reference

Definition at line 1042 of file iter-explorer.hpp.

◆ pointer

template<class SRC , typename AGG , class GRP >
using pointer = meta::RefTraits<AGG>::Pointer

Definition at line 1043 of file iter-explorer.hpp.

Member Function Documentation

◆ checkPoint()

template<class SRC , typename AGG , class GRP >
bool checkPoint ( ) const
inline

Definition at line 1060 of file iter-explorer.hpp.

References GroupAggregator< SRC, AGG, GRP >::agg_.

◆ yield()

template<class SRC , typename AGG , class GRP >
reference yield ( ) const
inline

Definition at line 1066 of file iter-explorer.hpp.

◆ iterNext()

template<class SRC , typename AGG , class GRP >
void iterNext ( )
inline

Definition at line 1072 of file iter-explorer.hpp.

References GroupAggregator< SRC, AGG, GRP >::agg_, GroupAggregator< SRC, AGG, GRP >::pullGroup(), and GroupAggregator< SRC, AGG, GRP >::srcIter().

+ Here is the call graph for this function:

◆ srcIter()

template<class SRC , typename AGG , class GRP >
SRC & srcIter ( ) const
inlineprotected

Definition at line 1083 of file iter-explorer.hpp.

Referenced by GroupAggregator< SRC, AGG, GRP >::iterNext(), and GroupAggregator< SRC, AGG, GRP >::pullGroup().

+ Here is the caller graph for this function:

◆ pullGroup()

template<class SRC , typename AGG , class GRP >
void pullGroup ( )
inlineprotected
Note
establishes the invariant: source has been consumed up to the beginning of next group

Definition at line 1091 of file iter-explorer.hpp.

References GroupAggregator< SRC, AGG, GRP >::agg_, GroupAggregator< SRC, AGG, GRP >::aggregate_, GroupAggregator< SRC, AGG, GRP >::grouping_, and GroupAggregator< SRC, AGG, GRP >::srcIter().

Referenced by GroupAggregator< SRC, AGG, GRP >::GroupAggregator(), and GroupAggregator< SRC, AGG, GRP >::iterNext().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ agg_

template<class SRC , typename AGG , class GRP >
std::optional<AGG> agg_ {}
protected

◆ grouping_

template<class SRC , typename AGG , class GRP >
Grouping grouping_
protected

Definition at line 1037 of file iter-explorer.hpp.

Referenced by GroupAggregator< SRC, AGG, GRP >::pullGroup().

◆ aggregate_

template<class SRC , typename AGG , class GRP >
Aggregator aggregate_
protected

Definition at line 1038 of file iter-explorer.hpp.

Referenced by GroupAggregator< SRC, AGG, GRP >::pullGroup().

+ Inheritance diagram for GroupAggregator< SRC, AGG, GRP >:
+ Collaboration diagram for GroupAggregator< SRC, AGG, GRP >:

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