简体   繁体   English

具有C ++中的自定义值和构造函数的Java类型枚举

[英]Java-type enum with custom values and constructor in C++

I have this Java enum that I need to interface with: 我有此Java enum需要与之交互:

// Parameter.java
public enum Parameter {
    ExampleParameter1(45920L, 3, 127, ValueFormat.BINARY,       true),
    ExampleParameter2(45703L, 6, 6,   ValueFormat.NUMERIC,      true),
    ExampleParameter3(73L,    4, 4,   ValueFormat.ALPHANUMERIC, true),
    ExampleParameter3(4512L,  2, 11,  ValueFormat.ALPHANUMERIC, true);

    ( . . . )

    private ValueFormat a
    private int b;
    private long c;
    private boolean d;

    private Parameter(long tag, int param, int min, ValueFormat format, boolean boo)
    {
        this.a = format;
        this.b = min;
        this.c = tag;
        this.d = boo;
    }
}

I would like to generated a valid C++ <-> Java interface using Djinni, but since djinni 's enums generate public enum in Java (correct in my case) and enum class in C++ (with int underlying type), it can't work. 我想使用Djinni生成有效的C ++ <-> Java接口,但是由于djinnipublic enum在Java中生成public enum (在我的情况下是正确的)和C ++中的enum class (具有int底层类型),因此无法正常工作。

Is this even possible? 这有可能吗? Or do I have to create a Djinni interface with Java and C++ implementation with manually-made "bindings"? 还是我必须使用Java和C ++实现以及手动创建的“绑定”来创建Djinni interface

Thanks in advance for any help. 在此先感谢您的帮助。

This kind of enum containing many fields is a pretty unique concept to Java, while Djinni exposes the concept which is common across all languages, which supports an enum which has only an int value. 这种包含许多字段的enum对Java是一个非常独特的概念,而Djinni公开了在所有语言中通用的概念,该概念支持仅具有int值的枚举。 If what you want is an object which contains multiple fields of various types, in Djinni you'll want a record . 如果您想要的是一个包含多个不同类型字段的对象,那么在Djinni中,您将需要一个record You can use an interface if you want to expose methods for custom behavior, but shouldn't need to for pure data. 如果要公开用于自定义行为的方法,则可以使用接口,但对于纯数据则不需要。

In any case, Djinni generates its own types. 无论如何,Djinni都会生成自己的类型。 It's not intended to directly expose existing types into other languages, so you'll need to write your own conversion function to turn your Parameter into a Djinni record, if you don't want to use the record directly. 它不打算直接将现有类型公开为其他语言,因此,如果您不想直接使用该记录,则需要编写自己的转换函数以将Parameter转换为Djinni记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM