2 * proxy.swg : SWIG include file for defining automatic proxy classes
4 * ====================================================================
5 * Copyright (c) 2000-2003 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
21 /* Note: See the big comment at the top of proxy_apr.swg for details on
22 * how this _is_valid stuff actually works. It's part of the magic
23 * that lets us gracefully handle objects that are allocated from
24 * a pool that's been cleared or destroyed.
27 /* Default code for all wrapped proxy classes in Python */
28 %define %proxy_pythoncode(TYPE)
30 def set_parent_pool(self, parent_pool=None):
31 """Create a new proxy object for TYPE"""
32 import libsvn.core, weakref
33 self.__dict__["_parent_pool"] = \
34 parent_pool or libsvn.core.application_pool;
35 if self.__dict__["_parent_pool"]:
36 self.__dict__["_is_valid"] = weakref.ref(
37 self.__dict__["_parent_pool"]._is_valid)
39 def assert_valid(self):
40 """Assert that this object is using valid pool memory"""
41 if "_is_valid" in self.__dict__:
42 assert self.__dict__["_is_valid"](), "Variable has already been deleted"
44 def __getattr__(self, name):
45 """Get an attribute from this object"""
48 value = _swig_getattr(self, self.__class__, name)
50 # Now, if this item has changed, SWIG must have generated a new object.
51 # Copy the pool metadata from the old object over to the new one.
52 members = self.__dict__.get("_members")
53 if members is not None:
54 old_value = members.get(name)
55 if (old_value is not None and value is not None and
56 value is not old_value):
58 value.__dict__.update(old_value.__dict__)
59 except AttributeError:
62 # Verify that the new object is good
63 if hasattr(value, "assert_valid"):
68 def __setattr__(self, name, value):
69 """Set an attribute on this object"""
72 # Save a copy of the object, so that the garbage
73 # collector won't kill the object while it's in
75 self.__dict__.setdefault("_members",{})[name] = value
77 return _swig_setattr(self, self.__class__, name, value)
81 /* Define a proxy for wrapping an existing struct */
84 %proxy_pythoncode(TYPE);
88 /* Define a proxy class for wrapping an opaque struct */
89 %define %opaque_proxy(TYPE)
92 %proxy_pythoncode(TYPE);
97 /* Treat typemapped function pointers as objects, which have a bound
98 * __call__ method. This mapping depends on the function pointer being
99 * typemapped as a CALLABLE_CALLBACK. */
100 %define %funcptr_proxy(TYPE, INVOKE)
104 %proxy_pythoncode(TYPE);
106 def __call__(self, *args):
107 return INVOKE(self, *args)
114 /* Add member functions to objects so that their function pointers can
117 * Unlike the CALLABLE_CALLBACKS, these member functions don't have or
118 * need typemaps, because the underlying C/SWIG object for the callback
121 %define %funcptr_member_proxy(TYPE, MEMBER, INVOKE)
124 def MEMBER(self, *args):
125 return INVOKE(self, *args)