%module BanditWorld %inline %{ typedef struct { double value; } Reward; typedef struct { int value; } State; %} %{ #include "BanditWorld.h" %} /* Typemap for Reward */ %typemap(in) reward_t *OUTVALUE { jclass clazz = (*jenv)->FindClass(jenv, "Reward"); jfieldID fid = (*jenv)->GetFieldID(jenv, clazz, "swigCPtr", "J"); jlong cPtr = (*jenv)->GetLongField(jenv, $input, fid); Reward *pReward = NULL; *(Reward **)&pReward = *(Reward **)&cPtr; $1 = &pReward->value; } %typemap(jtype) reward_t *OUTVALUE "Reward" %typemap(jstype) reward_t *OUTVALUE "Reward" %typemap(jni) reward_t *OUTVALUE "jobject" %typemap(javain) reward_t *OUTVALUE "$javainput" /* Typemap for State */ %typemap(in) state_t *OUTVALUE { jclass clazz = (*jenv)->FindClass(jenv, "State"); jfieldID fid = (*jenv)->GetFieldID(jenv, clazz, "swigCPtr", "J"); jlong cPtr = (*jenv)->GetLongField(jenv, $input, fid); State *pState = NULL; *(State **)&pState = *(State **)&cPtr; $1 = &pState->value; } %typemap(jtype) state_t *OUTVALUE "State" %typemap(jstype) state_t *OUTVALUE "State" %typemap(jni) state_t *OUTVALUE "jobject" %typemap(javain) state_t *OUTVALUE "$javainput" /* Apply typemaps */ %apply int { uint32_t }; %apply int { state_t }; %apply int { action_t }; %apply reward_t *OUTVALUE { reward_t *r }; %apply state_t *OUTVALUE { state_t *s }; extern state_t make_MDP(uint32_t seed, int state_count, int succ_count); extern state_t successor(action_t u); extern void act(action_t u, state_t *s, reward_t *r); extern void close_MDP();