ptolemy.codegen.c.kernel
Class CCodegenUtilities

java.lang.Object
  extended by ptolemy.codegen.c.kernel.CCodegenUtilities

public class CCodegenUtilities
extends java.lang.Object

A utility class used to simplify creating c templates in EmbeddedCActors.

Since:
Ptolemy II 6.1
Version:
$Id: CCodegenUtilities.java 48924 2008-03-25 21:22:11Z cxh $
Author:
Teale Fristoe
Accepted Rating:
Proposed Rating:
red (tbf)

Constructor Summary
CCodegenUtilities()
           
 
Method Summary
static java.lang.String getDefineBlock(java.lang.String constant, java.lang.String value)
          Return a code block to define a constant.
static java.lang.String getIncludeBlock(java.lang.String file, java.lang.String constant)
          Return a code block to include a file.
static java.lang.String jniDeleteLocalRef(java.lang.String reference, boolean targetCpp)
          Return a code block to delete a jni local reference.
static java.lang.String jniFindClass(java.lang.String className, boolean targetCpp)
          Return a code block to find a jni class.
static java.lang.String jniGetArrayElements(java.lang.String type, java.lang.String arrayName, boolean targetCpp)
          Return a code block to get the elements of a jni array.
static java.lang.String jniGetMethodID(java.lang.String jniClass, java.lang.String name, java.lang.String signature, boolean targetCpp)
          Return a code block to get the jni id of a Java method.
static java.lang.String jniGetObjectArrayElement(java.lang.String arrayName, java.lang.String index, boolean targetCpp)
          Return a code block to get an element from a jni array.
static java.lang.String jniNewArray(java.lang.String type, java.lang.String size, boolean targetCpp)
          Return a code block to create a new jni array.
static java.lang.String jniNewObject(java.lang.String objectType, java.lang.String methodID, java.lang.String[] arguments, boolean targetCpp)
          Return a code block to create a new Java object using jni.
static java.lang.String jniNewObjectArray(java.lang.String size, java.lang.String objectType, boolean targetCpp)
          Return a code block to create a new jni object array.
static java.lang.String jniReleaseArrayElements(java.lang.String type, java.lang.String arrayName, java.lang.String elementsPointer, boolean targetCpp)
          Return a code block to release elements from a jni array.
static java.lang.String jniSetArrayRegion(java.lang.String type, java.lang.String arrayName, java.lang.String index, java.lang.String length, java.lang.String valuePointer, boolean targetCpp)
          Return a code block to set elements in a jniarray.
static java.lang.String jniSetObjectArrayElement(java.lang.String arrayName, java.lang.String index, java.lang.String value, boolean targetCpp)
          Return a code block to set an element in a jni object array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CCodegenUtilities

public CCodegenUtilities()
Method Detail

getDefineBlock

public static java.lang.String getDefineBlock(java.lang.String constant,
                                              java.lang.String value)
Return a code block to define a constant.

Parameters:
constant - The name of the constant.
value - The value of the constant.
Returns:
A block of codegen code to define a constant.

getIncludeBlock

public static java.lang.String getIncludeBlock(java.lang.String file,
                                               java.lang.String constant)
Return a code block to include a file.

Parameters:
file - The name of the file.
constant - The name of the constant to check to see if the file has already been included.
Returns:
A block of codegen code to include a file.

jniDeleteLocalRef

public static java.lang.String jniDeleteLocalRef(java.lang.String reference,
                                                 boolean targetCpp)
Return a code block to delete a jni local reference.

Parameters:
reference - The reference to delete.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to delete a jni local reference.

jniFindClass

public static java.lang.String jniFindClass(java.lang.String className,
                                            boolean targetCpp)
Return a code block to find a jni class.

Parameters:
className - The name of the class to find.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to find a jni class.

jniGetArrayElements

public static java.lang.String jniGetArrayElements(java.lang.String type,
                                                   java.lang.String arrayName,
                                                   boolean targetCpp)
Return a code block to get the elements of a jni array.

Parameters:
type - The type, with a capital first letter, of the array elements.
arrayName - The name of the jni array.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to get elements from a jni array.

jniGetMethodID

public static java.lang.String jniGetMethodID(java.lang.String jniClass,
                                              java.lang.String name,
                                              java.lang.String signature,
                                              boolean targetCpp)
Return a code block to get the jni id of a Java method.

Parameters:
jniClass - The Java class whose method to find.
name - The name of the method to find.
signature - The signature of the method to find.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to get the jni id of a Java method. cid = (*env)->GetMethodID(env, stringClass, "", "([C)V");

jniGetObjectArrayElement

public static java.lang.String jniGetObjectArrayElement(java.lang.String arrayName,
                                                        java.lang.String index,
                                                        boolean targetCpp)
Return a code block to get an element from a jni array.

Parameters:
arrayName - The name of the jni array.
index - The index in the jni array to find the element.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to get an element from a jni array.

jniNewArray

public static java.lang.String jniNewArray(java.lang.String type,
                                           java.lang.String size,
                                           boolean targetCpp)
Return a code block to create a new jni array.

Parameters:
type - The type of the array.
size - The number of elements of the array.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to create a new jni element.

jniNewObject

public static java.lang.String jniNewObject(java.lang.String objectType,
                                            java.lang.String methodID,
                                            java.lang.String[] arguments,
                                            boolean targetCpp)
Return a code block to create a new Java object using jni.

Parameters:
objectType - The type of the object.
methodID - The jni id of the object's constructor.
arguments - A list of arguments to the constructor.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to create a new Java object.

jniNewObjectArray

public static java.lang.String jniNewObjectArray(java.lang.String size,
                                                 java.lang.String objectType,
                                                 boolean targetCpp)
Return a code block to create a new jni object array.

Parameters:
size - The number of elements of the array.
objectType - The type of object in the array.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to create a new jni object array.

jniReleaseArrayElements

public static java.lang.String jniReleaseArrayElements(java.lang.String type,
                                                       java.lang.String arrayName,
                                                       java.lang.String elementsPointer,
                                                       boolean targetCpp)
Return a code block to release elements from a jni array.

Parameters:
type - The type of object in the array.
arrayName - The name of the array.
elementsPointer - The pointer to the element to remove.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to release elements from a jni array.

jniSetArrayRegion

public static java.lang.String jniSetArrayRegion(java.lang.String type,
                                                 java.lang.String arrayName,
                                                 java.lang.String index,
                                                 java.lang.String length,
                                                 java.lang.String valuePointer,
                                                 boolean targetCpp)
Return a code block to set elements in a jniarray.

Parameters:
type - The type of the array.
arrayName - The name of the array.
index - The index of the first element to set.
length - The number of elements to set.
valuePointer - The value to set the elements.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to set selements in a jni array.

jniSetObjectArrayElement

public static java.lang.String jniSetObjectArrayElement(java.lang.String arrayName,
                                                        java.lang.String index,
                                                        java.lang.String value,
                                                        boolean targetCpp)
Return a code block to set an element in a jni object array.

Parameters:
arrayName - The name of the object array.
index - The index of the element to set.
value - The value to set the element.
targetCpp - Boolean indicating whether the target language is C or C++.
Returns:
A string containing code to set an element in a jni object array.