Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWIG Java cannot handle enums that are used as no-overhead strong-typing strategy #3046

Open
blauc opened this issue Oct 10, 2024 · 0 comments

Comments

@blauc
Copy link

blauc commented Oct 10, 2024

Currently, C++ strongly typed enums are mapped to java enums either unsafe, mapping directly to the underlying int type, or safe where only values that are defined in the enum are allowed. This misses the usecase of enums that are used as no-overhead strategy of introducing strongly typed integers like in std::byte.

A possible solution would be to add another enumstrongtype.swg apart fromt the already provided enumtypesafe.swg and enumtypeunsafe.swg, where enumtypesafe.swg:89 is altered in the following way:

  public static $javaclassname swigToEnum(int swigValue) {
    if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
      return swigValues[swigValue];
    for (int i = 0; i < swigValues.length; i++)
      if (swigValues[i].swigValue == swigValue)
        return swigValues[i];
    return new $javaclassname(swigValue);
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants