Class AutoAdapter
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.cg.kernel.generic.CodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.procedural.java.AutoAdapter
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class AutoAdapter extends NamedProgramCodeGeneratorAdapter
A code generator adapter that is auto generated and calls actor code.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)
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Christopher Brooks, Contributor: Edward A. Lee
- Pt.AcceptedRating:
- red (cxh)
- Pt.ProposedRating:
- red (cxh)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
NamedProgramCodeGeneratorAdapter.VariableScope
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
ProgramCodeGeneratorAdapter.Channel
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
-
Fields inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_component, _defaultBlocks, _eol, _templateParser
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description AutoAdapter(ProgramCodeGenerator codeGenerator, TypedAtomicActor component)
Construct the code generator adapter associated with the given component.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.static boolean
isAutoAdaptered(ProgramCodeGenerator codeGenerator, NamedObj namedObj)
Return true if the argument would be generated using an AutoAdapter.boolean
isAutoAdaptered(NamedObj namedObj)
Return true if the argument would be 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.boolean
isAutoAdapteredRemotePort(Port port)
Return true if the port connects to a remote port that would code generated using an AutoAdapter.-
Methods inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
_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
-
Methods inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_generateBlockByName, getAdapter, getCodeGenerator, getTemplateParser, processCode, setCodeGenerator, setTemplateParser, toString
-
Methods inherited from class ptolemy.cg.kernel.generic.CodeGeneratorAdapter
createDecoratorAttributes, generateName
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_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
-
-
-
-
Constructor Detail
-
AutoAdapter
public AutoAdapter(ProgramCodeGenerator codeGenerator, TypedAtomicActor component)
Construct the code generator adapter associated with the given component.The primary entry point for this class is
getAutoAdapter(GenericCodeGenerator, Object)
, but this is left public for testing.- Parameters:
codeGenerator
- The code generator with which to associate the adapter.component
- The associated component.
-
-
Method Detail
-
generateInitializeCode
public java.lang.String generateInitializeCode() throws IllegalActionException
Generate the initialize code.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.
- Overrides:
generateInitializeCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The initialize code of the containing composite actor.
- Throws:
IllegalActionException
- If thrown while appending to the the block or processing the macros.
-
generateParameterCode
public java.lang.String generateParameterCode() throws IllegalActionException
Generate code for the Parameters of the actor.- Returns:
- The generated code
- Throws:
IllegalActionException
- If thrown while reading the parameters of the actor.
-
generatePostfireCode
public java.lang.String generatePostfireCode() throws IllegalActionException
Generate the postfire code.- Overrides:
generatePostfireCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- Code that calls postfire() on the inner actor.
- Throws:
IllegalActionException
- If illegal macro names are found.
-
generatePrefireCode
public java.lang.String generatePrefireCode() throws IllegalActionException
Generate the prefire code.- Overrides:
generatePrefireCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- Code that calls prefire() on the inner actor.
- Throws:
IllegalActionException
- If illegal macro names are found.
-
generatePreinitializeCode
public java.lang.String generatePreinitializeCode() throws IllegalActionException
Generate the preinitialize code that declares the ports.Generate code that declares the container, actor and ports.
- Overrides:
generatePreinitializeCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- A string of the preinitialize code for the adapter.
- Throws:
IllegalActionException
- If illegal macro names are found.
-
generatePreinitializeMethodBodyCode
public java.lang.String generatePreinitializeMethodBodyCode() throws IllegalActionException
Generate the preinitialization method body.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.
- Overrides:
generatePreinitializeMethodBodyCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- a string for the preinitialization method body. In this base class, return the empty string.
- Throws:
IllegalActionException
- If there is a problem accessing the component, its ports or the remote components.
-
generatePreinitializeMethodBodyCode
public java.lang.String generatePreinitializeMethodBodyCode(NamedObj component) throws IllegalActionException
Generate the preinitialization method body.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.
- Parameters:
component
- The component for which the preinitialization method is to be created.- Returns:
- a string for the preinitialization method body. In this base class, return the empty string.
- Throws:
IllegalActionException
- If there is a problem accessing the component, its ports or the remote components.
-
generateWrapupCode
public java.lang.String generateWrapupCode() throws IllegalActionException
Generate the wrapup code.- Overrides:
generateWrapupCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- Code that calls wrapup() on the inner actor.
- Throws:
IllegalActionException
- If illegal macro names are found.
-
getAutoAdapter
public 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.This method is the entry point for this class. Typically,
JavaCodeGenerator._getAutoGeneratedAdapter(GenericCodeGenerator, Object)
calls this method.- Parameters:
codeGenerator
- The code generator with which to associate the adapter.object
- The given object.- Returns:
- the AutoAdapter or null if object is not assignable from TypedAtomicActor.
-
getHeaderFiles
public java.util.Set getHeaderFiles() throws IllegalActionException
Get the files needed by the code generated for this actor. Add $(PTII) to the classpath of the generated code.- Overrides:
getHeaderFiles
in classNamedProgramCodeGeneratorAdapter
- Returns:
- A set of strings that are names of the files needed by the code generated for the Maximum actor.
- Throws:
IllegalActionException
- If thrown by the superclass.
-
getSharedCode
public java.util.Set<java.lang.String> getSharedCode() throws IllegalActionException
Generate shared code that includes the declaration of the toplevel composite. If necessary a method that sets a private parameter is added.- Overrides:
getSharedCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- An empty set in this base class.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
isAutoAdaptered
public boolean isAutoAdaptered(NamedObj namedObj)
Return true if the argument would be generated using an AutoAdapter.This is used to put two or more custom actors in to the same container.
- Parameters:
namedObj
- The NamedObj to check.- Returns:
- True if the argument would be generated using an auto adapter.
-
isAutoAdaptered
public static boolean isAutoAdaptered(ProgramCodeGenerator codeGenerator, NamedObj namedObj)
Return true if the argument would be generated using an AutoAdapter.This is used to put two or more custom actors in to the same container.
- Parameters:
codeGenerator
- The codegenerator.namedObj
- The NamedObj to check.- Returns:
- True if the argument would be generated using an auto adapter.
-
isAutoAdapteredRemotePort
public boolean isAutoAdapteredRemotePort(Port port) throws IllegalActionException
Return true if the port connects to a remote port that would code generated using an AutoAdapter.This is used to put two or more custom actors in to the same container.
- Parameters:
port
- The port to check.- Returns:
- True if the remote port would be generated using an auto adapter.
- Throws:
IllegalActionException
- If the CodeGenerator verbosity parameter cannot be read.
-
isAutoAdapteredRemotePort
public static boolean isAutoAdapteredRemotePort(ProgramCodeGenerator codeGenerator, Port port) throws IllegalActionException
Return true if the port connects to a remote port that would code generated using an AutoAdapter.This is used to put two or more custom actors in to the same container.
- Parameters:
port
- The port to check.codeGenerator
- The codegenerator.- Returns:
- True if the remote port would be generated using an auto adapter.
- Throws:
IllegalActionException
- If the CodeGenerator verbosity parameter cannot be read.
-
_generateFireCode
protected java.lang.String _generateFireCode() throws IllegalActionException
Generate the fire code.Generate code that creates tokens, sends them to the input(s) of inner Ptolemy actor, calls fire() on the actor and reads the outputs.
- Overrides:
_generateFireCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The generated code.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
-