2

What is the difference between @MemberGetter and @ValueGetter annotations in JavaCPP?

What are the use cases for them?

I have C header file with two constants

static const int TRANSPOSE = 0;
static const int NO_TRANSPOSE = 1;

What is the prefferred way to get their values at Java side?


UPDATE:

I've read JavaCPP Generator source code, done some experiments and ended up doing this in both ways and both are working. Here's java sample (see our github project for more).

private static native @MemberGetter @Const int TRANSPOSE();
private static native @ValueGetter @Const int NO_TRANSPOSE();

But I still do not know what are the differences. Both annotations produced same C++ code.

JNIEXPORT jint JNICALL Java_com_rtbhouse_model_natives_NeuralNetworkNativeOps_TRANSPOSE(JNIEnv* env, jclass cls) {
    jint rarg = 0;
    const int rvalue = (const int)TRANSPOSE;
    rarg = (jint)rvalue;
    return rarg;
}

JNIEXPORT jint JNICALL Java_com_rtbhouse_model_natives_NeuralNetworkNativeOps_NO_1TRANSPOSE(JNIEnv* env, jclass cls) {
    jint rarg = 0;
    const int rvalue = (const int)NO_TRANSPOSE;
    rarg = (jint)rvalue;
    return rarg;
}
tworec
  • 4,409
  • 2
  • 29
  • 34

2 Answers2

1

For global variables and macros there isn't much of any difference. In the case of classes, a pair of native get() and put() methods default to a value getter and setter, mapping to the [] operator of the pointer, usually for accessing the elements of an array. Other getter and setter pairs are for accessing fields, like native int n(); native void n(int n) are member getter and setter for the member variable int n, by default. The @ValueGetter, @ValueSetter, @MemberGetter, @MemberSetter, and @Function annotations can be used to change the default behavior and use other names for the methods.

Samuel Audet
  • 4,964
  • 1
  • 26
  • 33
0

This seems to be a relatively small open source project. I wouldn't expect that you will get much feedback when asking about such stuff here. Thus, the answer to help you resolve your question is: use a different research strategy:

  1. First of all, it is open source. Just turn to github and clone that repository and start using it. Read source code, search for those annotations, and try if you can find usages of them.
  2. Simply contact the community around that product; the most simply way ... just write an email to the main contributor of JavaCPP.

Long story short: the answer is - you need to be more "energetic" to get your answer.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • I saw a few responses from @SamuelAudet here, for example this cool post http://stackoverflow.com/a/10809123/3805131 I hope he answers also this question. If not, I'll go further :) thanks. – tworec Nov 04 '16 at 09:41