Class TypeMapper

java.lang.Object
ca.weblite.objc.TypeMapper
All Implemented Interfaces:
TypeMapping

public class TypeMapper extends Object implements TypeMapping
Maps Objective-C types to Java types. This provides automatic conversion to message inputs and outputs (unless coercion is disabled in the message request). In many cases, it just passes the values straight through (e.g. primitive types. Notably, Java Strings are mapped to NSStrings if the signature of the argument context is an NSString, and NSObjects are mapped as Proxy wrapper objects.
  • Field Details

    • INSTANCE

      public static final TypeMapper INSTANCE
      Singleton instance of the TypeMapper
  • Method Details

    • getInstance

      public static TypeMapper getInstance()
      Obtains the singleton instance of the TypeMapper, i.e. INSTANCE.
      Returns:
      singleton TypeMapper object.
    • cToJ

      public Object cToJ(Object cVar, String signature, TypeMapping root)
      Converts a C variable to the corresponding Java variable given the context of the specified signature. Converts a C variable to the corresponding Java type based on the specified signature. By default, this will map scalars straight across without change. Strings are mapped to NSStrings.
      Specified by:
      cToJ in interface TypeMapping
      Parameters:
      cVar - The C variable to be converted.
      signature - The signature that tells what type of variable we are dealing with according to Objective-C Type Encoding conventions.
      root - The root TypeMapping object
      Returns:
      The converted Java object.
    • jToC

      public Object jToC(Object jVar, String signature, TypeMapping root)
      Converts a Java variable to the corresponding Java variable given the context of the specified signature. Converts a Java variable to the corresponding C type based on the specified signature. By default, this will map scalars straight across without change. Strings are mapped to NSStrings.

      Example Usage

      The following is a modified snippet from the NSObject class that shows (roughly) how the jToC method is used to take the output of a Java method and set the return value in an NSInvocation object to a corresponding C type.:

      Specified by:
      jToC in interface TypeMapping
      Parameters:
      jVar - The Java variable to be converted.
      signature - The signature that tells what type of variable we are dealing with according to Objective-C Type Encoding conventions.
      root - a TypeMapping object.
      Returns:
      The converted C variable