Handling Custom Returns in C++¶
The C++ API allows users to return custom objects from their workflows.
To do so, the user must create a functor object which overloads the operator() function. Lemon provides two implementations for C++ streams (such as std::cout) and associative arrays (such as std::map). These two examples are given below to guide users in the creation of their own custom functors for new types. It is recommended that the user use C++ templates to obtain the most flexible implementations.
-
struct
lemon
::
print_combine
¶ Functor to stream workflow results to an ostream object
This is a template functor which streams workflow results to a
collector
. This class is typically used to stream text results from workflows to thestd::cout
object. Any class which derives fromstd::ostream
is supported.Public Functions
-
print_combine
(std::ostream &collector)¶ Construct a print_combine which streams results to
collector
.This contructor will create a
print_combine
object which streams results tocollector
. This argument must derive from thestd::ostream
class and therefore provide an overload to the<<
operator. Common examples ofcollector
arestd::cout
and friends. All workflow results are streamed to thecollect
after all entries have been evaluated.- Parameters
collector
: An object for each workflow objects will be streamed to
-
-
template<typename
Map1
>
structlemon
::
map_combine
¶ Functor to combine the results of a workflow into a map
This is a template functor which opens combines the results of a workflow into a single map object. Use this class only when the work flow returns a map oject or other type of associative array.
Public Functions
-
map_combine
(Map1 &collector)¶ Construct a map_combine class which fills the
collector
This constructor will copy all results to the
collector
object. This operation is performed when the workflow completes for all entries.- Parameters
collector
: A map like object to store results in.
-
Python alternative¶
This feature is under current development for the Python API, but is not yet supported. Instead, users should store the results of their workflows in the self object and rely on the finalize function to analyze the result.