/* An actor producing a sequence of 0 and 1.
Copyright (c) 2000-2005 The Regents of the University of California.
All rights reserved.
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this
software and its documentation for any purpose, provided that the above
copyright notice and the following two paragraphs appear in all copies
of this software.
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
PT_COPYRIGHT_VERSION_2
COPYRIGHTENDKEY
*/
package ptolemy.domains.fsm.kernel.test;
import ptolemy.actor.TypedCompositeActor;
import ptolemy.actor.lib.SequenceSource;
import ptolemy.data.IntToken;
import ptolemy.data.Token;
import ptolemy.data.type.BaseType;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.InternalErrorException;
import ptolemy.kernel.util.NameDuplicationException;
//////////////////////////////////////////////////////////////////////////
//// ZeroOneSource
/**
This actor produces the sequence 011101011011000... as source of the AMI
(Alternating Mark 1) test.
@author Xiaojun Liu
@version $Id: ZeroOneSource.java,v 1.17 2005/07/08 19:58:23 cxh Exp $
@since Ptolemy II 1.0
@Pt.ProposedRating Red (liuxj)
@Pt.AcceptedRating Red (cxh)
*/
public class ZeroOneSource extends SequenceSource {
/** Construct an actor with the given container and name.
* @param container The container.
* @param name The name of this actor.
* @exception IllegalActionException If the actor cannot be contained
* by the proposed container.
* @exception NameDuplicationException If the container already has an
* actor with this name.
*/
public ZeroOneSource(TypedCompositeActor container, String name)
throws NameDuplicationException, IllegalActionException {
super(container, name);
output.setTypeEquals(BaseType.INT);
}
///////////////////////////////////////////////////////////////////
//// public methods ////
/** Send the current output in the sequence.
*/
public void fire() {
try {
if (_iterationCount >= _seq.length) {
output.broadcast(_zero);
} else {
output.broadcast(new IntToken(_seq[_iterationCount]));
}
} catch (IllegalActionException ex) {
// Should not be thrown because this is an output port.
throw new InternalErrorException(ex.getMessage());
}
}
/** Initialize the iteration counter.
* @exception IllegalActionException If the parent class throws it,
* which could occur if, for example, the director will not accept
* sequence actors.
*/
public void initialize() throws IllegalActionException {
super.initialize();
_iterationCount = 0;
}
/** Increment the iteration counter, and if it equals the
* value of the <i>firingCountLimit</i> parameter, return false.
* Otherwise, return true.
* @exception IllegalActionException If firingCountLimit has
* an invalid expression.
*/
public boolean postfire() throws IllegalActionException {
_iterationCount++;
return super.postfire();
}
///////////////////////////////////////////////////////////////////
//// private variables ////
private int[] _seq = { 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0 };
private int _iterationCount = 0;
private Token _zero = new IntToken(0);
}