Package pyplusplus :: Package decl_wrappers :: Module call_policies

Source Code for Module pyplusplus.decl_wrappers.call_policies

  1  # Copyright 2004-2008 Roman Yakovenko.
 
  2  # Distributed under the Boost Software License, Version 1.0. (See
 
  3  # accompanying file LICENSE_1_0.txt or copy at
 
  4  # http://www.boost.org/LICENSE_1_0.txt)
 
  5  
 
  6  """Contains definition of call policies classes""" 
  7  
 
  8  import algorithm 
  9  import python_traits 
 10  from pygccxml import declarations 
11 12 #keeps file name, where Py++ defined call policies will be defined 13 PYPP_CALL_POLICIES_HEADER_FILE = "__call_policies.pypp.hpp" 14 15 -class CREATION_POLICY:
16 """Implementation details""" 17 AS_INSTANCE = 'as instance' 18 AS_TEMPLATE_ARGUMENT = 'as template argument'
19
20 -class call_policy_t(object):
21 """base class for all classes, which generate "call policies" code"""
22 - def __init__(self):
23 object.__init__(self)
24
25 - def create(self, function_creator, creation_policy=CREATION_POLICY.AS_INSTANCE):
26 """Creates code from the call policies class instance. 27 @param function_creator: parent code creator 28 @type function_creator: L{code_creators.function_t} or L{code_creators.constructor_t} 29 30 @param creation_policy: indicates whether we this call policy used as template 31 argument or as an instance 32 @type creation_policy: L{CREATION_POLICY} 33 """ 34 code = self._create_impl( function_creator ) 35 if code and creation_policy == CREATION_POLICY.AS_INSTANCE: 36 code = code + '()' 37 return code
38
39 - def create_type(self):
40 """return call policies class declaration as string""" 41 return self.create( None, CREATION_POLICY.AS_TEMPLATE_ARGUMENT )
42
43 - def create_template_arg( self, function_creator ):
44 """return call policies class declaration as string""" 45 return self.create( function_creator, CREATION_POLICY.AS_TEMPLATE_ARGUMENT )
46
47 - def is_default( self ):
48 """return True is self is instance of L{default_call_policies_t} class""" 49 return False
50
51 - def is_predefined( self ):
52 """return True if call policy is defined in Boost.Python library, False otherwise""" 53 return True
54
55 - def _create_impl( self, function_creator ):
56 raise NotImplementedError()
57 58 @property
59 - def header_file(self):
60 """return a name of the header file the call policy is defined in""" 61 return "boost/python.hpp"
62
63 -class default_call_policies_t(call_policy_t):
64 """implements code generation for boost::python::default_call_policies"""
65 - def __init__( self ):
66 call_policy_t.__init__( self )
67
68 - def _create_impl(self, function_creator ):
69 return algorithm.create_identifier( function_creator, '::boost::python::default_call_policies' )
70
71 - def is_default( self ):
72 return True
73
74 - def __str__(self):
75 return 'default_call_policies'
76
77 -def default_call_policies():
78 """create ::boost::python::default_call_policies call policies code generator""" 79 return default_call_policies_t()
80
81 -class compound_policy_t( call_policy_t ):
82 """base class for all call policies, except the default one"""
83 - def __init__( self, base=None ):