Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/pyste/src/Pyste/policies.py @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.3 KB
Line 
1# Copyright Bruno da Silva de Oliveira 2003. Use, modification and
2# distribution is subject to the Boost Software License, Version 1.0.
3# (See accompanying file LICENSE_1_0.txt or copy at
4# http:#www.boost.org/LICENSE_1_0.txt)
5
6
7
8class Policy(object):
9    'Represents one of the call policies of boost.python.'
10
11    def __init__(self):
12        if type(self) is Policy:
13            raise RuntimeError, "Can't create an instance of the class Policy"
14
15
16    def Code(self):
17        'Returns the string corresponding to a instancialization of the policy.'
18        pass
19       
20
21    def _next(self):
22        if self.next is not None:
23            return ', %s >' % self.next.Code()
24        else:
25            return ' >'
26
27
28    def __eq__(self, other):
29        try:
30            return self.Code() == other.Code()
31        except AttributeError:
32            return False
33
34
35
36class return_internal_reference(Policy):
37    'Ties the return value to one of the parameters.'
38
39    def __init__(self, param=1, next=None):
40        '''
41        param is the position of the parameter, or None for "self".
42        next indicates the next policy, or None.
43        '''
44        self.param = param
45        self.next=next
46
47
48    def Code(self):
49        c = 'return_internal_reference< %i' % self.param
50        c += self._next()
51        return c
52
53
54
55class with_custodian_and_ward(Policy):
56    'Ties lifetime of two arguments of a function.'
57
58    def __init__(self, custodian, ward, next=None):
59        self.custodian = custodian
60        self.ward = ward
61        self.next = next
62
63    def Code(self):
64        c = 'with_custodian_and_ward< %i, %i' % (self.custodian, self.ward)
65        c += self._next()
66        return c
67
68
69
70class return_value_policy(Policy):
71    'Policy to convert return values.'
72   
73    def __init__(self, which, next=None):           
74        self.which = which
75        self.next = next
76
77
78    def Code(self):
79        c = 'return_value_policy< %s' % self.which
80        c += self._next()
81        return c
82
83class return_self(Policy):
84
85    def Code(self):
86        return 'return_self<>'
87
88
89#  values for return_value_policy
90reference_existing_object = 'reference_existing_object'
91copy_const_reference = 'copy_const_reference'
92copy_non_const_reference = 'copy_non_const_reference'
93manage_new_object = 'manage_new_object'       
94return_opaque_pointer = 'return_opaque_pointer'
95return_by_value = 'return_by_value'
Note: See TracBrowser for help on using the repository browser.