csp::ScopedExtInput< DATA_TYPE > Class Template Reference
[Channel EndsScoped Classes]

List of all members.

Detailed Description

template<typename DATA_TYPE>
class csp::ScopedExtInput< DATA_TYPE >

Provides an easy way to perform extended inputs using scope.

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.


Constructor & Destructor Documentation

template<typename DATA_TYPE>
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.

Parameters:
_in The channel input end to perform the extended input on
dest The destination for the extended input. Must not be NULL

template<typename DATA_TYPE>
csp::ScopedExtInput< DATA_TYPE >::~ScopedExtInput (  )  [inline]

Destroys the ScopedExtInput object.

This will finish the extended input and free the writer


Generated on Mon Aug 20 12:24:29 2007 for C++CSP2 by  doxygen 1.4.7