org.ptolemy.fmi
Class FMIScalarVariable

java.lang.Object
  extended by org.ptolemy.fmi.FMIScalarVariable

public class FMIScalarVariable
extends java.lang.Object

An object that represents the ScalarVariable element of a modelDescription.xml file contained within a Functional Mock-up Interface .fmu XML file.

A Functional Mock-up Unit file is a .fmu file in zip format that contains a .xml file named "modelDescription.xml". In that file, the ModelVariables element may contain elements such as ScalarVariable.

FMI documentation may be found at http://www.modelisar.com/fmi.html.

Version:
$Id: FMIScalarVariable.java 66026 2013-04-07 16:41:23Z cxh $
Author:
Christopher Brooks
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Nested Class Summary
static class FMIScalarVariable.Alias
          Acceptable values for the alias xml attribute.
static class FMIScalarVariable.Causality
          Acceptable values for the causality xml attribute.
static class FMIScalarVariable.Variability
          Acceptable values for the variability xml attribute.
 
Field Summary
private static java.util.Set<java.lang.String> _errorElements
          The set of elements that we don't yet handle.
private  com.sun.jna.Function _fmiGetFunction
          The FMI .c function that gets the value of this variable.
private  com.sun.jna.Function _fmiSetFunction
          The FMI .c function that sets the value of this variable.
private  java.lang.String _typeName
          The name of the type of this variable.
 FMIScalarVariable.Alias alias
          The value of the alias xml attribute.
 FMIScalarVariable.Causality causality
          The value of the causality xml attribute.
 java.lang.String description
          The value of the description xml attribute.
 java.util.Set<java.lang.String> directDependency
          The input ports on which an output has a direct dependence.
 FMIModelDescription fmiModelDescription
          The Model Description for this variable.
 java.lang.String name
          The value of the name xml attribute.
 FMIType type
          The value of the type xml attribute.
 long valueReference
          The value of the valueReference xml attribute.
 FMIScalarVariable.Variability variability
          The value of the variability xml attribute.
 
Constructor Summary
FMIScalarVariable()
          Create an empty ScalarVariable.
FMIScalarVariable(FMIModelDescription fmiModelDescription, org.w3c.dom.Element element)
          Create a ScalarVariable from an XML Element.
 
Method Summary
private  void _getOrSetValue(com.sun.jna.Pointer fmiComponent, java.lang.Object valueBuffer, java.lang.Class typeClass, com.sun.jna.Function getOrSetFunction)
          Get or set the value of this variable.
private  void _getValue(com.sun.jna.Pointer fmiComponent, java.lang.Object valueBuffer, java.lang.Class typeClass)
          Get the value of this variable.
private  void _setValue(com.sun.jna.Pointer fmiComponent, java.lang.Object valueBuffer, java.lang.Class typeClass)
          Set the value of this variable.
 boolean getBoolean(com.sun.jna.Pointer fmiComponent)
          Return the value of this variable as a boolean.
 double getDouble(com.sun.jna.Pointer fmiComponent)
          Return the value of this variable as a double.
 int getInt(com.sun.jna.Pointer fmiComponent)
          Return the value of this variable as an int.
 java.lang.String getString(com.sun.jna.Pointer fmiComponent)
          Return the value of this variable as a String.
 void setBoolean(com.sun.jna.Pointer fmiComponent, boolean value)
          Set the value of this variable as a boolean.
 void setDouble(com.sun.jna.Pointer fmiComponent, double value)
          Set the value of this variable as a double.
 void setInt(com.sun.jna.Pointer fmiComponent, int value)
          Set the value of this variable as an integer.
 void setString(com.sun.jna.Pointer fmiComponent, java.lang.String value)
          Set the value of this variable as a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

alias

public FMIScalarVariable.Alias alias
The value of the alias xml attribute.


causality

public FMIScalarVariable.Causality causality
The value of the causality xml attribute.


description

public java.lang.String description
The value of the description xml attribute.


directDependency

public java.util.Set<java.lang.String> directDependency
The input ports on which an output has a direct dependence.


fmiModelDescription

public FMIModelDescription fmiModelDescription
The Model Description for this variable.


name

public java.lang.String name
The value of the name xml attribute.


type

public FMIType type
The value of the type xml attribute.


valueReference

public long valueReference
The value of the valueReference xml attribute. In FMI 1.0, a valueReference is typically 32-bits or an unsigned int. Java does not have an unsigned int, so we use a long.


variability

public FMIScalarVariable.Variability variability
The value of the variability xml attribute.


_errorElements

private static java.util.Set<java.lang.String> _errorElements
The set of elements that we don't yet handle. This is used for error messages.


_fmiGetFunction

private com.sun.jna.Function _fmiGetFunction
The FMI .c function that gets the value of this variable. The name of the function depends on the value of the fmiModelDescription.modelIdentifer field and the type name. A typical value for the Bouncing Ball example might be "bouncingBall_fmiGetDouble".


_fmiSetFunction

private com.sun.jna.Function _fmiSetFunction
The FMI .c function that sets the value of this variable. The name of the function depends on the value of the fmiModelDescription.modelIdentifer field and the type name. A typical value for the Bouncing Ball example might be "bouncingBall_fmiSetDouble".


_typeName

private java.lang.String _typeName
The name of the type of this variable.

Constructor Detail

FMIScalarVariable

public FMIScalarVariable()
Create an empty ScalarVariable.


FMIScalarVariable

public FMIScalarVariable(FMIModelDescription fmiModelDescription,
                         org.w3c.dom.Element element)
Create a ScalarVariable from an XML Element.

Parameters:
fmiModelDescription - the Model Description for this variable.
element - The XML Element that contains attributes.
Method Detail

getBoolean

public boolean getBoolean(com.sun.jna.Pointer fmiComponent)
Return the value of this variable as a boolean.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
Returns:
the value of this variable as boolean.
See Also:
setBoolean(Pointer, boolean)

getDouble

public double getDouble(com.sun.jna.Pointer fmiComponent)
Return the value of this variable as a double. If the variable is of type FMIIntegerType, the the integer value is cast to a double.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
Returns:
the value of this variable as double.
See Also:
setDouble(Pointer, double)

getInt

public int getInt(com.sun.jna.Pointer fmiComponent)
Return the value of this variable as an int.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
Returns:
the value of this variable as an int.
See Also:
setInt(Pointer, int)

getString

public java.lang.String getString(com.sun.jna.Pointer fmiComponent)
Return the value of this variable as a String.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
Returns:
the value of this variable as a String.
See Also:
setString(Pointer, String)

setBoolean

public void setBoolean(com.sun.jna.Pointer fmiComponent,
                       boolean value)
Set the value of this variable as a boolean.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
value - The value of this variable.
See Also:
getBoolean(Pointer fmiComponent)

setDouble

public void setDouble(com.sun.jna.Pointer fmiComponent,
                      double value)
Set the value of this variable as a double.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
value - The value of this variable.
See Also:
getDouble(Pointer)

setInt

public void setInt(com.sun.jna.Pointer fmiComponent,
                   int value)
Set the value of this variable as an integer.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
value - The value of this variable.
See Also:
getInt(Pointer)

setString

public void setString(com.sun.jna.Pointer fmiComponent,
                      java.lang.String value)
Set the value of this variable as a String. This method allocates memory, the caller should eventually call FMIModelDescription.dispose().

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
value - The value of this variable.
See Also:
getString(Pointer)

_getOrSetValue

private void _getOrSetValue(com.sun.jna.Pointer fmiComponent,
                            java.lang.Object valueBuffer,
                            java.lang.Class typeClass,
                            com.sun.jna.Function getOrSetFunction)
Get or set the value of this variable.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
valueBuffer - The buffer that contains the value to be gotten or set. For booleans, doubles and integers, this is a Buffer, for String it is a PointerByReference
typeClass - The expected class of the type.
getOrSetFunction - the fmiGet or fmiSet function.

_getValue

private void _getValue(com.sun.jna.Pointer fmiComponent,
                       java.lang.Object valueBuffer,
                       java.lang.Class typeClass)
Get the value of this variable.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
valueBuffer - The buffer that contains the value to be gotten. For booleans, doubles and integers, this is a Buffer, for String it is a PointerByReference
typeClass - The expected class of the type.

_setValue

private void _setValue(com.sun.jna.Pointer fmiComponent,
                       java.lang.Object valueBuffer,
                       java.lang.Class typeClass)
Set the value of this variable.

Parameters:
fmiComponent - The Functional Mock-up Interface (FMI) component that contains a reference to the variable.
valueBuffer - The buffer that contains the value to be set. For booleans, doubles and integers, this is a Buffer, for String it is a PointerByReference
typeClass - The expected class of the type.