diff --git a/examples/AndroidMath/AndroidMath.cpp b/examples/AndroidMath/AndroidMath.cpp index 4a4a1d88c..5c2347855 100644 --- a/examples/AndroidMath/AndroidMath.cpp +++ b/examples/AndroidMath/AndroidMath.cpp @@ -3,21 +3,15 @@ #include -#ifdef __cplusplus extern "C" { -#endif -/* - * Class: org_upp_AndroidMath_AndroidMath - * Method: power - * Signature: (II)I - */ -JNIEXPORT jint JNICALL Java_org_upp_AndroidMath_AndroidMath_power - (JNIEnv *, jclass, jint number, jint n) -{ - return AndroidMathUtility::Power(number, n); -} + JNIEXPORT jint JNICALL Java_org_upp_AndroidMath_AndroidMath_power( + JNIEnv *, + jclass, + jint number, + jint n) + { + return AndroidMathUtility::Power(number, n); + } -#ifdef __cplusplus -} -#endif +} // extern "C" diff --git a/examples/AndroidMath/AndroidMath.java b/examples/AndroidMath/AndroidMath.java index b268052e7..1371e89ac 100644 --- a/examples/AndroidMath/AndroidMath.java +++ b/examples/AndroidMath/AndroidMath.java @@ -1,5 +1,8 @@ package org.upp.AndroidMath; +/** + * Native math functions from package AndroidMathUtility. + */ public class AndroidMath { private AndroidMath() {} diff --git a/examples/AndroidMath/MemoryManager.h b/examples/AndroidMath/MemoryManager.h index 5d0dc238f..2bd41311b 100644 --- a/examples/AndroidMath/MemoryManager.h +++ b/examples/AndroidMath/MemoryManager.h @@ -1,8 +1,6 @@ #ifndef _JniMath_MemoryManager_h_ #define _JniMath_MemoryManager_h_ -#include - #include #include #include diff --git a/examples/AndroidMath/Vector.cpp b/examples/AndroidMath/Vector.cpp index 0c5b3da23..15e1ac392 100644 --- a/examples/AndroidMath/Vector.cpp +++ b/examples/AndroidMath/Vector.cpp @@ -1,6 +1,3 @@ -#ifndef _Included_org_upp_AndroidMath_Vector -#define _Included_org_upp_AndroidMath_Vector - #include #include #include @@ -11,112 +8,80 @@ #include "MemoryManager.h" -#ifdef __cplusplus -extern "C" { -#endif - using AndroidMathUtility::Vector; static MemoryManager mm; -/* - * Class: org_upp_AndroidMath_Vector - * Method: construct - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_construct - (JNIEnv *env, jobject obj, jint size) -{ - mm.Insert(env, obj, new Vector(size)); -} +extern "C" { -/* - * Class: org_upp_AndroidMath_Vector - * Method: copyConstruct - * Signature: (Lorg/upp/AndroidMath/Vector;)V - */ -JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_copyConstruct - (JNIEnv *env, jobject jobjThis, jobject jobjThat) -{ - mm.MakeCopy(env, jobjThis, jobjThat); -} + JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_construct( + JNIEnv *env, + jobject obj, + jint size) + { + mm.Insert(env, obj, new Vector(size)); + } -/* - * Class: org_upp_AndroidMath_Vector - * Method: destruct - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_nativeFinalize - (JNIEnv *env, jobject obj) -{ - mm.Erase(env, obj); -} + JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_copyConstruct( + JNIEnv *env, + jobject jobjThis, + jobject jobjThat) + { + mm.MakeCopy(env, jobjThis, jobjThat); + } -/* - * Class: org_upp_AndroidMath_Vector - * Method: getSize - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_org_upp_AndroidMath_Vector_getSize - (JNIEnv *env, jobject obj) -{ - Vector* vec = mm.Get(env, obj); + JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_nativeFinalize( + JNIEnv *env, + jobject obj) + { + mm.Erase(env, obj); + } - return vec->GetSize(); -} + JNIEXPORT jint JNICALL Java_org_upp_AndroidMath_Vector_getSize( + JNIEnv *env, + jobject obj) + { + Vector* vec = mm.Get(env, obj); + + return vec->GetSize(); + } -/* - * Class: org_upp_AndroidMath_Vector - * Method: get - * Signature: (I)F - */ -JNIEXPORT jfloat JNICALL Java_org_upp_AndroidMath_Vector_get - (JNIEnv *env, jobject obj, jint id) -{ - Vector* vec = mm.Get(env, obj); + JNIEXPORT jfloat JNICALL Java_org_upp_AndroidMath_Vector_get( + JNIEnv *env, + jobject obj, + jint id) + { + Vector* vec = mm.Get(env, obj); + + return vec->Get(id); + } - return vec->Get(id); -} - -/* - * Class: org_upp_AndroidMath_Vector - * Method: set - * Signature: (IF)V - */ -JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_set - (JNIEnv *env, jobject obj, jint id, jfloat value) -{ - Vector* vec = mm.Get(env, obj); - vec->Set(id, value); -} - -/* - * Class: org_upp_AndroidMath_Vector - * Method: multipleByScalar - * Signature: (F)V - */ -JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_multipleByScalar - (JNIEnv *env, jobject obj, jfloat scalar) -{ - Vector* vec = mm.Get(env, obj); - vec->MultipleByScalar(scalar); -} - -/* - * Class: org_upp_AndroidMath_Vector - * Method: toStirng - * Signature: ()Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_upp_AndroidMath_Vector_toString - (JNIEnv *env, jobject obj) -{ - Vector* vec = mm.Get(env, obj); + JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_set( + JNIEnv *env, + jobject obj, + jint id, + jfloat value) + { + Vector* vec = mm.Get(env, obj); + vec->Set(id, value); + } - return env->NewStringUTF((vec->ToString()).c_str()); -} + JNIEXPORT void JNICALL Java_org_upp_AndroidMath_Vector_multipleByScalar( + JNIEnv *env, + jobject obj, + jfloat scalar) + { + Vector* vec = mm.Get(env, obj); + vec->MultipleByScalar(scalar); + } + + JNIEXPORT jstring JNICALL Java_org_upp_AndroidMath_Vector_toString( + JNIEnv *env, + jobject obj) + { + Vector* vec = mm.Get(env, obj); + + return env->NewStringUTF((vec->ToString()).c_str()); + } -#ifdef __cplusplus -} -#endif - -#endif +} // extern "C" diff --git a/examples/AndroidMath/Vector.java b/examples/AndroidMath/Vector.java index ae31d007e..bf56c8006 100644 --- a/examples/AndroidMath/Vector.java +++ b/examples/AndroidMath/Vector.java @@ -1,7 +1,7 @@ package org.upp.AndroidMath; /** - * Class which whole funtional implementaiton is native. + * Math vector class which whole implementaiton is native (c/c++). */ public class Vector { @@ -13,7 +13,9 @@ public class Vector private long nativeAdress = 0; /** - * We override finalize method, beacuse we need to destroy native c++ object. + * We override finalize method, because we need to destroy native c++ object when + * there is not more reference to Java object. This method is called by default + * by garbage collector. */ @Override protected void finalize() throws Throwable