📄 arraybuffe_lastr.java
字号:
/* An buffer for an array.*/
package ptolemy.actor.lib;
import ptolemy.actor.parameters.PortParameter;
import ptolemy.data.ArrayToken;
import ptolemy.data.IntToken;
import ptolemy.data.BooleanToken;
import ptolemy.data.DoubleToken;
import ptolemy.data.Token;
import ptolemy.data.expr.Parameter;
import ptolemy.data.type.ArrayType;
import ptolemy.data.type.BaseType;
import ptolemy.data.type.Typeable;
import ptolemy.data.type.Type;
import ptolemy.actor.TypedIOPort;
//import ptolemy.graph.Inequality;
//import ptolemy.graph.InequalityTerm;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.*;
//import java.util.Iterator;
//import java.util.LinkedList;
//import java.util.List;
//////////////////////////////////////////////////////////////////////////
//// ArrayBuffer
/**
An Buffer for a array. This actor reads an array from the
<i>input</i> port ,if reset is true,it will sends this array
to the <i>output</i>port. else will send this array to <i>discard_out<i>
port;
@author Irene
@since Ptolemy II 3.0
*/
public class ArrayBuffer extends Transformer {
/** 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 ArrayBuffer(CompositeEntity container, String name)
throws NameDuplicationException, IllegalActionException {
super(container, name);
// Set port
reset=new TypedIOPort(this ,"reset",true,false);
reset.setTypeEquals(BaseType.BOOLEAN);
discard_out=new TypedIOPort(this,"discard_out",false,true);
discard_out.setTypeAtLeast(input);
}
///////////////////////////////////////////////////////////////////
//// ports ////
// some unuseful signal will be send to this port;
public TypedIOPort discard_out;
public TypedIOPort reset;
///////////////////////////////////////////////////////////////////
//// public methods ////
/** Consume at most one array from the input port and produce
* one of its elements on the output port. If there is no token
* on the input, then no output is produced.
* @exception IllegalActionException If the <i>index</i> parameter
* (or port value) is out of range.
*/
public void fire() throws IllegalActionException {
Token inputArray[]=null;
if (input.hasToken(0))
inputArray = ((ArrayToken)input.get(0)).arrayValue();
for (int i = 0; i < reset.getWidth(); i++) {
if (reset.hasToken(i)) {
BooleanToken r = (BooleanToken)reset.get(i);
if (r.booleanValue()) output.send(0, new ArrayToken(inputArray));
else discard_out.send(0, new ArrayToken(inputArray));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -