com.jogamp.gluegen

## Class CMethodBindingEmitter

- java.lang.Object
- - com.jogamp.gluegen.FunctionEmitter
  - - com.jogamp.gluegen.CMethodBindingEmitter

- Direct Known Subclasses:
    ProcAddressCMethodBindingEmitter

      public class CMethodBindingEmitter
      extends FunctionEmitter

  Emits the C-side component of the Java<->C JNI binding.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `CMethodBindingEmitter.DefaultCommentEmitter` Class that emits a generic comment for CMethodBindingEmitters; the comment includes the C signature of the native method that is being bound by the emitter java method.

    - ### Nested classes/interfaces inherited from class com.jogamp.gluegen.FunctionEmitter

      `FunctionEmitter.EmissionModifier`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String` | `arrayIdx`
    `protected static String` | `arrayRes`
    `protected static String` | `arrayResLength`
    `protected MethodBinding` | `binding`
    `protected static CommentEmitter` | `defaultCommentEmitter`
    `protected boolean` | `forImplementingMethodCall`
    `protected boolean` | `forIndirectBufferAndArrayImplementation`
    `protected static Logger` | `LOG`
    `protected MachineDescription` | `machDesc`
    `protected static String` | `STRING_CHARS_PREFIX`

    - ### Fields inherited from class com.jogamp.gluegen.FunctionEmitter

      `STATIC`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CMethodBindingEmitter(MethodBinding binding, PrintWriter output, String javaPackageName, String javaClassName, boolean isOverloadedBinding, boolean isJavaMethodStatic, boolean forImplementingMethodCall, boolean forIndirectBufferAndArrayImplementation, MachineDescription machDesc)` Constructs an emitter for the specified binding, and sets a default comment emitter that will emit the signature of the C function that is being bound.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected String[]` | `argumentNameArray()`
    `protected String` | `byteOffsetArgName(int i)`
    `protected String` | `byteOffsetArrayArgName(int i)`
    `protected static String` | `cThisArgumentName()`
    `protected int` | `emitArguments(PrintWriter writer)` Returns the number of arguments emitted.
    `protected void` | `emitBody(PrintWriter writer)`
    `protected void` | `emitBodyCallCFunction(PrintWriter writer)`
    `protected int` | `emitBodyPassCArguments(PrintWriter writer)` Returns the number of arguments passed so calling code knows whether to print a comma
    `protected void` | `emitBodyReturnResult(PrintWriter writer)`
    `protected void` | `emitBodyUserVariableAssignments(PrintWriter writer)` Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the .cfg file.
    `protected void` | `emitBodyUserVariableDeclarations(PrintWriter writer)` Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in the .cfg file.
    `protected void` | `emitBodyVariableDeclarations(PrintWriter writer)`
    `protected void` | `emitBodyVariablePostCallCleanup(PrintWriter writer)` Code to clean up any variables that were declared in emitBodyVariableDeclarations(), AFTER calling the actual C function.
    `protected void` | `emitBodyVariablePreCallSetup(PrintWriter writer)` Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the actual C function.
    `protected void` | `emitName(PrintWriter writer)`
    `protected void` | `emitReturnType(PrintWriter writer)`
    `boolean` | `forIndirectBufferAndArrayImplementation()` Is this CMethodBindingEmitter implementing the case of an indirect buffer or array being passed down to C code?
    `MethodBinding` | `getBinding()`
    `protected String` | `getImplSuffix()`
    `boolean` | `getIsJavaMethodStatic()` Is the Java side of the Java<->C JNI binding for this emitter's MethodBinding a static method?.
    `boolean` | `getIsOverloadedBinding()` Is the Java<->C JNI binding for this emitter's MethodBinding one of several overloaded methods with the same name?
    `String` | `getJavaClassName()` Get the name of the package in which the corresponding Java method resides.
    `String` | `getJavaPackageName()` Get the name of the class in which the corresponding Java method resides.
    `MachineDescription` | `getMachineDescription()` Used for certain internal type size computations
    `String` | `getName()`
    `MessageFormat` | `getReturnValueCapacityExpression()` Get the expression for the capacity of the returned java.nio.Buffer.
    `MessageFormat` | `getReturnValueLengthExpression()` Get the expression for the length of the returned array
    `List<String>` | `getTemporaryCVariableAssignments()` Returns the List of Strings containing assignments for temporary C variables which are made after the underlying function call.
    `List<String>` | `getTemporaryCVariableDeclarations()` Returns the List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.
    `protected String` | `isNIOArgName(int i)`
    `protected String` | `isNIOArgName(String s)`
    `protected boolean` | `isUTF8Type(Type type)` Checks a type to see whether it is for a UTF-8 pointer type (i.e., "const char *", "const char **").
    `protected boolean` | `javaArgTypeNeedsDataCopy(JavaType javaArgType)`
    `protected void` | `jniMangle(Class<?> c, StringBuilder res, boolean syntheticArgument)`
    `protected String` | `jniMangle(MethodBinding binding)`
    `protected String` | `pointerConversionArgumentName(String argName)`
    `protected void` | `setIsCStructFunctionPointer(boolean v)` If method originates from a struct, see `MethodBinding.hasContainingType()`, it can either purposed to call a native static function (default) or a struct's function pointer.
    `void` | `setReturnValueCapacityExpression(MessageFormat expression)` If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper), sets the expression for the capacity of the returned Buffer.
    `void` | `setReturnValueLengthExpression(MessageFormat expression)` If this function returns an array, sets the expression for the length of the returned array.
    `void` | `setTemporaryCVariableAssignments(List<String> arg)` Sets up a List of Strings containing assignments for temporary C variables which are made after the underlying function call.
    `void` | `setTemporaryCVariableDeclarations(List<String> arg)` Sets up a List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.

    - ### Methods inherited from class com.jogamp.gluegen.FunctionEmitter

      `addModifier, addModifiers, clearModifiers, emit, emit, emitDocComment, emitModifiers, emitSignature, getBaseIndentString, getCommentEmitter, getCommentEndString, getCommentStartString, getDefaultOutput, getModifiers, hasModifier, isBaseTypeConst, isInterface, removeModifier, setCommentEmitter, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### LOG

          protected static final Logger LOG

    - #### defaultCommentEmitter

          protected static final CommentEmitter defaultCommentEmitter

    - #### arrayResLength

          protected static final String arrayResLength

      See Also:
        Constant Field Values

    - #### arrayRes

          protected static final String arrayRes

      See Also:
        Constant Field Values

    - #### arrayIdx

          protected static final String arrayIdx

      See Also:
        Constant Field Values

    - #### binding

          protected MethodBinding binding

    - #### forImplementingMethodCall

          protected boolean forImplementingMethodCall

    - #### forIndirectBufferAndArrayImplementation

          protected boolean forIndirectBufferAndArrayImplementation

    - #### STRING_CHARS_PREFIX

          protected static final String STRING_CHARS_PREFIX

      See Also:
        Constant Field Values

    - #### machDesc

          protected MachineDescription machDesc

  - ### Constructor Detail

    - #### CMethodBindingEmitter

          public CMethodBindingEmitter(MethodBinding binding,
                               PrintWriter output,
                               String javaPackageName,
                               String javaClassName,
                               boolean isOverloadedBinding,
                               boolean isJavaMethodStatic,
                               boolean forImplementingMethodCall,
                               boolean forIndirectBufferAndArrayImplementation,
                               MachineDescription machDesc)

      Constructs an emitter for the specified binding, and sets a default comment emitter that will emit the signature of the C function that is being bound.

  - ### Method Detail

    - #### getBinding

          public final MethodBinding getBinding()

    - #### getName

          public String getName()

      Specified by:
        `getName` in class `FunctionEmitter`

    - #### getReturnValueCapacityExpression

          public final MessageFormat getReturnValueCapacityExpression()

      Get the expression for the capacity of the returned java.nio.Buffer.

    - #### setReturnValueCapacityExpression

          public final void setReturnValueCapacityExpression(MessageFormat expression)

      If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper), sets the expression for the capacity of the returned Buffer.
      Parameters:
        `expression` - a MessageFormat which, when applied to an array of type String[] that contains each of the arguments names of the Java-side binding, returns an expression that will (when compiled by a C compiler) evaluate to an integer-valued expression. The value of this expression is the capacity of the java.nio.Buffer returned from this method.
      Throws:
        `IllegalArgumentException` - if the `binding.getJavaReturnType().isNIOBuffer() == false and binding.getJavaReturnType().isCompoundTypeWrapper() == false`

    - #### getReturnValueLengthExpression

          public final MessageFormat getReturnValueLengthExpression()

      Get the expression for the length of the returned array

    - #### setReturnValueLengthExpression

          public final void setReturnValueLengthExpression(MessageFormat expression)

      If this function returns an array, sets the expression for the length of the returned array.
      Parameters:
        `expression` - a MessageFormat which, when applied to an array of type String[] that contains each of the arguments names of the Java-side binding, returns an expression that will (when compiled by a C compiler) evaluate to an integer-valued expression. The value of this expression is the length of the array returned from this method.
      Throws:
        `IllegalArgumentException` - if the `binding.getJavaReturnType().isNIOBuffer() == false`

    - #### getTemporaryCVariableDeclarations

          public final List<String> getTemporaryCVariableDeclarations()

      Returns the List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.

    - #### setTemporaryCVariableDeclarations

          public final void setTemporaryCVariableDeclarations(List<String> arg)

      Sets up a List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call. A null argument indicates that no manual declarations are to be made.

    - #### getTemporaryCVariableAssignments

          public final List<String> getTemporaryCVariableAssignments()

      Returns the List of Strings containing assignments for temporary C variables which are made after the underlying function call. A null argument indicates that no manual assignments are to be made.

    - #### setTemporaryCVariableAssignments

          public final void setTemporaryCVariableAssignments(List<String> arg)

      Sets up a List of Strings containing assignments for temporary C variables which are made after the underlying function call. A null argument indicates that no manual assignments are to be made.

    - #### getJavaPackageName

          public String getJavaPackageName()

      Get the name of the class in which the corresponding Java method resides.

    - #### getJavaClassName

          public String getJavaClassName()

      Get the name of the package in which the corresponding Java method resides.

    - #### getIsOverloadedBinding

          public final boolean getIsOverloadedBinding()

      Is the Java<->C JNI binding for this emitter's MethodBinding one of several overloaded methods with the same name?

    - #### getIsJavaMethodStatic

          public final boolean getIsJavaMethodStatic()

      Is the Java side of the Java<->C JNI binding for this emitter's MethodBinding a static method?.

    - #### forIndirectBufferAndArrayImplementation

          public final boolean forIndirectBufferAndArrayImplementation()

      Is this CMethodBindingEmitter implementing the case of an indirect buffer or array being passed down to C code?

    - #### getMachineDescription

          public final MachineDescription getMachineDescription()

      Used for certain internal type size computations

    - #### emitReturnType

          protected void emitReturnType(PrintWriter writer)

      Specified by:
        `emitReturnType` in class `FunctionEmitter`

    - #### emitName

          protected void emitName(PrintWriter writer)

      Specified by:
        `emitName` in class `FunctionEmitter`

    - #### getImplSuffix

          protected String getImplSuffix()

    - #### emitArguments

          protected int emitArguments(PrintWriter writer)

      Description copied from class: `FunctionEmitter`
      Returns the number of arguments emitted.
      Specified by:
        `emitArguments` in class `FunctionEmitter`

    - #### emitBody

          protected void emitBody(PrintWriter writer)

      Specified by:
        `emitBody` in class `FunctionEmitter`

    - #### emitBodyVariableDeclarations

          protected void emitBodyVariableDeclarations(PrintWriter writer)

    - #### emitBodyUserVariableDeclarations

          protected void emitBodyUserVariableDeclarations(PrintWriter writer)

      Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in the .cfg file.

    - #### isUTF8Type

          protected boolean isUTF8Type(Type type)

      Checks a type to see whether it is for a UTF-8 pointer type (i.e., "const char *", "const char **"). False implies that this type is for a Unicode pointer type ("jchar *", "jchar **").

    - #### emitBodyVariablePreCallSetup

          protected void emitBodyVariablePreCallSetup(PrintWriter writer)

      Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the actual C function.

    - #### emitBodyVariablePostCallCleanup

          protected void emitBodyVariablePostCallCleanup(PrintWriter writer)

      Code to clean up any variables that were declared in emitBodyVariableDeclarations(), AFTER calling the actual C function.

    - #### emitBodyPassCArguments

          protected int emitBodyPassCArguments(PrintWriter writer)

      Returns the number of arguments passed so calling code knows whether to print a comma

    - #### setIsCStructFunctionPointer

          protected void setIsCStructFunctionPointer(boolean v)

      If method originates from a struct, see `MethodBinding.hasContainingType()`, it can either purposed to call a native static function (default) or a struct's function pointer.

    - #### emitBodyCallCFunction

          protected void emitBodyCallCFunction(PrintWriter writer)

    - #### emitBodyUserVariableAssignments

          protected void emitBodyUserVariableAssignments(PrintWriter writer)

      Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the .cfg file.

    - #### emitBodyReturnResult

          protected void emitBodyReturnResult(PrintWriter writer)

    - #### cThisArgumentName

          protected static String cThisArgumentName()

    - #### jniMangle

          protected String jniMangle(MethodBinding binding)

    - #### jniMangle

          protected void jniMangle(Class<?> c,
                       StringBuilder res,
                       boolean syntheticArgument)

    - #### byteOffsetArgName

          protected String byteOffsetArgName(int i)

    - #### isNIOArgName

          protected String isNIOArgName(int i)

    - #### isNIOArgName

          protected String isNIOArgName(String s)

    - #### byteOffsetArrayArgName

          protected String byteOffsetArrayArgName(int i)

    - #### argumentNameArray

          protected String[] argumentNameArray()

    - #### pointerConversionArgumentName

          protected String pointerConversionArgumentName(String argName)

    - #### javaArgTypeNeedsDataCopy

          protected boolean javaArgTypeNeedsDataCopy(JavaType javaArgType)