// "bool-source.hac"
//	$Id: bool-source.hac,v 1.7 2007/10/12 22:44:21 fang Exp $
// cyclic and non-cyclic sources of bool tokens


//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/***
	Sources finite sequence of bool values.  
***/
template <><pint N; pbool B[N]>
defproc bool_source_once(chan!(bool) S) {
chp {
{;i:N: S!(B[i]) }
}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/***
	Cycles through finite sequence of bool values.  
***/
template <><pint N; pbool B[N]>
defproc bool_source(chan!(bool) S) {
chp {
*[
	{;i:N: S!(B[i]) }
]
}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
	Cycles through finite sequence of bool values.
	Takes an extra delay parameter, that overrides default send delay.  
 */
template <><pint N; pbool B[N]; preal D>
defproc bool_source_delay(chan!(bool) S) {
chp {
*[
	{;i:N: $(after=D) S!(B[i]) }
]
}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
	Could define in terms of generalized bool_source.
 */
template <><pbool V>
defproc bool_source_constant(chan!(bool) S) {
chp {
*[ S!(V) ]
}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
	Shared output channel, whose access is granted by control token
	on void channel.  
 */
template <><pint N; pbool B[N]>
defproc bool_source_shared(chan?() Cin; chan!() Cout; chan!!(bool) S) {
chp {
*[
	Cin?;
	{;i:N: S!(B[i]) };
	Cout!
]
}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

