2 * Copyright (c) 2007-2008 Open Source Applications Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 class _DLL_EXPORT JObject {
26 int id; /* zero when this$ is a weak ref */
28 inline explicit JObject(jobject obj)
33 this$ = env->newGlobalRef(obj, id);
42 inline JObject(const JObject& obj)
44 id = obj.id ? obj.id : env->id(obj.this$);
45 this$ = env->newGlobalRef(obj.this$, id);
50 this$ = env->deleteGlobalRef(this$, id);
57 jobject ref = env->newGlobalRef(this$, 0);
59 env->deleteGlobalRef(this$, id);
67 inline int operator!() const
69 return env->isSame(this$, NULL);
72 inline int operator==(const JObject& obj) const
74 return env->isSame(this$, obj.this$);
77 JObject& operator=(const JObject& obj)
80 int objid = obj.id ? obj.id : env->id(obj.this$);
82 this$ = env->newGlobalRef(obj.this$, objid);
83 env->deleteGlobalRef(prev, id);
102 extern PyTypeObject PY_TYPE(JObject);
107 #endif /* _JObject_H */