Class 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)
    • 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 class NamedProgramCodeGeneratorAdapter
        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.
      • 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 class NamedProgramCodeGeneratorAdapter
        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.
      • 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.
      • 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.