Lumiera  0.pre.03
»edit your freedom«
MutableFilter< SRC > Class Template Reference

#include "lib/iter-explorer.hpp"

Description

template<class SRC>
class lib::iter_explorer::MutableFilter< SRC >

Special variant of the Filter Decorator to allow for dynamic remoulding. This covers a rather specific use case, where we want to remould or even exchange the Filter predicate in the middle of an ongoing iteration. Such a remoulding can be achieved by binding the existing (opaque) filter predicate into a new combined lambda, thereby capturing it by value. After building, this remoulded version can be assigned to the original filter functor, under the assumption that both are roughly compatible. Moreover, since we wrap the actual lambda into an adapter, allowing for generic lambdas to be used as filter predicates, this setup allows for a lot of leeway regarding the concrete predicates.

Note
whenever the filter is remoulded, the invariant is immediately re-established, possibly forwarding the sequence to the next element approved by the new version of the filter.
Remarks
filter predicates can be specified in a wide variety of forms, and will be adapted automatically. This flexibility also holds for any of the additional clauses provided for remoulding the filter. Especially this means that functors of different kinds can be mixed and combined.

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

Public Member Functions

template<typename FUN >
 MutableFilter (SRC &&dataSrc, FUN &&filterFun)
 
template<typename COND >
void andFilter (COND &&conjunctiveClause)
 remould existing predicate to require in addition the given clause to hold
 
template<typename COND >
void andNotFilter (COND &&conjunctiveClause)
 remould existing predicate to require in addition the negation of the given clause to hold
 
void disableFilter ()
 discard filter predicates and disable any filtering
 
void flipFilter ()
 remould existing predicate to negate the meaning of the existing clause
 
template<typename COND >
void orFilter (COND &&disjunctiveClause)
 remould existing predicate to require either the old OR the given new clause to hold
 
template<typename COND >
void orNotFilter (COND &&disjunctiveClause)
 remould existing predicate to require either the old OR the negation of a new clause to hold
 
template<typename COND >
void setNewFilter (COND &&entirelyDifferentPredicate)
 replace the existing predicate with the given, entirely different predicate
 
- Public Member Functions inherited from Filter< SRC >
template<typename FUN >
 Filter (SRC &&dataSrc, FUN &&filterFun)
 
bool checkPoint () const
 
void expandChildren ()
 refresh state when other layers manipulate the source sequence. More...
 
void iterNext ()
 
SRC::reference yield () const
 

Private Types

using _Filter = Filter< SRC >
 

Private Member Functions

template<typename COND , class COMB >
void remouldFilter (COND &&additionalClause, COMB buildCombinedClause)
 

Additional Inherited Members

- Protected Types inherited from Filter< SRC >
using FilterPredicate = function< bool(SRC &)>
 
- Protected Member Functions inherited from Filter< SRC >
bool isDisabled () const
 
void pullFilter ()
 
SRC & srcIter () const
 
- Protected Attributes inherited from Filter< SRC >
FilterPredicate predicate_
 

Member Function Documentation

◆ remouldFilter()

void remouldFilter ( COND &&  additionalClause,
COMB  buildCombinedClause 
)
inlineprivate

boilerplate to remould the filter predicate in-place

Parameters
additionalClauseadditional functor object to combine
buildCombinedClausea generic lambda (important!) to define how exactly the old and the new predicate are to be combined
Note
the actual combination logic is handed in as generic lambda, which essentially is a template class, and this allows to bind to any kind of function objects or lambdas. This combination closure requires a specific setup: when invoked with the existing and the new functor as argument, it needs to build a new likewise generic lambda to perform the combined evaluation.
Warning
the handed-in lambda buildCombinedClause must capture its arguments, the existing functors by value. This is the key piece in the puzzle, since it effectively moves the existing functor into a new heap allocated storage.

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

+ Inheritance diagram for MutableFilter< SRC >:
+ Collaboration diagram for MutableFilter< SRC >:

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