[pygccxml-commit] SF.net SVN: pygccxml: [538] pyplusplus_dev/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-09-13 11:08:29
|
Revision: 538 http://svn.sourceforge.net/pygccxml/?rev=538&view=rev Author: roman_yakovenko Date: 2006-09-13 04:08:13 -0700 (Wed, 13 Sep 2006) Log Message: ----------- preventing default_call_policies to be generated Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/array_1_registrator.py pyplusplus_dev/pyplusplus/code_creators/calldef.py pyplusplus_dev/pyplusplus/code_creators/global_variable.py pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py Modified: pyplusplus_dev/pyplusplus/code_creators/array_1_registrator.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/array_1_registrator.py 2006-09-13 09:24:37 UTC (rev 537) +++ pyplusplus_dev/pyplusplus/code_creators/array_1_registrator.py 2006-09-13 11:08:13 UTC (rev 538) @@ -21,7 +21,7 @@ self._array_type = array_type self._call_policies = self._guess_call_policies() self.works_on_instance = False - + def _get_array_type( self ): return self._array_type def _set_array_type( self, new_array_type ): @@ -37,8 +37,8 @@ def _create_name( self ): item_type = declarations.array_item_type(self.array_type) return "__array_1_%(type)s_%(size)d" \ - % dict( type=algorithm.create_valid_name( item_type.decl_string ) - , size=declarations.array_size(self.array_type) ) + % dict( type=algorithm.create_valid_name( item_type.decl_string ) + , size=declarations.array_size(self.array_type) ) def _guess_call_policies(self): item_type = declarations.array_item_type( self.array_type ) @@ -55,8 +55,10 @@ fn_name = 'register_const_array_1' else: fn_name = 'register_array_1' - fn_def = templates.join( '::'.join( [ns_name, fn_name] ) - , [ declarations.array_item_type(self.array_type).decl_string - , str( declarations.array_size(self.array_type) ) - , self.call_policies.create(self, call_policies.CREATION_POLICY.AS_TEMPLATE_ARGUMENT )]) - return call_invocation.join( fn_def, [ '"%s"' % self._create_name() ] ) + ';' \ No newline at end of file + + fn_def_tmpl_args = [ declarations.array_item_type(self.array_type).decl_string + , str( declarations.array_size(self.array_type) ) + , self.call_policies.create(self, call_policies.CREATION_POLICY.AS_TEMPLATE_ARGUMENT )] + + fn_def = templates.join( '::'.join( [ns_name, fn_name] ), fn_def_tmpl_args ) + return call_invocation.join( fn_def, [ '"%s"' % self._create_name() ] ) + ';' Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-09-13 09:24:37 UTC (rev 537) +++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-09-13 11:08:13 UTC (rev 538) @@ -9,7 +9,7 @@ import declaration_based import class_declaration from pygccxml import declarations -from pyplusplus.decl_wrappers import python_traits +from pyplusplus import decl_wrappers import pyplusplus.function_transformers as function_transformers #virtual functions that returns const reference to something @@ -120,8 +120,11 @@ result.append( self.keywords_args() ) if self.declaration.call_policies: - result.append( self.param_sep() ) - result.append( self.declaration.call_policies.create( self ) ) + if not self.declaration.call_policies.is_default(): + result.append( self.param_sep() ) + result.append( self.declaration.call_policies.create( self ) ) + else: + pass#don't generate default_call_policies else: result.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) @@ -175,11 +178,11 @@ params = [] for index in range( len( self.declaration.arguments ) ): arg_type = declarations.remove_alias( self.declaration.arguments[index].type ) - if python_traits.is_immutable( arg_type ): + if decl_wrappers.python_traits.is_immutable( arg_type ): params.append( self.argument_name( index ) ) elif declarations.is_reference( arg_type ): no_ref = declarations.remove_reference( arg_type ) - if python_traits.is_immutable( no_ref ): + if decl_wrappers.python_traits.is_immutable( no_ref ): #pass by value params.append( self.argument_name( index ) ) else: @@ -187,7 +190,7 @@ params.append( 'boost::ref(%s)' % self.argument_name( index ) ) elif declarations.is_pointer( arg_type ) \ and not declarations.is_pointer( arg_type.base ) \ - and not python_traits.is_immutable( arg_type.base ): + and not decl_wrappers.python_traits.is_immutable( arg_type.base ): params.append( 'boost::python::ptr(%s)' % self.argument_name( index ) ) else: params.append( self.argument_name( index ) ) @@ -1130,11 +1133,8 @@ answer.append( ', ' ) answer.append( self.documentation ) answer.append( ')' ) - if self.declaration.call_policies: + if self.declaration.call_policies and not self.declaration.call_policies.is_default(): answer.append('[%s]' % self.declaration.call_policies.create( self ) ) - #I think it better not to print next line - #else: - # answer.append( '/*[ undefined call policies ]*/' ) return ''.join( answer ) def _create_impl( self ): @@ -1369,7 +1369,6 @@ def __init__( self, operator ): declaration_based.declaration_based_t.__init__( self, declaration=operator ) - self._call_policies = None def _create_impl(self): template = 'def( "%(function_name)s", &%(class_name)s::operator %(destination_type)s %(call_policies)s%(doc)s )' @@ -1377,9 +1376,12 @@ class_name = algorithm.create_identifier( self , declarations.full_name( self.declaration.parent ) ) - policies = '/*, undefined call policies */' + policies = '' if self.declaration.call_policies: - policies = ',' + self.declaration.call_policies.create( self ) + if not self.declaration.call_policies.is_default(): + policies = ',' + self.declaration.call_policies.create( self ) + else: + policies = '/*, undefined call policies */' doc = '' if self.documentation: @@ -1537,7 +1539,8 @@ result.append( os.linesep + self.indent( self.PARAM_SEPARATOR, 3 ) ) result.append( self.overloads_class.max_function.documentation ) result.append( ' )' ) - if self.overloads_class.max_function.call_policies: + if self.overloads_class.max_function.call_policies \ + and not self.overloads_class.max_function.call_policies.is_default(): result.append( os.linesep + self.indent('', 3) ) result.append('[ %s ]' % self.overloads_class.max_function.call_policies.create( self ) ) return ''.join( result ) Modified: pyplusplus_dev/pyplusplus/code_creators/global_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/global_variable.py 2006-09-13 09:24:37 UTC (rev 537) +++ pyplusplus_dev/pyplusplus/code_creators/global_variable.py 2006-09-13 11:08:13 UTC (rev 538) @@ -9,31 +9,30 @@ import declaration_based from pygccxml import declarations from pyplusplus import code_repository -from pyplusplus.decl_wrappers import call_policies #TODO: if variable is not const, then export it using boost::python::ptr class global_variable_base_t( declaration_based.declaration_based_t ): """ - Base class for all global variables code creators. Mainly exists to + Base class for all global variables code creators. Mainly exists to simplify file writers algorithms. """ def __init__(self, variable, wrapper=None ): declaration_based.declaration_based_t.__init__( self, declaration=variable) - self._wrapper = wrapper + self._wrapper = wrapper def _get_wrapper( self ): return self._wrapper def _set_wrapper( self, new_wrapper ): self._wrapper = new_wrapper wrapper = property( _get_wrapper, _set_wrapper ) - + class global_variable_t( global_variable_base_t ): """ Creates boost.python code that exposes global variable. """ def __init__(self, variable ): global_variable_base_t.__init__( self, variable=variable ) - + def _create_impl(self): assert isinstance( self.declaration, pygccxml.declarations.variable_t ) result = [] @@ -42,7 +41,7 @@ full_name = pygccxml.declarations.full_name( self.declaration ) result.append( ' = %s;' % algorithm.create_identifier( self, full_name ) ) return ''.join( result ) - + class array_gv_t( global_variable_base_t ): """ Creates boost.python code that exposes array global variable. @@ -51,7 +50,7 @@ _PARAM_SEPARATOR = ', ' def __init__(self, variable, wrapper ): global_variable_base_t.__init__( self, variable=variable, wrapper=wrapper ) - + def _create_impl( self ): answer = [] answer.append( algorithm.create_identifier( self, '::boost::python::scope' ) ) @@ -60,7 +59,7 @@ answer.append( self.wrapper.wrapper_creator_full_name ) answer.append( '();' ) return ''.join( answer ) - + class array_gv_wrapper_t( declaration_based.declaration_based_t ): """ Creates C++ code that register array class. @@ -75,22 +74,22 @@ class_name = 'const_array_1_t' else: class_name = 'array_1_t' - - decl_string = declarations.templates.join( + + decl_string = declarations.templates.join( '::'.join( [ns_name, class_name] ) , [ declarations.array_item_type( self.declaration.type ).decl_string , str( declarations.array_size( self.declaration.type ) ) ]) - + return declarations.dummy_type_t( decl_string ) wrapper_type = property( _get_wrapper_type ) - + def _get_wrapper_creator_type(self): return declarations.free_function_type_t.create_decl_string( return_type=self.wrapper_type , arguments_types=[] ) wrapper_creator_type = property( _get_wrapper_creator_type ) - + def _get_wrapper_creator_name(self): return '_'.join( [self.declaration.name, 'wrapper'] ) wrapper_creator_name = property( _get_wrapper_creator_name ) @@ -100,7 +99,7 @@ if len(ns_names) > 1 and ns_names[0] == '::': ns_names = ns_names[1:] return ns_names - + def _get_wrapper_creator_full_name(self): names = self._create_namespaces() names.append( self.wrapper_creator_name ) @@ -112,7 +111,7 @@ for ns_name in self._create_namespaces(): temp.append( ''.join( ['namespace ', ns_name, '{ '] ) ) return ''.join( temp ) - + def _create_impl( self ): answer = [self._create_namespaces_name()] answer.append( self.wrapper_type.decl_string ) @@ -126,4 +125,3 @@ answer.append('}') answer.append( '}' * len( self._create_namespaces() ) ) return os.linesep.join( answer ) - \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-09-13 09:24:37 UTC (rev 537) +++ pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-09-13 11:08:13 UTC (rev 538) @@ -5,21 +5,21 @@ import os import types -import algorithm +import algorithm import code_creator import declaration_based from pygccxml import declarations class indexing_suite1_t( declaration_based.declaration_based_t ): - def __init__(self, container ): + def __init__(self, container ): declaration_based.declaration_based_t.__init__( self, declaration=container ) - + def _get_configuration( self ): return self.declaration.indexing_suite configuration = property( _get_configuration ) def _get_container( self ): - return self.declaration + return self.declaration container = property( _get_container ) def guess_suite_name( self ): @@ -40,19 +40,19 @@ args.append( self.configuration.derived_policies ) else: if 'true' == no_proxy: - args.append( no_proxy) - return declarations.templates.join( suite_identifier, args ) + args.append( no_proxy) + return declarations.templates.join( suite_identifier, args ) def _create_impl(self): return "def( %s() )" % self._create_suite_declaration() - + class indexing_suite2_t( declaration_based.declaration_based_t ): - def __init__(self, container ): + def __init__(self, container ): declaration_based.declaration_based_t.__init__( self, declaration=container ) self.__method_mask_var_name = "methods_mask" self.works_on_instance = not self.does_user_disable_methods() - + def does_user_disable_methods( self ): return bool( self.declaration.indexing_suite.disabled_methods_groups ) \ or bool( self.declaration.indexing_suite.disable_methods ) @@ -76,7 +76,7 @@ answer.append( ' ) ' ) answer.append( ';' ) return ''.join( answer ) - + def _create_impl( self ): answer = [] if self.does_user_disable_methods(): @@ -93,8 +93,9 @@ answer.append( self.PARAM_SEPARATOR ) answer.append( self.__method_mask_var_name ) answer.append( ' >' ) - if self.declaration.indexing_suite.call_policies: - answer.append( '::with_policies(%s)' + if self.declaration.indexing_suite.call_policies \ + and not self.declaration.indexing_suite.call_policies.is_default(): + answer.append( '::with_policies(%s)' % self.declaration.indexing_suite.call_policies.create( self ) ) else: answer.append( '()' ) @@ -121,7 +122,7 @@ , self.indent( "%(less)s" ) , "" , self.indent( "template<typename PythonClass, typename Policy>" ) - , self.indent( "static void visit_container_class(PythonClass &, Policy const &){" ) + , self.indent( "static void visit_container_class(PythonClass &, Policy const &){" ) , self.indent( "%(visitor_helper_body)s", 2 ) , self.indent( "}" ) , "" @@ -147,7 +148,7 @@ def generate_value_class_fwd_declaration( self ): pass # for inner class this code will generate error :-(((( - + def _create_impl( self ): return self.generate_value_traits() Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-09-13 09:24:37 UTC (rev 537) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-09-13 11:08:13 UTC (rev 538) @@ -13,20 +13,20 @@ class member_variable_base_t( declaration_based.declaration_based_t ): """ - Base class for all member variables code creators. Mainly exists to + Base class for all member variables code creators. Mainly exists to simplify file writers algorithms. """ def __init__(self, variable, wrapper=None ): declaration_based.declaration_based_t.__init__( self, declaration=variable) - self._wrapper = wrapper + self._wrapper = wrapper def _get_wrapper( self ): return self._wrapper def _set_wrapper( self, new_wrapper ): self._wrapper = new_wrapper wrapper = property( _get_wrapper, _set_wrapper ) - + class member_variable_t( member_variable_base_t ): """ Creates boost.python code that exposes member variable. @@ -36,7 +36,7 @@ #> On Wednesday, 19. April 2006 23:05, Ralf W. Grosse-Kunstleve wrote: #> .add_property("p", make_function(&A::get_p, return_value_policy<reference_existing_object>())) - def _generate_for_pointer( self ): + def _generate_for_pointer( self ): doc = '' #static property does not support documentation if self.declaration.type_qualifiers.has_static: add_property = 'add_static_property' @@ -48,11 +48,11 @@ answer.append( '( ' ) answer.append('"%s"' % self.alias) answer.append( self.PARAM_SEPARATOR ) - + call_pol = call_policies.return_value_policy( call_policies.reference_existing_object ).create( self ) make_function = algorithm.create_identifier( self, '::boost::python::make_function' ) - answer.append( '%(mk_func)s( (%(getter_type)s)(&%(wfname)s), %(call_pol)s )' + answer.append( '%(mk_func)s( (%(getter_type)s)(&%(wfname)s), %(call_pol)s )' % { 'mk_func' : make_function , 'getter_type' : self.wrapper.getter_type , 'wfname' : self.wrapper.getter_full_name @@ -61,11 +61,10 @@ #don't generate setter method, right now I don't know how to do it. if False and self.wrapper.has_setter: answer.append( self.PARAM_SEPARATOR ) - if self.declaration.type_qualifiers.has_static: - call_pol = call_policies.default_call_policies().create(self) - else: - call_pol = call_policies.with_custodian_and_ward_postcall( 0, 1 ).create(self) - answer.append( '%(mk_func)s( (%(setter_type)s)(&%(wfname)s), %(call_pol)s )' + call_pol = '' + if not self.declaration.type_qualifiers.has_static: + call_pol = ", " + call_policies.with_custodian_and_ward_postcall( 0, 1 ).crate(self) + answer.append( '%(mk_func)s( (%(setter_type)s)(&%(wfname)s)%(call_pol)s )' % { 'mk_func' : make_function , 'setter_type' : self.wrapper.setter_type , 'wfname' : self.wrapper.setter_full_name @@ -74,7 +73,7 @@ answer.append( self.PARAM_SEPARATOR ) answer.append( doc ) answer.append( ' ) ' ) - + code = ''.join( answer ) if len( code ) <= self.LINE_LENGTH: return code @@ -82,27 +81,27 @@ for i in range( len( answer ) ): if answer[i] == self.PARAM_SEPARATOR: answer[i] = os.linesep + self.indent( self.indent( self.indent( answer[i] ) ) ) - return ''.join( answer ) - + return ''.join( answer ) + def _generate_for_none_pointer( self ): tmpl = None if self.declaration.type_qualifiers.has_static: - tmpl = '%(access)s( "%(alias)s", %(name)s%(doc)s )' + tmpl = '%(access)s( "%(alias)s", %(name)s%(doc)s )' else: tmpl = '%(access)s( "%(alias)s", &%(name)s%(doc)s )' - + access = 'def_readwrite' if self.is_read_only(): access = 'def_readonly' doc = '' if self.documentation: - doc = ', %s' % self.documentation - result = tmpl % { + doc = ', %s' % self.documentation + result = tmpl % { 'access' : access , 'alias' : self.alias , 'name' : algorithm.create_identifier( self, self.declaration.decl_string ) , 'doc' : doc } - + return result def is_read_only( self ): @@ -110,13 +109,13 @@ if declarations.is_pointer( type_ ): type_ = declarations.remove_pointer( type_ ) return isinstance( type_, declarations.const_t ) - + if declarations.is_reference( type_ ): - type_ = declarations.remove_reference( type_ ) + type_ = declarations.remove_reference( type_ ) if isinstance( type_, declarations.const_t ): return True - + if isinstance( type_, declarations.declarated_t ) \ and isinstance( type_.declaration, declarations.class_t ) \ and not declarations.has_public_assign( type_.declaration ): @@ -142,29 +141,29 @@ MV_GET_TEMPLATE = os.linesep.join([ 'static %(type)s get_%(name)s(%(cls_type)s inst ){' , indent( 'return inst.%(name)s;' ) - , '}' + , '}' , '' ]) MV_STATIC_GET_TEMPLATE = os.linesep.join([ 'static %(type)s get_%(name)s(){' , indent( 'return %(cls_type)s::%(name)s;' ) - , '}' + , '}' , '' ]) MV_SET_TEMPLATE = os.linesep.join([ 'static void set_%(name)s( %(cls_type)s inst, %(type)s new_value ){ ' , indent( 'inst.%(name)s = new_value;' ) - , '}' - , '' + , '}' + , '' ]) MV_STATIC_SET_TEMPLATE = os.linesep.join([ 'static void set_%(name)s( %(type)s new_value ){ ' , indent( '%(cls_type)s::%(name)s = new_value;' ) - , '}' - , '' + , '}' + , '' ]) def __init__(self, variable ): @@ -180,28 +179,28 @@ inst_arg_type = declarations.const_t(inst_arg_type) inst_arg_type = declarations.reference_t(inst_arg_type) return inst_arg_type - + def _get_getter_type(self): if self.declaration.type_qualifiers.has_static: - arguments_types=[] + arguments_types=[] else: - arguments_types=[ self.inst_arg_type(True) ] - + arguments_types=[ self.inst_arg_type(True) ] + return declarations.free_function_type_t.create_decl_string( return_type=self.declaration.type , arguments_types=arguments_types ) getter_type = property( _get_getter_type ) - + def _get_setter_full_name(self): return self.parent.full_name + '::' + 'set_' + self.declaration.name setter_full_name = property(_get_setter_full_name) - + def _get_setter_type(self): if self.declaration.type_qualifiers.has_static: - arguments_types=[ self.declaration.type ] + arguments_types=[ self.declaration.type ] else: - arguments_types=[ self.inst_arg_type(False), self.declaration.type ] - + arguments_types=[ self.inst_arg_type(False), self.declaration.type ] + return declarations.free_function_type_t.create_decl_string( return_type=declarations.void_t() , arguments_types=arguments_types ) @@ -210,14 +209,14 @@ def _get_has_setter( self ): return not declarations.is_const( self.declaration.type ) has_setter = property( _get_has_setter ) - + def _create_impl(self): answer = [] if self.declaration.type_qualifiers.has_static: substitutions = { 'type' : self.declaration.type.decl_string , 'name' : self.declaration.name - , 'cls_type' : declarations.full_name( self.declaration.parent ) + , 'cls_type' : declarations.full_name( self.declaration.parent ) } answer.append( self.MV_STATIC_GET_TEMPLATE % substitutions) if self.has_setter: @@ -253,18 +252,18 @@ answer.append( '( ' ) answer.append('"%s"' % self.alias) answer.append( self.PARAM_SEPARATOR ) - answer.append( '(%s)(&%s)' + answer.append( '(%s)(&%s)' % ( self.wrapper.getter_type, self.wrapper.getter_full_name ) ) if self.wrapper.has_setter: answer.append( self.PARAM_SEPARATOR ) - answer.append( '(%s)(&%s)' + answer.append( '(%s)(&%s)' % ( self.wrapper.setter_type, self.wrapper.setter_full_name ) ) if doc: answer.append( self.PARAM_SEPARATOR ) answer.append( doc ) answer.append( ' ) ' ) - + code = ''.join( answer ) if len( code ) <= self.LINE_LENGTH: return code @@ -283,15 +282,15 @@ BF_GET_TEMPLATE = os.linesep.join([ '%(type)s get_%(name)s() const {' , indent( 'return %(name)s;' ) - , '}' + , '}' , '' ]) - + BF_SET_TEMPLATE = os.linesep.join([ 'void set_%(name)s( %(type)s new_value ){ ' , indent( '%(name)s = new_value;' ) - , '}' - , '' + , '}' + , '' ]) def __init__(self, variable ): @@ -300,7 +299,7 @@ def _get_getter_full_name(self): return self.parent.full_name + '::' + 'get_' + self.declaration.name getter_full_name = property( _get_getter_full_name ) - + def _get_getter_type(self): return declarations.member_function_type_t.create_decl_string( return_type=self.declaration.type @@ -308,11 +307,11 @@ , arguments_types=[] , has_const=True ) getter_type = property( _get_getter_type ) - + def _get_setter_full_name(self): return self.parent.full_name + '::' + 'set_' + self.declaration.name setter_full_name = property(_get_setter_full_name) - + def _get_setter_type(self): return declarations.member_function_type_t.create_decl_string( return_type=declarations.void_t() @@ -324,11 +323,11 @@ def _get_has_setter( self ): return not declarations.is_const( self.declaration.type ) has_setter = property( _get_has_setter ) - + def _create_impl(self): answer = [] substitutions = dict( type=self.declaration.type.decl_string - , name=self.declaration.name ) + , name=self.declaration.name ) answer.append( self.BF_GET_TEMPLATE % substitutions ) if self.has_setter: answer.append( self.BF_SET_TEMPLATE % substitutions ) @@ -340,7 +339,7 @@ """ def __init__(self, variable, wrapper ): member_variable_base_t.__init__( self, variable=variable, wrapper=wrapper ) - + def _create_impl( self ): assert isinstance( self.wrapper, array_mv_wrapper_t ) doc = '' @@ -355,7 +354,7 @@ answer.append( os.linesep + self.indent( self.PARAM_SEPARATOR ) ) temp = [ algorithm.create_identifier( self, "::boost::python::make_function" ) ] temp.append( '( ' ) - temp.append( '(%s)(&%s)' + temp.append( '(%s)(&%s)' % ( self.wrapper.wrapper_creator_type , self.wrapper.wrapper_creator_full_name ) ) if not self.declaration.type_qualifiers.has_static: @@ -366,16 +365,16 @@ if doc: answer.append( self.PARAM_SEPARATOR ) answer.append( doc ) - answer.append( ' );' ) + answer.append( ' );' ) return ''.join( answer ) - + #TODO: generated fucntion should be static and take instance of the wrapped class #as first argument. class array_mv_wrapper_t( declaration_based.declaration_based_t ): """ Creates C++ code that register array class. """ - + def __init__(self, variable ): declaration_based.declaration_based_t.__init__( self, declaration=variable) @@ -385,16 +384,16 @@ class_name = 'const_array_1_t' else: class_name = 'array_1_t' - - decl_string = declarations.templates.join( + + decl_string = declarations.templates.join( '::'.join( [ns_name, class_name] ) , [ declarations.array_item_type( self.declaration.type ).decl_string , str( declarations.array_size( self.declaration.type ) ) ]) - + return declarations.dummy_type_t( decl_string ) wrapper_type = property( _get_wrapper_type ) - + def _get_wrapper_creator_type(self): return declarations.member_function_type_t.create_decl_string( return_type=self.wrapper_type @@ -402,7 +401,7 @@ , arguments_types=[] , has_const=False ) wrapper_creator_type = property( _get_wrapper_creator_type ) - + def _get_wrapper_creator_name(self): return '_'.join( ['pyplusplus', self.declaration.name, 'wrapper'] ) wrapper_creator_name = property( _get_wrapper_creator_name ) @@ -417,13 +416,13 @@ temp = ''.join([ 'return ' , self.wrapper_type.decl_string , '( ' - , self.declaration.name + , self.declaration.name , ' );']) answer.append( self.indent( temp ) ) answer.append('}') return os.linesep.join( answer ) - + class mem_var_ref_t( member_variable_base_t ): """ Creates C++ code that creates accessor for class member variable, that has type reference. @@ -438,34 +437,36 @@ answer.append( '( ' ) answer.append( '"get_%s"' % self.alias) answer.append( self.param_sep ) - answer.append( '(%s)(&%s)' + answer.append( '(%s)(&%s)' % ( self.wrapper.getter_type.decl_string, self.wrapper.getter_full_name ) ) if self.declaration.getter_call_policies: - answer.append( self.param_sep ) - answer.append( self.declaration.getter_call_policies.create( self ) ) + if not self.declaration.getter_call_policies.is_default(): + answer.append( self.param_sep ) + answer.append( self.declaration.getter_call_policies.create( self ) ) else: - answer.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) + answer.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) if self.documentation: answer.append( self.param_sep ) answer.append( self.documentation ) answer.append( ' )' ) return ''.join( answer ) - + def _create_setter( self ): answer = ['def'] answer.append( '( ' ) answer.append( '"set_%s"' % self.alias) answer.append( self.param_sep ) - answer.append( '(%s)(&%s)' + answer.append( '(%s)(&%s)' % ( self.wrapper.setter_type.decl_string, self.wrapper.setter_full_name ) ) if self.declaration.setter_call_policies: - answer.append( self.param_sep ) - answer.append( self.declaration.setter_call_policies.create( self ) ) + if not self.declaration.setter_call_policies.is_default(): + answer.append( self.param_sep ) + answer.append( self.declaration.setter_call_policies.create( self ) ) else: - answer.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) + answer.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) answer.append( ' )' ) return ''.join( answer ) - + def _create_impl( self ): #TODO: fix me, should not force class scope usage answer = [] @@ -475,25 +476,25 @@ answer.append( os.linesep ) answer.append( "%s.%s;" % (class_var_name, self._create_setter() ) ) return ''.join( answer ) - + class mem_var_ref_wrapper_t( declaration_based.declaration_based_t ): """ Creates C++ code that creates accessor for class member variable, that has type reference. """ - + indent = declaration_based.declaration_based_t.indent GET_TEMPLATE = os.linesep.join([ 'static %(type)s get_%(name)s( %(class_type)s& inst ) {' , indent( 'return inst.%(name)s;' ) - , '}' + , '}' , '' ]) - + SET_TEMPLATE = os.linesep.join([ 'static void set_%(name)s( %(class_type)s& inst, %(type)s new_value ){ ' , indent( 'inst.%(name)s = new_value;' ) - , '}' - , '' + , '}' + , '' ]) def __init__(self, variable ): @@ -519,11 +520,11 @@ return_type=self._get_exported_var_type() , arguments_types=[ declarations.reference_t( self._get_class_inst_type() ) ] ) getter_type = property( _get_getter_type ) - + def _get_setter_full_name(self): return self.parent.full_name + '::' + 'set_' + self.declaration.name setter_full_name = property(_get_setter_full_name) - + def _get_setter_type(self): return declarations.free_function_type_t( return_type=declarations.void_t() @@ -531,37 +532,37 @@ , self._get_exported_var_type() ] ) setter_type = property( _get_setter_type ) - def _get_has_setter( self ): + def _get_has_setter( self ): if declarations.is_const( declarations.remove_reference( self.declaration.type ) ): return False elif python_traits.is_immutable( self._get_exported_var_type() ): return True else: pass - + no_ref = declarations.remove_reference( self.declaration.type ) - no_const = declarations.remove_const( no_ref ) + no_const = declarations.remove_const( no_ref ) base_type = declarations.remove_alias( no_const ) if not isinstance( base_type, declarations.declarated_t ): return True #TODO ???? decl = base_type.declaration if decl.is_abstract: return False - if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ): + if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ): return False if not declarations.has_trivial_copy(decl): return False return True has_setter = property( _get_has_setter ) - + def _create_impl(self): answer = [] cls_type = algorithm.create_identifier( self, self.declaration.parent.decl_string ) - + substitutions = dict( type=self._get_exported_var_type().decl_string , class_type=cls_type - , name=self.declaration.name ) + , name=self.declaration.name ) answer.append( self.GET_TEMPLATE % substitutions ) if self.has_setter: answer.append( self.SET_TEMPLATE % substitutions ) - return os.linesep.join( answer ) \ No newline at end of file + return os.linesep.join( answer ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-09-13 09:24:37 UTC (rev 537) +++ pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-09-13 11:08:13 UTC (rev 538) @@ -60,6 +60,7 @@ from pygccxml import declarations from call_policies import call_policy_t +from call_policies import default_call_policies_t from call_policies import default_call_policies from call_policies import compound_policy_t from call_policies import return_argument_t Modified: pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2006-09-13 09:24:37 UTC (rev 537) +++ pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2006-09-13 11:08:13 UTC (rev 538) @@ -5,9 +5,9 @@ """ This modules contains definition of call policies classes. Call policies names -are same, that used in boost.python library. +are same, that used in boost.python library. -For every class that implements code creation of call policies, there is a +For every class that implements code creation of call policies, there is a convinience function. """ @@ -34,27 +34,35 @@ @type creation_policy: L{CREATION_POLICY} """ code = self._create_impl( function_creator ) - if creation_policy == CREATION_POLICY.AS_INSTANCE: + if code and creation_policy == CREATION_POLICY.AS_INSTANCE: code = code + '()' return code + def is_default( self ): + """Returns True is self is instance of L{default_call_policies_t} class""" + #Small hack that allows to write nicer code + return False + def _create_impl( self, function_creator ): raise NotImplementedError() - -class default_t(call_policy_t): + +class default_call_policies_t(call_policy_t): """implementation for ::boost::python::default_call_policies""" def __init__( self ): call_policy_t.__init__( self ) - + def _create_impl(self, function_creator ): return algorithm.create_identifier( function_creator, '::boost::python::default_call_policies' ) - + + def is_default( self ): + return True + def __str__(self): return 'default_call_policies' - + def default_call_policies(): """create ::boost::python::default_call_policies""" - return default_t() + return default_call_policies_t() class compound_policy_t( call_policy_t ): """base class for all call policies, except default one""" @@ -62,24 +70,26 @@ call_policy_t.__init__( self ) self._base = base if not base: - self._base = default_t() - + self._base = default_call_policies_t() + def _get_base_policy( self ): - return self._base + return self._base def _set_base_policy( self, new_policy ): self._base = new_policy base_policy = property( _get_base_policy, _set_base_policy - , doc="base call policy, by default is reference to L{default_t} call policy") + , doc="base call policy, by default is reference to L{default_call_policies_t} call policy") def _get_args(self, function_creator): return [] def _get_name(self, function_creator): raise NotImplementedError() - + def _create_impl( self, function_creator ): args = self._get_args(function_creator) - args.append( self._base.create( function_creator, CREATION_POLICY.AS_TEMPLATE_ARGUMENT ) ) + base_policy_code = self._base.create( function_creator, CREATION_POLICY.AS_TEMPLATE_ARGUMENT ) + if base_policy_code: + args.append( base_policy_code ) name = algorithm.create_identifier( function_creator, self._get_name(function_creator) ) return declarations.templates.join( name, args ) @@ -88,13 +98,13 @@ args = map( lambda text: text.replace( '::boost::python::', '' ) , self._get_args( None ) ) return declarations.templates.join( name, args ) - + class return_argument_t( compound_policy_t ): """implementation for ::boost::python::return_argument call policies""" def __init__( self, position=1, base=None): compound_policy_t.__init__( self, base ) self._position = position - + def _get_position( self ): return self._position def _set_position( self, new_position): @@ -106,7 +116,7 @@ return '::boost::python::return_self' else: return '::boost::python::return_arg' - + def _get_args(self, function_creator): if self.position == 1: return [] @@ -123,7 +133,7 @@ def __init__( self, position=1, base=None): compound_policy_t.__init__( self, base ) self._position = position - + def _get_position( self ): return self._position def _set_position( self, new_position): @@ -132,34 +142,34 @@ def _get_name(self, function_creator): return '::boost::python::return_internal_reference' - + def _get_args(self, function_creator): return [ str( self.position ) ] def return_internal_reference( arg_pos=1, base=None): return return_internal_reference_t( arg_pos, base ) - + class with_custodian_and_ward_t( compound_policy_t ): def __init__( self, custodian, ward, base=None): compound_policy_t.__init__( self, base ) self._custodian = custodian self._ward = ward - + def _get_custodian( self ): return self._custodian def _set_custodian( self, new_custodian): self._custodian = new_custodian custodian = property( _get_custodian, _set_custodian ) - + def _get_ward( self ): return self._ward def _set_ward( self, new_ward): self._ward = new_ward ward = property( _get_ward, _set_ward ) - + def _get_name(self, function_creator): return '::boost::python::with_custodian_and_ward' - + def _get_args(self, function_creator): return [ str( self.custodian ), str( self.ward ) ] @@ -172,7 +182,7 @@ def _get_name(self, function_creator): return '::boost::python::with_custodian_and_ward_postcall' - + def with_custodian_and_ward_postcall( custodian, ward, base=None): return with_custodian_and_ward_postcall_t( custodian, ward, base ) @@ -180,7 +190,7 @@ def __init__( self, result_converter_generator, base=None): compound_policy_t.__init__( self, base ) self._result_converter_generator = result_converter_generator - + def _get_result_converter_generator( self ): return self._result_converter_generator def _set_result_converter_generator( self, new_result_converter_generator): @@ -190,7 +200,7 @@ def _get_name(self, function_creator): return '::boost::python::return_value_policy' - + def _get_args(self, function_creator): if function_creator: rcg = algorithm.create_identifier( function_creator, self.result_converter_generator ) @@ -206,4 +216,4 @@ return_opaque_pointer = '::boost::python::return_opaque_pointer' def return_value_policy( result_converter_generator, base=None): - return return_value_policy_t( result_converter_generator, base ) \ No newline at end of file + return return_value_policy_t( result_converter_generator, base ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |