µEvLoop
A fast and lightweight event loop aimed at embedded platforms in C99.
|
Contains helpers for composing and augumenting closures. More...
#include "uevloop/utils/closure.h"
#include "uevloop/utils/pipeline.h"
#include "uevloop/utils/conditional.h"
#include "uevloop/utils/iterator.h"
Go to the source code of this file.
Data Structures | |
struct | uel_func_mapper_t |
Maps elements of an iterator to an area of memory. Each element is assigned to a void pointer slot. More... | |
Functions | |
void | uel_func_mapper_init (uel_func_mapper_t *mapper, uel_iterator_t *iterator, void **destination, size_t limit) |
Initialises a mapper object. More... | |
uel_closure_t | uel_func_pipeline (uel_pipeline_t *pipeline) |
Wraps a pipeline in a closure. More... | |
uel_closure_t | uel_func_conditional (uel_conditional_t *conditional) |
Wraps a conditional in a closure. More... | |
uel_closure_t | uel_func_foreach (uel_closure_t *closure) |
Wraps a closure in a foreach construct. More... | |
uel_closure_t | uel_func_map (uel_closure_t *closure) |
Wraps a closure in a map construct. More... | |
uel_closure_t | uel_func_find (uel_closure_t *closure) |
Wraps a closure in a find construct. More... | |
uel_closure_t | uel_func_count (uel_closure_t *closure) |
Wraps a closure in a count construct. More... | |
uel_closure_t | uel_func_all (uel_closure_t *closure) |
Wraps a closure in a all construct. More... | |
uel_closure_t | uel_func_none (uel_closure_t *closure) |
Wraps a closure in a none construct. More... | |
uel_closure_t | uel_func_any (uel_closure_t *closure) |
Wraps a closure in a all construct. More... | |
Contains helpers for composing and augumenting closures.
uel_closure_t uel_func_all | ( | uel_closure_t * | closure | ) |
Wraps a closure in a all
construct.
Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t
as parameter and applies the supplied closure to each element yielded by this iterator.
If all enumerate elements cause the supplied closure to return true
, this new closure also returns true
. Otherwise, it returns false
.
closure | The test to be applied against each enumerated element |
uel_closure_t uel_func_any | ( | uel_closure_t * | closure | ) |
Wraps a closure in a all construct.
Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t
as parameter and applies the supplied closure to each element yielded by this iterator.
If any enumerate elements cause the supplied closure to return true
, this new closure also returns true
. Otherwise, it returns false
.
closure | The test to be applied against each enumerated element |
uel_closure_t uel_func_conditional | ( | uel_conditional_t * | conditional | ) |
Wraps a conditional in a closure.
This function wraps a conditional in a closure. When invoked, the closure's parameters will be forwarded to the conditional. Also, the conditional's returned value will be returned from the closure.
conditional | The conditional to be wrapped |
uel_closure_t uel_func_count | ( | uel_closure_t * | closure | ) |
Wraps a closure in a count
construct.
Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t
as parameter and applies the supplied closure to each element yielded by this iterator.
This new closure counts the number of enumerated elements that caused the test closure to return true
.
closure | The test to be applied against each enumerated element |
uel_closure_t uel_func_find | ( | uel_closure_t * | closure | ) |
Wraps a closure in a find
construct.
Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t
as parameter and applies the supplied closure to each element yielded by this iterator.
When some enumerated element causes the supplied closure to return true, its address is returned by the new closure.
closure | The test to be applied against each enumerated element |
NULL
. uel_closure_t uel_func_foreach | ( | uel_closure_t * | closure | ) |
Wraps a closure in a foreach
construct.
Creates a new closure based on a supplied closure. When invoked, this new closure takes an uel_iterator_t
for parameter and yields each element in it to the supplied closure.
closure | A reference to the closure to be wrapped |
uel_closure_t uel_func_map | ( | uel_closure_t * | closure | ) |
Wraps a closure in a map
construct.
Creates a new closure based on a supplied closure. This new closure takes an uel_func_mapper_t
for parameter describing the mapping relation between elements yielded from an iterator and a region of memory.
When invoked, this new closure passes each element enumerated by this mapper as parameter to the supplied closure and stores its returned value sequentially in the destination area. It then returns the destination address.
See uel_iterator_map()
.
closure | A reference to the closure to be wrapped |
void uel_func_mapper_init | ( | uel_func_mapper_t * | mapper, |
uel_iterator_t * | iterator, | ||
void ** | destination, | ||
size_t | limit | ||
) |
Initialises a mapper object.
mapper | The mapper instance to be initialised |
iterator | The iterator responsible for enumerating elements |
destination | An array of void pointers to where elements will be mapped |
limit | The maximum size of elements that can be mapped |
uel_closure_t uel_func_none | ( | uel_closure_t * | closure | ) |
Wraps a closure in a none
construct.
Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t
as parameter and applies the supplied closure to each element yielded by this iterator.
If all enumerate elements cause the supplied closure to return false
, this new closure also returns true
. Otherwise, it returns false
.
closure | The test to be applied against each enumerated element |
uel_closure_t uel_func_pipeline | ( | uel_pipeline_t * | pipeline | ) |
Wraps a pipeline in a closure.
This function wraps a pipeline in a closure. When invoked, the closure's parameters will be forwarded to the pipeline. Also, the pipeline's returned value will be returned from the closure.
pipeline | The pipeline to be wrapped |