An extended input needs a beginning and an end, with the extended action inbetween. The Chanin::extInput (and AltChanin::extInput) functions provide one way to accomplish this, accepting a function that represents the extended action. However, this can be annoying where you want the extended action to use variables declared in the function with the extended input.
Hence the ScopedExtInput class. It is used as follows:
One2OneChannel<int> c; int n; ... { ScopedExtInput<int> ext(c.reader(),&n); //Extended input begins here //Extended action takes place in this block } //Extended input finishes here
It is advised that you begin a new block solely for the ScopedExtInput. It aids readability and makes it clear where the extended input begins and ends. Other uses may make the action less clear.
Some may feel that this class is dangerous, because the end of the extended input is hidden inside the end of the block. There are other mechanisms available to perform an extended input, so you may use them instead. The advantage of this method is that it allows a simple use of extended inputs, and prevents you forgetting to end the extended input.
If an exception is thrown (be it a PoisonException or any other exception) that causes ScopedExtInput to be destroyed, the extended input is still finished correctly.
More information can be found on the Scoped Classes page and in the Extended Input section of the guide.
Public Member Functions | |
ScopedExtInput (const Chanin< DATA_TYPE > &_in, DATA_TYPE *const dest) | |
Constructs a ScopedExtInput, beginning an extended input on the designated channel. | |
~ScopedExtInput () | |
Destroys the ScopedExtInput object. |
csp::ScopedExtInput< DATA_TYPE >::ScopedExtInput | ( | const Chanin< DATA_TYPE > & | _in, | |
DATA_TYPE *const | dest | |||
) | [inline] |
Constructs a ScopedExtInput, beginning an extended input on the designated channel.
See the documentation at the top of this page for details on how to use this class.
_in | The channel input end to perform the extended input on | |
dest | The destination for the extended input. Must not be NULL |
csp::ScopedExtInput< DATA_TYPE >::~ScopedExtInput | ( | ) | [inline] |
Destroys the ScopedExtInput object.
This will finish the extended input and free the writer