2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
21 class _DLL_EXPORT JObject {
24 int id; /* zero when this$ is a weak ref */
26 inline explicit JObject(jobject obj)
31 this$ = env->newGlobalRef(obj, id);
40 inline JObject(const JObject& obj)
42 id = obj.id ? obj.id : env->id(obj.this$);
43 this$ = env->newGlobalRef(obj.this$, id);
48 this$ = env->deleteGlobalRef(this$, id);
55 jobject ref = env->newGlobalRef(this$, 0);
57 env->deleteGlobalRef(this$, id);
65 inline int operator!() const
67 return env->isSame(this$, NULL);
70 inline int operator==(const JObject& obj) const
72 return env->isSame(this$, obj.this$);
75 JObject& operator=(const JObject& obj)
78 int objid = obj.id ? obj.id : env->id(obj.this$);
80 this$ = env->newGlobalRef(obj.this$, objid);
81 env->deleteGlobalRef(prev, id);
100 extern PyTypeObject PY_TYPE(JObject);
105 #endif /* _JObject_H */