Annotation Interface CEnum


@Retention(RUNTIME) @Target(TYPE) public @interface CEnum
Annotation to import a C enumeration to Java. In C, enumeration values are plain integer constants. In Java, enumeration values are object constants. Therefore, the Java enumeration value cannot just represent the C value, as it is done for CConstant. Instead, the Java enumeration with this annotation can define the following methods to convert between C and Java values:
  • An instance method annotated with CEnumValue to convert the Java object value to the C integer value.
  • A static method annotated with CEnumLookup to retrieve the Java object value from a C integer value.
The Java enumeration values can be annotated with CEnumConstant to specify the C enumeration value. This annotation is optional and only needed if an attribute has a non-default value.

Note that in C, the keyword "enum" is merely a type-safe way to specify integer constants. Therefore, it is also possible to import C enumeration values as regular CConstants into Java.

CEnum can also be used to import multiple (potentially unrelated) regular integer C constants into a single Java enumeration. However, please note that each C constant will be converted to the C type that CEnum specifies.

The annotated class, or an outer class that contains the class, must be annotated with CContext.

Since:
19.0
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Add the C enum keyword to the name specified in value().
    Specifies the name of the imported C enum type.
  • Element Details

    • value

      String value
      Specifies the name of the imported C enum type. If no name is provided, the C data type int is used instead.
      Since:
      19.0
      Default:
      ""
    • addEnumKeyword

      boolean addEnumKeyword
      Add the C enum keyword to the name specified in value().
      Since:
      19.0
      Default:
      false