public class AutoAdapter extends NamedProgramCodeGeneratorAdapter
This class provides a way to generate code for actors that do not have custom code generation templates. The generated code requires the Ptolemy kernel, actor, data and other packages.
This class wraps a Ptolemy actor in a TypedCompositeActor container, makes connections from the code generated actors to the container and invokes the actor execution methods (preinitialize(), initialize(), prefire(), fire(), postfire() and wrapup()) of the inner Ptolemy actor.
The primary entry point for this class is
getAutoAdapter(GenericCodeGenerator, Object)
NamedProgramCodeGeneratorAdapter.VariableScope
ProgramCodeGeneratorAdapter.Channel
NamedObj.ContainedObjectsIterator
_component, _defaultBlocks, _eol, _templateParser
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
Constructor and Description |
---|
AutoAdapter(ProgramCodeGenerator codeGenerator,
TypedAtomicActor component)
Construct the code generator adapter associated with the given
component.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
_generateFireCode()
Generate the fire code.
|
java.lang.String |
generateInitializeCode()
Generate the initialize code.
|
java.lang.String |
generateParameterCode()
Generate code for the Parameters of the actor.
|
java.lang.String |
generatePostfireCode()
Generate the postfire code.
|
java.lang.String |
generatePrefireCode()
Generate the prefire code.
|
java.lang.String |
generatePreinitializeCode()
Generate the preinitialize code that declares the ports.
|
java.lang.String |
generatePreinitializeMethodBodyCode()
Generate the preinitialization method body.
|
java.lang.String |
generatePreinitializeMethodBodyCode(NamedObj component)
Generate the preinitialization method body.
|
java.lang.String |
generateWrapupCode()
Generate the wrapup code.
|
static AutoAdapter |
getAutoAdapter(GenericCodeGenerator codeGenerator,
java.lang.Object object)
Create a new adapter to a preexisting actor that presumably does
not have a code generation template.
|
java.util.Set |
getHeaderFiles()
Get the files needed by the code generated for this actor.
|
java.util.Set<java.lang.String> |
getSharedCode()
Generate shared code that includes the declaration of the toplevel
composite.
|
boolean |
isAutoAdaptered(NamedObj namedObj)
Return true if the argument would be generated using
an AutoAdapter.
|
static boolean |
isAutoAdaptered(ProgramCodeGenerator codeGenerator,
NamedObj namedObj)
Return true if the argument would be generated using
an AutoAdapter.
|
boolean |
isAutoAdapteredRemotePort(Port port)
Return true if the port connects to a remote port that would
code generated using an AutoAdapter.
|
static boolean |
isAutoAdapteredRemotePort(ProgramCodeGenerator codeGenerator,
Port port)
Return true if the port connects to a remote port that would
code generated using an AutoAdapter.
|
_generateTypeConvertStatement, analyzeTypeConvert, copyFilesToCodeDirectory, generateFireCode, generateFireFunctionCode, generateMainLoop, generateModeTransitionCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, generateVariableDeclaration, generateVariableInitialization, getAddTimeString, getBufferSize, getBufferSize, getComponent, getDeclareSharedCode, getDefaultBlocks, getFireFunctionParameters, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getName, getParameterValue, getReference, getReference, getSinkChannels, getSourceTimeString, getTimeSourcePortName, getTypeConvertChannels, getTypeConvertReference, getTypeConvertSinkChannels, setupAdapter, targetType
_generateBlockByName, getAdapter, getCodeGenerator, getTemplateParser, processCode, setCodeGenerator, setTemplateParser, toString
createDecoratorAttributes, generateName
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateExistence, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getContainer, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
public AutoAdapter(ProgramCodeGenerator codeGenerator, TypedAtomicActor component)
The primary entry point for this class is
getAutoAdapter(GenericCodeGenerator, Object)
, but this
is left public for testing.
codeGenerator
- The code generator with which to associate the adapter.component
- The associated component.public java.lang.String generateInitializeCode() throws IllegalActionException
Generate code that creates the container, actor and ports.
Generate code that connects the ports of the inner actor to the ports of the outer actor.
generateInitializeCode
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- If thrown while appending to the
the block or processing the macros.public java.lang.String generateParameterCode() throws IllegalActionException
IllegalActionException
- If thrown while reading the parameters
of the actor.public java.lang.String generatePostfireCode() throws IllegalActionException
generatePostfireCode
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- If illegal macro names are found.public java.lang.String generatePrefireCode() throws IllegalActionException
generatePrefireCode
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- If illegal macro names are found.public java.lang.String generatePreinitializeCode() throws IllegalActionException
Generate code that declares the container, actor and ports.
generatePreinitializeCode
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- If illegal macro names are found.public java.lang.String generatePreinitializeMethodBodyCode() throws IllegalActionException
Typically, the preinitialize code consists of variable declarations. However, AutoAdapter generates method calls that instantiate wrapper TypedCompositeActors, so we need to invoke those method calls.
generatePreinitializeMethodBodyCode
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- If there is a problem
accessing the component, its ports or the remote components.public java.lang.String generatePreinitializeMethodBodyCode(NamedObj component) throws IllegalActionException
Typically, the preinitialize code consists of variable declarations. However, AutoAdapter generates method calls that instantiate wrapper TypedCompositeActors, so we need to invoke those method calls.
component
- The component for which the preinitialization
method is to be created.IllegalActionException
- If there is a problem
accessing the component, its ports or the remote components.public java.lang.String generateWrapupCode() throws IllegalActionException
generateWrapupCode
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- If illegal macro names are found.public static AutoAdapter getAutoAdapter(GenericCodeGenerator codeGenerator, java.lang.Object object)
This method is the entry point for this class. Typically,
JavaCodeGenerator._getAutoGeneratedAdapter(GenericCodeGenerator, Object)
calls this method.
codeGenerator
- The code generator with which to associate the adapter.object
- The given object.public java.util.Set getHeaderFiles() throws IllegalActionException
getHeaderFiles
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- If thrown by the superclass.public java.util.Set<java.lang.String> getSharedCode() throws IllegalActionException
getSharedCode
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- Not thrown in this base class.public boolean isAutoAdaptered(NamedObj namedObj)
This is used to put two or more custom actors in to the same container.
namedObj
- The NamedObj to check.public static boolean isAutoAdaptered(ProgramCodeGenerator codeGenerator, NamedObj namedObj)
This is used to put two or more custom actors in to the same container.
codeGenerator
- The codegenerator.namedObj
- The NamedObj to check.public boolean isAutoAdapteredRemotePort(Port port) throws IllegalActionException
This is used to put two or more custom actors in to the same container.
port
- The port to check.IllegalActionException
- If the CodeGenerator verbosity parameter
cannot be read.public static boolean isAutoAdapteredRemotePort(ProgramCodeGenerator codeGenerator, Port port) throws IllegalActionException
This is used to put two or more custom actors in to the same container.
port
- The port to check.codeGenerator
- The codegenerator.IllegalActionException
- If the CodeGenerator verbosity parameter
cannot be read.protected java.lang.String _generateFireCode() throws IllegalActionException
Generate code that creates tokens, sends them to the input(s) of inner Ptolemy actor, calls fire() on the actor and reads the outputs.
_generateFireCode
in class NamedProgramCodeGeneratorAdapter
IllegalActionException
- Not thrown in this base class.