Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <AdblockPlus.h> | 18 #include <AdblockPlus.h> |
19 #include "Utils.h" | 19 #include "Utils.h" |
20 #include "JniJsValue.h" | 20 #include "JniJsValue.h" |
21 | 21 |
22 static AdblockPlus::Filter* GetFilterPtr(jlong ptr) | 22 static AdblockPlus::Filter* GetFilterPtr(jlong ptr) |
23 { | 23 { |
24 return JniLongToTypePtr<AdblockPlus::FilterPtr>(ptr)->get(); | 24 return JniLongToTypePtr<AdblockPlus::FilterPtr>(ptr)->get(); |
25 } | |
26 | |
27 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsValue) | |
28 { | |
29 try | |
30 { | |
31 AdblockPlus::JsValue *jsValuePtr = JniGetJsValue(jsValue); | |
32 return JniPtrToLong(new AdblockPlus::FilterPtr( | |
33 new AdblockPlus::Filter(std::move(*jsValuePtr)))); | |
sergei
2016/08/30 09:45:57
What about using of
return JniPtrToLong(new Adbloc
sergei
2016/08/30 10:07:31
Even better without affecting address arithmetic
r
anton
2016/08/30 10:57:29
Done.
| |
34 } | |
35 CATCH_THROW_AND_RETURN(env, 0) | |
36 } | 25 } |
37 | 26 |
38 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) | 27 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) |
39 { | 28 { |
40 AdblockPlus::Filter::Type type; | 29 AdblockPlus::Filter::Type type; |
41 try | 30 try |
42 { | 31 { |
43 type = GetFilterPtr(ptr)->GetType(); | 32 type = GetFilterPtr(ptr)->GetType(); |
44 } | 33 } |
45 CATCH_THROW_AND_RETURN(env, 0) | 34 CATCH_THROW_AND_RETURN(env, 0) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 | 97 |
109 try | 98 try |
110 { | 99 { |
111 return *me == *other ? JNI_TRUE : JNI_FALSE; | 100 return *me == *other ? JNI_TRUE : JNI_FALSE; |
112 } | 101 } |
113 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | 102 CATCH_THROW_AND_RETURN(env, JNI_FALSE) |
114 } | 103 } |
115 | 104 |
116 static JNINativeMethod methods[] = | 105 static JNINativeMethod methods[] = |
117 { | 106 { |
118 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, | |
119 { (char*)"getType", (char*)"(J)" TYP("Filter$Type"), (void*)JniGetType }, | 107 { (char*)"getType", (char*)"(J)" TYP("Filter$Type"), (void*)JniGetType }, |
120 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed }, | 108 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed }, |
121 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList }, | 109 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList }, |
122 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList }, | 110 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList }, |
123 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals } | 111 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals } |
124 }; | 112 }; |
125 | 113 |
126 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Filter_reg isterNatives(JNIEnv *env, jclass clazz) | 114 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Filter_reg isterNatives(JNIEnv *env, jclass clazz) |
127 { | 115 { |
128 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 116 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
129 } | 117 } |
LEFT | RIGHT |