public class SetVariable extends TypedAtomicActor implements ChangeListener, ExplicitChangeContext
Set the value of a variable. If there is a variable or parameter in scope with a name matching variableName, then that variable is the one to be set. If there is no such variable, then one will be created in the container of this actor. A variable is in scope if it is contained by the container, the container's container, or any container above in the hierarchy. NOTE: We recommend always creating a parameter with a name matching variableName, because then the model is explicit about which variable will be set. It also makes it easier to monitor the variable updates.
The update to the variable
may occur at two different times, depending on the value of the
If delayed is false, then the output port produces the same token provided at the input port when the actor fires, after the specified variable has been set. This can be used, even with delayed set to false, to ensure determinacy by triggering downstream actions only after the variable has been set.
If delayed is true, then the output port produces the current value of the referenced variable. If the referenced variable does not exist on the first firing, or is not an instance of Variable, then no output is produced on the first firing.
The variable can be any attribute that implements the Settable interface, which includes Parameter. If it is in addition an instance of Variable or Parameter, then the input token is used directly to set the value, and the type of the variable is constrained to be the same as the type of the input. Otherwise, then input token is converted to a string and the setExpression() method on the variable is used to set the value.
For efficiency, the variable update does not automatically trigger a repaint in Vergil. If the variable value is being used to create an animation in Vergil, then you should include in the model an instance of RepaintController, which can be found under Utilities in the library.
Publisher
,
Subscriber
Red (cxh) |
Red (yuhong) |
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
Parameter |
delayed
Parameter that determines when reconfiguration occurs.
|
TypedIOPort |
input
The input port.
|
TypedIOPort |
output
The output port.
|
StringAttribute |
variableName
The name of the variable in the container to set.
|
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
SetVariable(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name.
|
SetVariable(Workspace workspace)
Construct an actor in the specified workspace with an empty
string as a name.
|
Modifier and Type | Method and Description |
---|---|
protected java.util.Set<Inequality> |
_customTypeConstraints()
Return a constraint requiring that if there is a specified variable to
modify, the type of that variable is less than or equal to the type
of the output port.
|
void |
changeExecuted(ChangeRequest change)
Do nothing.
|
void |
changeFailed(ChangeRequest change,
java.lang.Exception exception)
React to the fact that a change failed by setting a flag
that causes an exception to be thrown in next call to prefire()
or wrapup().
|
java.lang.Object |
clone(Workspace workspace)
Clone the actor into the specified workspace.
|
void |
fire()
Read at most one token from the input port and issue a change
request to update variables as indicated by the input.
|
Entity |
getContext()
Return the change context being made explicit.
|
Attribute |
getModifiedVariable()
Return the (presumably Settable) attribute modified by this
actor.
|
java.util.List |
getModifiedVariables()
Return a list of variables that this entity modifies.
|
boolean |
postfire()
Read at most one token from the input port and issue a change
request to update variables as indicated by the input.
|
void |
preinitialize()
If there is no variable with the specified name, then create one.
|
_containedTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
description, getContainer, getDisplayName, getFullName, getName, getName, setName
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
addInitializable, initialize, removeInitializable, wrapup
getDerivedLevel, getDerivedList, propagateValue
public Parameter delayed
public TypedIOPort input
public TypedIOPort output
public StringAttribute variableName
public SetVariable(Workspace workspace)
workspace
- The workspace that will list the entity.public SetVariable(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
container
- The container.name
- The name of this actor.IllegalActionException
- If this actor cannot be contained
by the proposed container.NameDuplicationException
- If the container already has an
actor with this name.public void changeExecuted(ChangeRequest change)
changeExecuted
in interface ChangeListener
change
- The change that executed.public void changeFailed(ChangeRequest change, java.lang.Exception exception)
changeFailed
in interface ChangeListener
change
- The change request.exception
- The exception that resulted.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class TypedAtomicActor
workspace
- The workspace for the new object.java.lang.CloneNotSupportedException
- If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class AtomicActor<TypedIOPort>
IllegalActionException
- If thrown reading the input.public Entity getContext()
getContext
in interface ExplicitChangeContext
public Attribute getModifiedVariable() throws IllegalActionException
IllegalActionException
- If the variable cannot be found.public java.util.List getModifiedVariables() throws IllegalActionException
getModifiedVariables
in interface ExplicitChangeContext
IllegalActionException
- If the list of modified
variables cannot be returned.public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class AtomicActor<TypedIOPort>
IllegalActionException
- If thrown reading the input.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class AtomicActor<TypedIOPort>
IllegalActionException
- If the superclass throws it,
or if there is no container.protected java.util.Set<Inequality> _customTypeConstraints()
_customTypeConstraints
in class TypedAtomicActor