This class is returned by functions like One2AnyChannel::reader() to return a reading end of a channel (that carries items of type DATA_TYPE). More information can be found on the Channel Ends page and in the Channels section of the guide.
They are small classes (the size of a pointer and a boolean) that can be assigned around but only one reading end on a channel should be in use at any one time for the one-to-one and any-to-one channel types.
The mobile channel-ends paradigm may be implemented by simply encasing the channel end in a mobile, i.e. Mobile< Chanin<int> > for ints
This item can be used for normal inputting in one of two ways, either by using the input() or read() methods or by using the >> operator so for example:
One2OneChannel<int> chan; Chanin<int> in = chan.reader(); int a,b; //This: in.input(&a);in.read(&b); //Is the same as this: in >> a >> b;
Note that the input/read functions take a pointer (rather than references) to emphasise that the location is assigned to whereas for simplicity the >> operator uses references, as in >> a is more natural than in >> &a.
This class can be declared const easily as all of its methods are const.
Chanin does not support ALTing (see the Alternative class for details). This is because the channels with shared reading ends, such as One2AnyChannel, do not allow ALTing. Channels that do allow ALTing, such as One2OneChannel, provide an AltChanin that does allow ALTing.
You should also read about the PoisonException that could be thrown, to understand poisoning channels.
C++CSP v1.x Compatibility:
See the note in the Channel Ends module
BufferedOne2AnyChannel::reader()
Public Types | |
typedef ScopedExtInput< DATA_TYPE > | ScopedExtInput |
A typedef for the ScopedExtInput. | |
Public Member Functions | |
Chanin () | |
A constructor for instances that are class members. | |
Chanin (const Chanin< DATA_TYPE > &cho) | |
A standard copy constructor. | |
void | checkPoison () const |
Checks the channel for poison. | |
void | extInput (DATA_TYPE *const dest, void(*function)()) const |
DEPRECATED; Performs an extended input. | |
template<class PROCESS> | |
void | extInput (DATA_TYPE *const dest, PROCESS *proc, void(PROCESS::*memberFn)()) const |
DEPRECATED; A syntax for performing an extended input. | |
void | input (DATA_TYPE *const dest) const |
Performs a normal input. | |
bool | operator== (const csp::Chanin< DATA_TYPE > &b) const |
To allow sets of channel ends that are able to keep only one end per channel we define relational operators Note that a non-poisonable channel end is not equal to a poisonable channel end of the same channel. | |
const Chanin< DATA_TYPE > & | operator>> (DATA_TYPE &obj) const |
Performs a normal input. | |
void | poison () const |
Poisons the channel. | |
void | read (DATA_TYPE *const dest) const |
Identical to the input method. |
typedef ScopedExtInput<DATA_TYPE> csp::Chanin< DATA_TYPE >::ScopedExtInput |
A typedef for the ScopedExtInput.
Chanin<DATA_TYPE>::ScopedExtInput is equivalent to ScopedExtInput<DATA_TYPE>
csp::Chanin< DATA_TYPE >::Chanin | ( | const Chanin< DATA_TYPE > & | cho | ) | [inline] |
A standard copy constructor.
csp::Chanin< DATA_TYPE >::Chanin | ( | ) | [inline] |
A constructor for instances that are class members.
Do not use this constructor for constructing channel ends, instead use something like this:
Chanin<int> chanin = somechannel.reader();
void csp::Chanin< DATA_TYPE >::input | ( | DATA_TYPE *const | dest | ) | const [inline] |
Performs a normal input.
This simply performs a normal input on the channel, into dest It will not return until the input has completed
dest | The destination of the input. Must not be NULL |
void csp::Chanin< DATA_TYPE >::read | ( | DATA_TYPE *const | dest | ) | const [inline] |
const Chanin<DATA_TYPE>& csp::Chanin< DATA_TYPE >::operator>> | ( | DATA_TYPE & | obj | ) | const [inline] |
Performs a normal input.
Does the same as the input() function but takes a reference not a pointer. It can be used to easily chain sequential inputs as follows:
One2OneChannel<int> chan; Chanin<int> in = chan.reader(); int a,b; //This: in.input(&a);in.input(&b); //Is the same as this: in >> a >> b;
obj | The variable to input into |
void csp::Chanin< DATA_TYPE >::poison | ( | ) | const [inline] |
Poisons the channel.
This poisons the channel, and can be safely called multiple times
Read about PoisonException for more information regarding poison
void csp::Chanin< DATA_TYPE >::checkPoison | ( | ) | const [inline] |
Checks the channel for poison.
Rather than being an accessor for the poison flag, this function instead checks it and then returns normally if the channel is not poisoned, or throws a PoisonException if it is.
This function allows processes performing lots of calculations and no channel communications to check for poison more often than only checking when a channel communication is performed
bool csp::Chanin< DATA_TYPE >::operator== | ( | const csp::Chanin< DATA_TYPE > & | b | ) | const [inline] |
To allow sets of channel ends that are able to keep only one end per channel we define relational operators Note that a non-poisonable channel end is not equal to a poisonable channel end of the same channel.
void csp::Chanin< DATA_TYPE >::extInput | ( | DATA_TYPE *const | dest, | |
PROCESS * | proc, | |||
void(PROCESS::*)() | memberFn | |||
) | const [inline] |
DEPRECATED; A syntax for performing an extended input.
This function takes a destination for the extended input, a class type - which will usually be a process, though it can be any class - and a member function of that class (which should be accessible by Chanin).
The input will be performed, then the function will be called then the outputter will be freed.
You may well wish to look at ScopedExtInput for an alternative way of performing extended inputs.
dest | The destination for the extended input. Must not be NULL | |
proc | The class (not necessarily a process) to call memberFn for | |
memberFn | The member function of proc to call |
void csp::Chanin< DATA_TYPE >::extInput | ( | DATA_TYPE *const | dest, | |
void(*)() | function | |||
) | const [inline] |
DEPRECATED; Performs an extended input.
This function inputs to dest, then calls function() then frees the outputter. You may well wish to look at ScopedExtInput for an alternative way of performing extended inputs
dest | The destination for the extended input. Must not be NULL | |
function | The function to call during the extended input |