|
Boost : |
Subject: [boost] [dataflow][review] facilities for creating generic components
From: Stjepan Rajko (stipe_at_[hidden])
Date: 2008-09-04 03:08:12
Hello,
I updated the Dataflow documentation with some examples showing how to
create generic (in the sense that they can be used with a number of
signal signatures) components for Dataflow.Signals with the help of
some provided class templates. These class templates are applicator,
conditional, instantiator, and modifier (there is also a
conditional_modifier which is not documented, but it basically
provides functionality of both conditional and modifier). The updated
docs (with examples) are uploaded to:
http://www.dancinghacker.com/code/dataflow/
You will find the mentioned class templates in the Components
subsection of the Dataflow.Signals section.
For example, the modifier documentation shows how to easily build a
generic multiplier component, which will multiply each argument of the
passing signal by a specified factor. The component could then be
used as follows:
{
signals::storage<void (int, double)> result;
multiplier<void (int, double)> multiply_by_3 (3);
// result will store the result of the multiplication
multiply_by_3 >>= result;
multiply_by_3(1, 1.5);
BOOST_ASSERT(result.at<0>() == 3);
BOOST_ASSERT(result.at<1>() == 4.5);
}
{
signals::storage<void (float, int, double)> result;
multiplier<void (float, int, double)> multiply_by_half (0.5);
// result will store the result of the multiplication
multiply_by_half >>= result;
multiply_by_half(1.0f, 9, 9.0);
BOOST_ASSERT(result.at<0>() == 0.5f);
BOOST_ASSERT(result.at<1>() == 4);
BOOST_ASSERT(result.at<2>() == 4.5);
}
Note that without this facility, building such a generic multiplier
would be somewhat involved (unless you are using variadic templates).
Stjepan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk