Package ptolemy.actor

Class TypeAttribute

  • All Implemented Interfaces:
    java.lang.Cloneable, HasTypeConstraints, Typeable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Settable, ValueListener

    public class TypeAttribute
    extends Parameter
    An attribute for defining a data type for a port. Use setExpression() to define a data type, as in for example,
     attribute.setExpression("double");
     
    The class TypedIOPort recognizes when this attribute is inserted and calls setTypeEquals() to define its type. In the above example, the type of the port is set to double.

    The type can be given by any expression that can be evaluated. In fact, it would be equally valid to specify the type to be double using

     attribute.setExpression("0.0");
     
    The Constants class defines the constant "double" to have the value 0.0, so that instead you may give the type by name. The Constants class defines for convenience the following constants: boolean, complex, double, fixedpoint, general, int, long, matrix, object, scalar, string, and unknown. The constant "unknown" has a rather special behavior, in that it sets the type of the port to be unknown, allowing type resolution to infer it. The constant "matrix" designates a matrix without specifying an element type, in contrast to, for example, "[double]", which specifies a double matrix. Similarly, the constant "scalar" designates a scalar of any type (double, int, long, etc.). The constant "general" designates any type.

    Since the type is given by a "prototype" (an expression with the appropriate type), any data type that can be given in an expression can be specified as a type. For structured types, follow the same syntax as in expressions. For example:

     {double} - double array
     [int]    - int matrix
     {field1 = string, field2 = int} - record with two fields
     

    This attribute is a singleton in a strong sense. When its container is set, if the container contains any other instance of TypeAttribute, that other instance is removed.

    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    Edward A. Lee, Xiaojun Liu
    See Also:
    TypedIOPort, Constants
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Constructor Detail

      • TypeAttribute

        public TypeAttribute​(Workspace workspace)
        Construct a parameter in the specified workspace with an empty string as a name. If the workspace argument is null, then use the default workspace. The object is added to the list of objects in the workspace. Increment the version number of the workspace.
        Parameters:
        workspace - The workspace that will list the parameter.
      • TypeAttribute

        public TypeAttribute​(TypedIOPort container,
                             java.lang.String name)
                      throws IllegalActionException,
                             NameDuplicationException
        Construct an attribute with the given name contained by the specified port. The container argument must not be null, or a NullPointerException will be thrown. This attribute will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. The object is added to the directory of the workspace if the container is null. Increment the version of the workspace.
        Parameters:
        container - The container.
        name - The name of this attribute.
        Throws:
        IllegalActionException - If the attribute is not of an acceptable class for the container, or if the name contains a period.
        NameDuplicationException - If the name coincides with an attribute already in the container.
      • TypeAttribute

        public TypeAttribute​(Attribute container,
                             java.lang.String name)
                      throws IllegalActionException,
                             NameDuplicationException
        Construct an attribute with the given name contained by the specified port. The container argument must not be null, or a NullPointerException will be thrown. This attribute will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. The object is added to the directory of the workspace if the container is null. Increment the version of the workspace.
        Parameters:
        container - The container.
        name - The name of this attribute.
        Throws:
        IllegalActionException - If the attribute is not of an acceptable class for the container, or if the name contains a period.
        NameDuplicationException - If the name coincides with an attribute already in the container.