ptolemy.cg.kernel.generic
Class CodeGeneratorAdapter

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.cg.kernel.generic.CodeGeneratorAdapter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
HTMLCodeGeneratorAdapter, ProgramCodeGeneratorAdapter, TypedCompositeActor

public abstract class CodeGeneratorAdapter
extends NamedObj

Base class for code generator adapter.

Subclasses should override generateFireCode(), generateInitializeCode() generatePostfireCode(), generatePreinitializeCode(), and generateWrapupCode() methods by appending a corresponding code block.

Subclasses should be sure to properly indent the code by either using the code block functionality in methods like _generateBlockCode(String) or by calling CodeStream.indent(String), for example:

     StringBuffer code = new StringBuffer();
     code.append(super.generateWrapupCode());
     code.append("// Local wrapup code");
     return processCode(CodeStream.indent(code.toString()));
 

Since:
Ptolemy II 7.1
Version:
$Id: CodeGeneratorAdapter.java 55939 2009-10-22 16:12:24Z cxh $
Author:
Bert Rodiers
See Also:
Serialized Form
Accepted Rating:
Red (rodiers)
Proposed Rating:
Red (rodiers)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
CodeGeneratorAdapter()
           
 
Method Summary
 DecoratedAttributes createDecoratedAttributes(NamedObj target, GenericCodeGenerator genericCodeGenerator)
          Create and return the decorated attributes for the corresponding Ptolemy Component.
static java.lang.String generateName(NamedObj namedObj)
          Generate sanitized name for the given named object.
abstract  GenericCodeGenerator getCodeGenerator()
          Get the code generator associated with this adapter class.
abstract  void setCodeGenerator(GenericCodeGenerator codeGenerator)
          Set the code generator associated with this adapter class.
 void setTypesOfDecoratedVariables(DecoratedAttributes decoratedAttributes)
          Set the current type of the decorated attributes.
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateExistence, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, 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, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CodeGeneratorAdapter

public CodeGeneratorAdapter()
Method Detail

createDecoratedAttributes

public DecoratedAttributes createDecoratedAttributes(NamedObj target,
                                                     GenericCodeGenerator genericCodeGenerator)
                                              throws IllegalActionException,
                                                     NameDuplicationException
Create and return the decorated attributes for the corresponding Ptolemy Component.

Parameters:
target - The NamedObj that will be decorated.
genericCodeGenerator - The code generator that is the decorator for the corresponding Ptolemy Component.
Returns:
The decorated attributes.
Throws:
IllegalActionException - If the parameter is not of an acceptable class for the container.
NameDuplicationException - If the name coincides with a parameter already in the container.

generateName

public static java.lang.String generateName(NamedObj namedObj)
Generate sanitized name for the given named object. Remove all underscores to avoid conflicts with systems functions.

Parameters:
namedObj - The named object for which the name is generated.
Returns:
The sanitized name.

getCodeGenerator

public abstract GenericCodeGenerator getCodeGenerator()
Get the code generator associated with this adapter class.

Returns:
The code generator associated with this adapter class.
See Also:
setCodeGenerator(GenericCodeGenerator)

setCodeGenerator

public abstract void setCodeGenerator(GenericCodeGenerator codeGenerator)
Set the code generator associated with this adapter class.

Parameters:
codeGenerator - The code generator associated with this adapter class.
See Also:
getCodeGenerator()

setTypesOfDecoratedVariables

public void setTypesOfDecoratedVariables(DecoratedAttributes decoratedAttributes)
                                  throws IllegalActionException
Set the current type of the decorated attributes. The type information of the parameters are not saved in the model hand hence this has to be reset when reading the model again.

Parameters:
decoratedAttributes - The decorated attributes
Throws:
IllegalActionException - If the attribute is not of an acceptable class for the container, or if the name contains a period.