ptolemy.actor.lib
Class BooleanSelect

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.BooleanSelect
All Implemented Interfaces:
Actor, Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, Executable, Instantiable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable, TypedActor

public class BooleanSelect
extends TypedAtomicActor

A type polymorphic select with boolean valued control. In an iteration, if an input token is available at the control input, that token is read, and its value is noted. Its value specifies the input port that should be read next. If the control input is true, then if an input token is available on the trueInput port, then it is is read and sent to the output. Likewise with a false input and the falseInput port. The token sent to the output is determined by the control input, which must be a boolean value. Because tokens are immutable, the same Token is sent to the output, rather than a copy. The trueInput and falseInput port may receive Tokens of any type.

The actor indicates a willingness to fire in its prefire() method if there is an input available on the channel specified by the most recently seen token on the control port. If no token has ever been received on the control port, then falseInput is assumed to be the one to read.

This actor is similar to the BooleanMultiplexor actor, except that it never discards input tokens. Tokens on channels that are not selected are not consumed.

Since:
Ptolemy II 2.0
Version:
$Id: BooleanSelect.java,v 1.14 2004/04/13 03:02:23 cxh Exp $
Author:
Steve Neuendorffer, Adam Cataldo
See Also:
Serialized Form
Accepted Rating:
Red (neuendor)
Proposed Rating:
Green (neuendor)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
 TypedIOPort control
          Input that selects one of the other input ports.
 TypedIOPort falseInput
          Input for tokens on the false path.
 TypedIOPort output
          The output port.
 TypedIOPort trueInput
          Input for tokens on the true path.
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
BooleanSelect(CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
 void fire()
          Read a token from each input port.
 void initialize()
          Initialize this actor so that the falseInput is read from until a token arrives on the control input.
 boolean prefire()
          Return false if any input channel does not have a token.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, postfire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
iterate, postfire, preinitialize, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

trueInput

public TypedIOPort trueInput
Input for tokens on the true path. The type can be anything.


falseInput

public TypedIOPort falseInput
Input for tokens on the false path. The type can be anything.


control

public TypedIOPort control
Input that selects one of the other input ports. The type is BooleanToken.


output

public TypedIOPort output
The output port. The type is at least the type of trueInput and falseInput

Constructor Detail

BooleanSelect

public BooleanSelect(CompositeEntity container,
                     java.lang.String name)
              throws IllegalActionException,
                     NameDuplicationException
Construct an actor in the specified container with the specified name.

Parameters:
container - The container.
name - The name of this actor within the container.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the name coincides with an actor already in the container.
Method Detail

fire

public void fire()
          throws IllegalActionException
Read a token from each input port. If the token from the control input is true, then output the token consumed from the trueInput port, otherwise output the token from the falseInput port. This method will throw a NoTokenException if any input channel does not have a token.

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - If there is no director.

initialize

public void initialize()
                throws IllegalActionException
Initialize this actor so that the falseInput is read from until a token arrives on the control input.

Specified by:
initialize in interface Executable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the parent class throws it.

prefire

public boolean prefire()
                throws IllegalActionException
Return false if any input channel does not have a token. Otherwise, return whatever the superclass returns.

Specified by:
prefire in interface Executable
Overrides:
prefire in class AtomicActor
Returns:
False if there are not enough tokens to fire.
Throws:
IllegalActionException - If there is no director.