cppJNI icon indicating copy to clipboard operation
cppJNI copied to clipboard

Implement access to Java fileds

Open michal-los opened this issue 8 years ago • 0 comments

It would be nice to provide direct access to Java class fields. Proposal is to provide it using special function object, which would provide overloaded operator* to C++ type, or overloaded operator. Ideally this could look like this:

//in Java class meta-declaration
MAKE_JAVA_FIELD(fieldName, String);
//Usage:
auto x = *javaObject.fieldName;

I don't like the additional operator thing, but the other options are:

  • overloaded operator -> for Java class meta-declaration - but this might be ineffective and is, in fact, inconsistent with the way that methods are called.
  • overloaded operator () for field class - this is nice, but it doesn't look like field.

BUT!

There is a problem. In order to get some object field value, we need to obtain it using object reference, which would need to be passed to all field wrappers. This complicates constructors, and probably means that rather than single macro, fields would have to be also provided via mpl::list, which I really don't like, since it's an information duplication:

//in Java class meta-declaration
MAKE_JAVA_FIELD(fieldName, String);
using fields = mpl::list<
    Field<typestring_is(fieldName), String>
>;

This probably means that we need to provide some more macrology : /. I'll think about it more I guess. Add to this also information about static/non static + final.

michal-los avatar Nov 22 '17 09:11 michal-los