summaryrefslogtreecommitdiff
path: root/libs/python/pyste/src/Pyste/policies.py
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-06-25 22:59:01 +0000
committer <>2013-09-27 11:49:28 +0000
commit8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch)
treec09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/python/pyste/src/Pyste/policies.py
downloadboost-tarball-baserock/morph.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/python/pyste/src/Pyste/policies.py')
-rw-r--r--libs/python/pyste/src/Pyste/policies.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/libs/python/pyste/src/Pyste/policies.py b/libs/python/pyste/src/Pyste/policies.py
new file mode 100644
index 000000000..57ebd0dea
--- /dev/null
+++ b/libs/python/pyste/src/Pyste/policies.py
@@ -0,0 +1,95 @@
+# Copyright Bruno da Silva de Oliveira 2003. Use, modification and
+# distribution is subject to the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+
+
+class Policy(object):
+ 'Represents one of the call policies of boost.python.'
+
+ def __init__(self):
+ if type(self) is Policy:
+ raise RuntimeError, "Can't create an instance of the class Policy"
+
+
+ def Code(self):
+ 'Returns the string corresponding to a instancialization of the policy.'
+ pass
+
+
+ def _next(self):
+ if self.next is not None:
+ return ', %s >' % self.next.Code()
+ else:
+ return ' >'
+
+
+ def __eq__(self, other):
+ try:
+ return self.Code() == other.Code()
+ except AttributeError:
+ return False
+
+
+
+class return_internal_reference(Policy):
+ 'Ties the return value to one of the parameters.'
+
+ def __init__(self, param=1, next=None):
+ '''
+ param is the position of the parameter, or None for "self".
+ next indicates the next policy, or None.
+ '''
+ self.param = param
+ self.next=next
+
+
+ def Code(self):
+ c = 'return_internal_reference< %i' % self.param
+ c += self._next()
+ return c
+
+
+
+class with_custodian_and_ward(Policy):
+ 'Ties lifetime of two arguments of a function.'
+
+ def __init__(self, custodian, ward, next=None):
+ self.custodian = custodian
+ self.ward = ward
+ self.next = next
+
+ def Code(self):
+ c = 'with_custodian_and_ward< %i, %i' % (self.custodian, self.ward)
+ c += self._next()
+ return c
+
+
+
+class return_value_policy(Policy):
+ 'Policy to convert return values.'
+
+ def __init__(self, which, next=None):
+ self.which = which
+ self.next = next
+
+
+ def Code(self):
+ c = 'return_value_policy< %s' % self.which
+ c += self._next()
+ return c
+
+class return_self(Policy):
+
+ def Code(self):
+ return 'return_self<>'
+
+
+# values for return_value_policy
+reference_existing_object = 'reference_existing_object'
+copy_const_reference = 'copy_const_reference'
+copy_non_const_reference = 'copy_non_const_reference'
+manage_new_object = 'manage_new_object'
+return_opaque_pointer = 'return_opaque_pointer'
+return_by_value = 'return_by_value'