pygccxml-commit Mailing List for C++ Python language bindings (Page 45)
Brought to you by:
mbaas,
roman_yakovenko
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(190) |
Apr
(166) |
May
(170) |
Jun
(75) |
Jul
(105) |
Aug
(131) |
Sep
(99) |
Oct
(84) |
Nov
(67) |
Dec
(54) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(66) |
Feb
(49) |
Mar
(25) |
Apr
(62) |
May
(21) |
Jun
(34) |
Jul
(9) |
Aug
(21) |
Sep
(5) |
Oct
|
Nov
(63) |
Dec
(34) |
| 2008 |
Jan
(10) |
Feb
(42) |
Mar
(26) |
Apr
(25) |
May
(6) |
Jun
(40) |
Jul
(18) |
Aug
(29) |
Sep
(6) |
Oct
(32) |
Nov
(14) |
Dec
(56) |
| 2009 |
Jan
(127) |
Feb
(52) |
Mar
(2) |
Apr
(10) |
May
(29) |
Jun
(3) |
Jul
|
Aug
(16) |
Sep
(4) |
Oct
(11) |
Nov
(8) |
Dec
(14) |
| 2010 |
Jan
(31) |
Feb
(1) |
Mar
(7) |
Apr
(9) |
May
(1) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
(8) |
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <rom...@us...> - 2006-11-27 10:23:04
|
Revision: 758
http://svn.sourceforge.net/pygccxml/?rev=758&view=rev
Author: roman_yakovenko
Date: 2006-11-27 02:23:04 -0800 (Mon, 27 Nov 2006)
Log Message:
-----------
adding missing imports
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/decl_wrappers/__init__.py
Modified: pyplusplus_dev_ft/pyplusplus/decl_wrappers/__init__.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/decl_wrappers/__init__.py 2006-11-27 10:18:38 UTC (rev 757)
+++ pyplusplus_dev_ft/pyplusplus/decl_wrappers/__init__.py 2006-11-27 10:23:04 UTC (rev 758)
@@ -98,6 +98,8 @@
from doc_extractor import doc_extractor_i
from properties import property_t
+from properties import property_recognizer_i
+from properties import name_based_recognizer_t
import python_traits
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-27 10:18:37
|
Revision: 757
http://svn.sourceforge.net/pygccxml/?rev=757&view=rev
Author: roman_yakovenko
Date: 2006-11-27 02:18:38 -0800 (Mon, 27 Nov 2006)
Log Message:
-----------
making prefixes to be public
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/decl_wrappers/properties.py
Modified: pyplusplus_dev_ft/pyplusplus/decl_wrappers/properties.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/decl_wrappers/properties.py 2006-11-27 09:03:29 UTC (rev 756)
+++ pyplusplus_dev_ft/pyplusplus/decl_wrappers/properties.py 2006-11-27 10:18:38 UTC (rev 757)
@@ -58,11 +58,12 @@
class name_based_recognizer_t( property_recognizer_i ):
def __init__( self ):
property_recognizer_i.__init__( self )
- self.__prefixes = (
- ( 'is', 'set' )
- , ( 'get', 'set' )
- , ( 'has', 'set' )
- , ( '', 'set' ) )
+
+ def prefixes( self ):
+ return [ ( 'is', 'set' )
+ , ( 'get', 'set' )
+ , ( 'has', 'set' )
+ , ( '', 'set' ) ]
def check_prefix( self, name, prefix ):
if not name.startswith( prefix ):
@@ -118,7 +119,7 @@
, self.make_l_camel_convention ]
for convention_maker in convention_makers:
- for g, unused in self.__prefixes:
+ for g, unused in self.prefixes():
if not g:
continue
gc, unused = convention_maker( g, 'set' )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-27 09:03:30
|
Revision: 756
http://svn.sourceforge.net/pygccxml/?rev=756&view=rev
Author: roman_yakovenko
Date: 2006-11-27 01:03:29 -0800 (Mon, 27 Nov 2006)
Log Message:
-----------
small refactoring - moving return statement logic out of code creators
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py
pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-26 20:15:57 UTC (rev 755)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-27 09:03:29 UTC (rev 756)
@@ -94,37 +94,14 @@
% { 'type': cntrl.result_variable.type.decl_string
, 'name' : cntrl.result_variable.name }
- post_call = os.linesep.join( cntrl.post_call )
+ return_stmt_creator = calldef_utils.return_stmt_creator_t( self
+ , self.controller
+ , self.controller.result_variable
+ , self.controller.return_variables )
- return_stmt = ''
- if cntrl.return_variables:
- return_vars = cntrl.return_variables[:]
- if not declarations.is_void( self.declaration.return_type ):
- if self.declaration.call_policies.is_default():
- return_vars.insert( 0, cntrl.result_variable.name )
- else:
- c_p_alias = cntrl.register_variable_name( 'call_policies_t' )
- c_p_typedef = 'typedef %s %s;' \
- % ( self.declaration.call_policies.create_template_arg( self )
- , c_p_alias )
- post_call = os.linesep.join( [post_call, c_p_typedef] )
- return_vars.insert( 0
- , declarations.call_invocation.join(
- declarations.templates.join( make_object, [c_p_alias] )
- , [cntrl.result_variable.name] ) )
-
- return_stmt = declarations.call_invocation.join( make_tuple, return_vars )
- if self.LINE_LENGTH < len( return_stmt ):
- return_stmt = declarations.call_invocation.join(
- make_tuple
- , return_vars
- , os.linesep + self.indent( self.PARAM_SEPARATOR, 6 ) )
- elif not declarations.is_void( self.declaration.return_type ):
- return_stmt = cntrl.result_variable.name
- else:
- pass
- if return_stmt:
- return_stmt = 'return ' + return_stmt + ';'
+ post_call = os.linesep.join( cntrl.post_call )
+ if return_stmt_creator.pre_return_code:
+ post_call = os.linesep.join( [post_call, return_stmt_creator.pre_return_code] )
return cntrl.template.substitute({
'declare_variables' : os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
@@ -133,7 +110,7 @@
, 'save_result' : result_var_assign
, 'function' : self.resolve_function_ref()
, 'arg_expressions' : self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
- , 'return' : return_stmt
+ , 'return' : return_stmt_creator.statement
})
def _create_impl(self):
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py 2006-11-26 20:15:57 UTC (rev 755)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py 2006-11-27 09:03:29 UTC (rev 756)
@@ -3,6 +3,8 @@
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
+import os
+import algorithm
import code_creator
from pygccxml import declarations
from pyplusplus import decl_wrappers
@@ -91,5 +93,60 @@
params.append( decl_wrappers.python_traits.call_traits( arg.type ) % self.argument_name( index ) )
return ', '.join( params )
+class return_stmt_creator_t( object ):
+ def __init__( self, creator, controller, result_var, return_vars ):
+ object.__init__( self )
+ self.__creator = creator
+ self.__controller = controller
+ self.__function = controller.function
+ self.__return_vars = return_vars[:]
+ self.__pre_return_code = None
+ self.__return_stmt = None
+ self.__result_var = result_var
+ self.__call_policy_alias = controller.register_variable_name( 'call_policies_t' )
+
+ @property
+ def pre_return_code( self ):
+ if None is self.__pre_return_code:
+ if not self.__controller.return_variables \
+ or self.__function.call_policies.is_default() \
+ or declarations.is_void( self.__function.return_type ):
+ self.__pre_return_code = ''
+ else:
+ c_p_typedef = 'typedef %s %s;' \
+ % ( self.__function.call_policies.create_template_arg( self.__creator )
+ , self.__call_policy_alias )
+ self.__pre_return_code = c_p_typedef
+ return self.__pre_return_code
+ @property
+ def statement( self ):
+ if None is self.__return_stmt:
+ stmt = ''
+ make_tuple = algorithm.create_identifier( self.__creator, 'boost::python::make_tuple' )
+ make_object = algorithm.create_identifier( self.__creator, 'pyplusplus::call_policies::make_object' )
+ if self.__return_vars:
+ if not declarations.is_void( self.__function.return_type ):
+ if self.__function.call_policies.is_default():
+ self.__return_vars.insert( 0, self.__result_var.name )
+ else:
+ self.__return_vars.insert( 0
+ , declarations.call_invocation.join(
+ declarations.templates.join( make_object, [self.__call_policy_alias] )
+ , [self.__result_var.name] ) )
+
+ stmt = declarations.call_invocation.join( make_tuple, self.__return_vars )
+ if self.__creator.LINE_LENGTH < len( stmt ):
+ stmt = declarations.call_invocation.join(
+ make_tuple
+ , self.__return_vars
+ , os.linesep + self.__creator.indent( self.__creator.PARAM_SEPARATOR, 6 ) )
+ elif not declarations.is_void( self.__function.return_type ):
+ stmt = self.__result_var.name
+ else:
+ pass
+ if stmt:
+ stmt = 'return ' + stmt + ';'
+ self.__return_stmt = stmt
+ return self.__return_stmt
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-26 20:15:57 UTC (rev 755)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-27 09:03:29 UTC (rev 756)
@@ -47,19 +47,19 @@
default_body = Template( os.linesep.join([
'$declare_variables'
, '$pre_call'
- , '$declare_wrapped_class_inst'
- , 'if( dynamic_cast< $wrapped_class* >( boost::addressof( $wrapped_class_inst_var_name ) ) ){'
- # The following call is done on an instance created in Python i.e. a
- # wrapper instance. this call might invoke python code.
- , ' $save_return_value_stmt$wrapped_class_inst_var_name->$wrapped_class::$function_name($input_params);'
+ , 'if( $wrapper_class $py_wrapper_var = dynamic_cast< $wrapper_class >( boost::addressof( $wrapped_inst ) ) ){'
+ , ' // The following call is done on an instance created in Python i.e.'
+ , ' // a wrapper instance. this call might invoke python code.'
+ , ' // a wrapper instance. this call might invoke python code.'
+ , ' $py_save_result$wrapped_inst->$wrapped_class::$function_name($py_arg_expressions);'
, '}'
, 'else{'
- # The following call is done on an instance created in C++, so it won't
- # invoke python code.
- , ' $save_return_value_stmt$function_name($input_params);'
+ , " // The following call is done on an instance created in C++, so it won't "
+ , ' // invoke python code.'
+ , ' $cpp_save_result$wrapped_inst.$function_name($cpp_arg_expressions);'
, '}'
, '$post_call'
- , '$return_stmt'
+ , '$return'
]))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-26 20:15:58
|
Revision: 755
http://svn.sourceforge.net/pygccxml/?rev=755&view=rev
Author: roman_yakovenko
Date: 2006-11-26 12:15:57 -0800 (Sun, 26 Nov 2006)
Log Message:
-----------
changing templates
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-26 19:22:48 UTC (rev 754)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-26 20:15:57 UTC (rev 755)
@@ -31,42 +31,18 @@
]))
class mem_fun_v:
-
- original_function_call = Template( "$return_$wrapped_class::%function_name( $args );" )
-
override_body = Template( os.linesep.join([
- '$declare_variables'
- , 'boost::python::override $override_function_var_name = this->get_override( "$function_alias" );'
- , 'if( $override_function_var_name ){'
- , ' $declare_override_variables'
- , ' $override_pre_call'
- , ' ${save_override_return_value}boost::python::call<$override_return_type>( $override_function_var_name$override_input_params;'
- , ' $override_post_call'
- , ' $override_return_stmt'
+ 'if( boost::python::override $py_function_var = this->get_override( "$function_alias" ) ){'
+ , ' $declare_py_variables'
+ , ' $py_pre_call'
+ , ' ${save_py_result}boost::python::call<$py_return_type>( $py_function_var$py_arg_expressions );'
+ , ' $py_post_call'
+ , ' $py_return'
, '}'
, 'else{'
- , ' ' + original_function_call.template
+ , ' $cpp_return$wrapped_class::%function_name( $cpp_arg_expressions );'
, '}'
]))
-
- override_body_safe = Template( os.linesep.join([
- '$declare_gil_guard'
- , '$declare_variables'
- , '$lock_gil_guard'
- , '$declare_override_function = this->get_override( "$function_alias" );'
- , '$unlock_gil_guard'
- , 'if( $override_function_var_name ){'
- , ' $lock_gil_guard //release() will be called from destructor'
- , ' $declare_override_variables'
- , ' $override_pre_call'
- , ' ${save_override_return_value}boost::python::call<$override_return_type>( $override_function_var_name$override_input_params;'
- , ' $override_post_call'
- , ' $override_return_stmt'
- , '}'
- , 'else{'
- , ' ' + original_function_call.template
- , '}'
- ]))
default_body = Template( os.linesep.join([
'$declare_variables'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-26 19:22:50
|
Revision: 754
http://svn.sourceforge.net/pygccxml/?rev=754&view=rev
Author: roman_yakovenko
Date: 2006-11-26 11:22:48 -0800 (Sun, 26 Nov 2006)
Log Message:
-----------
small refactoring to separate mem and free functions
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/decl_wrappers/calldef_wrapper.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-26 06:23:23 UTC (rev 753)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-26 19:22:48 UTC (rev 754)
@@ -22,25 +22,17 @@
return __REMOVE_DUPLICAET_LINESEP.sub( os.linesep, code )
class non_virtual_fun_transformed_t( calldef_t ):
- """Creates code for public non-virtual member functions.
- """
-
def __init__( self, function, wrapper=None ):
calldef_t.__init__( self, function=function, wrapper=wrapper )
- if isinstance( self.declaration.parent, declarations.namespace_t ):
- self.works_on_instance = False
- #map( lambda transformer: transformer.configure_mem_fun
- def create_def_code( self ):
- if isinstance( self.declaration.parent, declarations.namespace_t ):
- return self.def_identifier()
- else:
- return super( non_virtual_fun_transformed_t, self ).create_def_code()
-
@property
def ft( self ): #function transformation
return self.declaration.transformations[0]
+ @property
+ def controller( self ):
+ return self.ft.controller
+
def _get_alias_impl( self ):
return self.wrapper.ft.alias
@@ -61,85 +53,37 @@
return '&%s' % full_name
def create_call_policies( self ):
- if self.ft.controller.return_variables:
+ if self.controller.wrapper_call_policies.is_default():
return ''
else:
- return super( mem_fun_transformed_t, self ).create_call_policies()
+ return super( non_virtual_fun_transformed_t, self ).create_call_policies()
- def create_keywords_args(self):
- arg_utils = calldef_utils.argument_utils_t( self.declaration
- , algorithm.make_id_creator( self )
- , self.ft.controller.wrapper_args )
- return arg_utils.keywords_args()
-
-
class non_virtual_fun_transformed_wrapper_t( calldef_wrapper_t ):
def __init__( self, function ):
- """Constructor.
-
- @param function: Function declaration
- @type function: calldef_t
- """
calldef_wrapper_t.__init__( self, function=function )
-
- def __is_global( self ):
- return not isinstance( self.parent, class_declaration.class_wrapper_t )
- def inst_arg( self ):
- if isinstance( self.declaration.parent, declarations.class_t ):
- return self.ft.controller.inst_arg
- else:
- return None
-
@property
def ft( self ): #function transformation
return self.declaration.transformations[0]
- def function_type(self):
- args = map( lambda arg: arg.type, self.ft.controller.wrapper_args )
- if self.inst_arg():
- args.insert( 0, self.inst_arg().type )
- return declarations.free_function_type_t(
- return_type=self.ft.controller.wrapper_return_type
- , arguments_types=args )
+ @property
+ def controller( self ):
+ return self.ft.controller
- def wrapper_name( self ):
- if self.__is_global():
- return self.ft.unique_name
- else:
- if self.declaration.overloads:
- #it is possible that other functions will have same signature
- return self.ft.unique_name
- else:
- return self.declaration.name
-
- def full_name(self):
- if self.__is_global():
- return self.ft.unique_name
- else:
- return self.parent.full_name + '::' + self.wrapper_name()
-
- def args_declaration( self ):
- args = self.ft.controller.wrapper_args[:]
- if self.inst_arg():
- args.insert( 0, self.inst_arg() )
- arg_utils = calldef_utils.argument_utils_t(
- self.declaration
- , algorithm.make_id_creator( self )
- , args )
- return arg_utils.args_declaration()
-
def create_declaration(self, name):
template = 'static %(return_type)s %(name)s( %(args)s )'
return template % {
- 'return_type' : self.ft.controller.wrapper_return_type.decl_string
+ 'return_type' : self.controller.wrapper_return_type.decl_string
, 'name' : self.wrapper_name()
, 'args' : self.args_declaration()
}
+ def resolve_function_ref( self ):
+ raise NotImplementedError()
+
def create_body(self):
- cntrl = self.ft.controller
+ cntrl = self.controller
make_object = algorithm.create_identifier( self, 'pyplusplus::call_policies::make_object' )
make_tuple = algorithm.create_identifier( self, 'boost::python::make_tuple' )
@@ -182,358 +126,147 @@
if return_stmt:
return_stmt = 'return ' + return_stmt + ';'
- f_invokation = None
- if self.inst_arg():
- f_invokation = self.inst_arg().name + '.' + self.declaration.name
- else:
- f_invokation = declarations.full_name( self.declaration )
-
-
return cntrl.template.substitute({
'declare_variables' : os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
, 'pre_call' : os.linesep.join( cntrl.pre_call )
, 'post_call' : post_call
, 'save_result' : result_var_assign
- , 'function' : f_invokation
+ , 'function' : self.resolve_function_ref()
, 'arg_expressions' : self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
, 'return' : return_stmt
})
def _create_impl(self):
- answer = ['// Transformed wrapper function for "%s"' % self.declaration ]
- answer.append( self.create_declaration(self.declaration.alias) + '{')
+ answer = [ self.create_declaration(self.declaration.alias) + '{' ]
+ answer.append( '// Transformed wrapper function for "%s"' % self.declaration )
body = self.create_body()
body = remove_duplicate_linesep( body )
answer.append( self.indent( body ) )
answer.append( '}' )
return os.linesep.join( answer )
-mem_fun_transformed_t = non_virtual_fun_transformed_t
-mem_fun_transformed_wrapper_t = non_virtual_fun_transformed_wrapper_t
-free_fun_transformed_t = non_virtual_fun_transformed_t
-free_fun_transformed_wrapper_t = non_virtual_fun_transformed_wrapper_t
+class free_fun_transformed_t( non_virtual_fun_transformed_t ):
+ """Creates code for public non-virtual member functions.
+ """
-#~ ######################################################################
+ def __init__( self, function, wrapper=None ):
+ non_virtual_fun_transformed_t.__init__( self, function=function, wrapper=wrapper )
+ self.works_on_instance = False
-#~ class mem_fun_v_transformed_t( calldef_t ):
- #~ """Creates code for (public) virtual member functions.
- #~ """
+ def create_def_code( self ):
+ return self.def_identifier()
- #~ def __init__( self, function, wrapper=None ):
- #~ calldef_t.__init__( self, function=function, wrapper=wrapper )
- #~ self.default_function_type_alias = 'default_' + self.function_type_alias
+ def create_keywords_args(self):
+ arg_utils = calldef_utils.argument_utils_t( self.declaration
+ , algorithm.make_id_creator( self )
+ , self.controller.wrapper_args )
+ return arg_utils.keywords_args()
- #~ def create_function_type_alias_code( self, exported_class_alias=None ):
- #~ if self.wrapper==None:
- #~ ftype = self.declaration.function_type()
- #~ else:
- #~ ftype = self.wrapper.function_type()
- #~ result = []
- #~ result.append( 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) )
- #~ return ''.join( result )
+class free_fun_transformed_wrapper_t( non_virtual_fun_transformed_wrapper_t ):
+ def __init__( self, function ):
+ """Constructor.
- #~ def create_doc(self):
- #~ return None
-
- #~ def create_function_ref_code(self, use_function_alias=False):
- #~ if self.wrapper:
- #~ full_name = self.wrapper.default_full_name()
- #~ else:
- #~ full_name = declarations.full_name( self.declaration )
-
- #~ result = []
- #~ if use_function_alias:
- #~ result.append( '%s(&%s)'
- #~ % ( self.function_type_alias, full_name ) )
- #~ elif self.declaration.create_with_signature:
- #~ if self.wrapper:
- #~ func_type = self.wrapper.function_type()
- #~ else:
- #~ func_type = self.declaration.function_type().decl_string
- #~ result.append( '(%s)(&%s)'
- #~ % ( func_type, full_name ) )
- #~ else:
- #~ result.append( '&%s' % full_name )
-
- #~ return ''.join( result )
-
-
-#~ class mem_fun_v_transformed_wrapper_t( calldef_wrapper_t ):
- #~ """Creates wrapper code for (public) virtual member functions.
-
- #~ The generated code consists of two functions: the virtual function
- #~ and the 'default' function.
- #~ """
-
- #~ def __init__( self, function ):
- #~ """Constructor.
-
- #~ @param function: Function declaration
- #~ @type function: calldef_t
- #~ """
- #~ calldef_wrapper_t.__init__( self, function=function )
-
- #~ # Create the substitution manager
- #~ sm = function_transformers.substitution_manager_t(function
- #~ , transformers=function.transformations[0].transformers )
+ @param function: Function declaration
+ @type function: calldef_t
+ """
+ non_virtual_fun_transformed_wrapper_t .__init__( self, function=function )
- #~ sm.init_funcs()
- #~ self._subst_manager = sm
+ def function_type(self):
+ return declarations.free_function_type_t(
+ return_type=self.controller.wrapper_return_type
+ , arguments_types=self.controller.wrapper_args )
- #~ # Stores the name of the variable that holds the override
- #~ self._override_var \
- #~ = sm.virtual_func.declare_variable(function.alias + "_callable", 'boost::python::override')
- #~ # Stores the name of the 'gstate' variable
- #~ self._gstate_var \
- #~ = sm.virtual_func.declare_variable("gstate", 'pyplusplus::threading ::gil_guard_t' )
+ def wrapper_name( self ):
+ return self.ft.unique_name
- #~ def default_name(self):
- #~ """Return the name of the 'default' function.
+ def full_name(self):
+ return self.ft.unique_name
- #~ @rtype: str
- #~ """
- #~ return "default_" + self.declaration.alias
+ def args_declaration( self ):
+ arg_utils = calldef_utils.argument_utils_t(
+ self.declaration
+ , algorithm.make_id_creator( self )
+ , self.controller.wrapper_args )
+ return arg_utils.args_declaration()
- #~ def default_full_name(self):
- #~ """Return the full name of the 'default' function.
+ def create_declaration(self, name):
+ template = 'static %(return_type)s %(name)s( %(args)s )'
- #~ The returned name also includes the class name.
+ return template % {
+ 'return_type' : self.controller.wrapper_return_type.decl_string
+ , 'name' : self.wrapper_name()
+ , 'args' : self.args_declaration()
+ }
- #~ @rtype: str
- #~ """
- #~ return self.parent.full_name + '::default_' + self.declaration.alias
+ def resolve_function_ref( self ):
+ return declarations.full_name( self.declaration )
- #~ def virtual_name(self):
- #~ """Return the name of the 'virtual' function.
- #~ @rtype: str
- #~ """
- #~ return self.declaration.name
+class mem_fun_transformed_t( non_virtual_fun_transformed_t ):
+ """Creates code for public non-virtual member functions.
+ """
+ def __init__( self, function, wrapper=None ):
+ non_virtual_fun_transformed_t.__init__( self, function=function, wrapper=wrapper )
- #~ def base_name(self):
- #~ """Return the name of the 'base' function.
+ def create_keywords_args(self):
+ args = self.controller.wrapper_args[:]
+ if self.controller.inst_arg:
+ args.insert( 0, self.controller.inst_arg )
- #~ @rtype: str
- #~ """
- #~ return "base_" + self.declaration.name
+ arg_utils = calldef_utils.argument_utils_t( self.declaration
+ , algorithm.make_id_creator( self )
+ , args )
+ return arg_utils.keywords_args()
- #~ def function_type(self):
- #~ template = '$RET_TYPE'
- #~ rettype = self._subst_manager.subst_wrapper(template)
- #~ rettype = declarations.dummy_type_t(rettype)
+class mem_fun_transformed_wrapper_t( non_virtual_fun_transformed_wrapper_t ):
+ def __init__( self, function ):
+ """Constructor.
- #~ return declarations.free_function_type_t(
- #~ return_type=rettype
- #~ , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) )
+ @param function: Function declaration
+ @type function: calldef_t
+ """
+ non_virtual_fun_transformed_wrapper_t.__init__( self, function=function )
- #~ return declarations.member_function_type_t(
- #~ return_type=self.declaration.return_type
- #~ , class_inst=declarations.dummy_type_t( self.parent.full_name )
- #~ , arguments_types=map( lambda arg: arg.type, self.declaration.arguments )
- #~ , has_const=self.declaration.has_const )
+ def __is_global( self ):
+ return not isinstance( self.parent, class_declaration.class_wrapper_t )
- #~ def create_declaration(self, name, virtual=True):
- #~ """Create the function header.
+ def function_type(self):
+ args = map( lambda arg: arg.type, self.controller.wrapper_args )
+ if self.controller.inst_arg:
+ args.insert( 0, self.controller.inst_arg.type )
+ return declarations.free_function_type_t(
+ return_type=self.controller.wrapper_return_type
+ , arguments_types=args )
- #~ This method is used for the virtual function (and the base_ function),
- #~ but not for the default function.
- #~ """
- #~ template = '%(virtual)s$RET_TYPE %(name)s( $ARG_LIST_DEF )%(constness)s %(throw)s'
+ def wrapper_name( self ):
+ if self.__is_global():
+ return self.ft.unique_name
+ else:
+ if self.declaration.overloads:
+ #it is possible that other functions will have same signature
+ return self.ft.unique_name
+ else:
+ return self.declaration.name
- #~ # Substitute the $-variables
- #~ template = self._subst_manager.subst_virtual(template)
+ def full_name(self):
+ if self.__is_global():
+ return self.ft.unique_name
+ else:
+ return self.parent.full_name + '::' + self.wrapper_name()
- #~ virtualspec = ''
- #~ if virtual:
- #~ virtualspec = 'virtual '
+ def args_declaration( self ):
+ args = self.controller.wrapper_args[:]
+ if self.controller.inst_arg:
+ args.insert( 0, self.controller.inst_arg )
+ arg_utils = calldef_utils.argument_utils_t(
+ self.declaration
+ , algorithm.make_id_creator( self )
+ , args )
+ return arg_utils.args_declaration()
- #~ constness = ''
- #~ if self.declaration.has_const:
- #~ constness = ' const '
-
- #~ return template % {
- #~ 'virtual' : virtualspec
- #~ , 'name' : name
- #~ , 'constness' : constness
- #~ , 'throw' : self.throw_specifier_code()
- #~ }
-
- #~ def create_base_body(self):
- #~ body = "%(return_)s%(wrapped_class)s::%(name)s( %(args)s );"
-
- #~ return_ = ''
- #~ if not declarations.is_void( self.declaration.return_type ):
- #~ return_ = 'return '
-
- #~ return body % {
- #~ 'name' : self.declaration.name
- #~ , 'args' : self.function_call_args()
- #~ , 'return_' : return_
- #~ , 'wrapped_class' : self.wrapped_class_identifier()
- #~ }
-
- #~ def create_virtual_body(self):
-
- #~ thread_safe = self.declaration.transformations[0].thread_safe
-
- #~ if thread_safe:
- #~ body = """
-#~ pyplusplus::threading::gil_guard_t %(gstate_var)s;
-
-#~ %(gstate_var)s.ensure();
-#~ boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
-#~ %(gstate_var)s.release();
-
-#~ if( %(override_var)s )
-#~ {
- #~ // The corresponding release() is done in the destructor of %(gstate_var)s
- #~ %(gstate_var)s.ensure();
-
- #~ $DECLARATIONS
-
- #~ try {
- #~ $PRE_CALL
-
- #~ ${RESULT_VAR_ASSIGNMENT}boost::python::call<$RESULT_TYPE>($INPUT_PARAMS);
-
- #~ $POST_CALL
-
- #~ $RETURN_STMT
- #~ }
- #~ catch(...)
- #~ {
- #~ if (PyErr_Occurred())
- #~ {
- #~ PyErr_Print();
- #~ }
-
- #~ $CLEANUP
-
- #~ $EXCEPTION_HANDLER_EXIT
- #~ }
-#~ }
-#~ else
-#~ {
- #~ %(inherited)s
-#~ }
-#~ """
-
- #~ if not thread_safe:
- #~ body = """
-#~ boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
-
-#~ if( %(override_var)s )
-#~ {
- #~ $DECLARATIONS
-
- #~ $PRE_CALL
-
- #~ ${RESULT_VAR_ASSIGNMENT}boost::python::call<$RESULT_TYPE>($INPUT_PARAMS);
-
- #~ $POST_CALL
-
- #~ $RETURN_STMT
-#~ }
-#~ else
-#~ {
- #~ %(inherited)s
-#~ }
-#~ """
-
- #~ vf = self._subst_manager.virtual_func
- #~ arg0 = "%s.ptr()"%self._override_var
- #~ if vf.INPUT_PARAMS=="":
- #~ vf.INPUT_PARAMS = arg0
- #~ else:
- #~ vf.INPUT_PARAMS = arg0+", "+vf.INPUT_PARAMS
-
- #~ # Replace the $-variables
- #~ body = self._subst_manager.subst_virtual(body)
-
- #~ return body % {
- #~ 'override_var' : self._override_var
- #~ , 'gstate_var' : self._gstate_var
- #~ , 'alias' : self.declaration.alias
- #~ , 'inherited' : self.create_base_body()
- #~ }
-
- #~ def create_default_body(self):
- #~ cls_wrapper_type = self.parent.full_name
- #~ cls_wrapper = self._subst_manager.wrapper_func.declare_variable("cls_wrapper", cls_wrapper_type);
- #~ # The name of the 'self' variable (i.e. first argument)
- #~ selfname = self._subst_manager.wrapper_func.arg_list[0].name
-
- #~ body = """$DECLARATIONS
-
-#~ $PRE_CALL
-
-#~ %(cls_wrapper_type)s* %(cls_wrapper)s = dynamic_cast<%(cls_wrapper_type)s*>(boost::addressof(%(self)s));
-#~ if (%(cls_wrapper)s==0)
-#~ {
- #~ // The following call is done on an instance created in C++,
- #~ // so it won't invoke Python code.
- #~ $RESULT_VAR_ASSIGNMENT$CALL_FUNC_NAME($INPUT_PARAMS);
-#~ }
-#~ else
-#~ {
- #~ // The following call is done on an instance created in Python,
- #~ // i.e. a wrapper instance. This call might invoke Python code.
- #~ $RESULT_VAR_ASSIGNMENT%(cls_wrapper)s->%(base_name)s($INPUT_PARAMS);
-#~ }
-
-#~ $POST_CALL
-
-#~ $RETURN_STMT
-#~ """
-
- #~ # Replace the $-variables
- #~ body = self._subst_manager.subst_wrapper(body)
-
- #~ # Replace the remaining parameters
- #~ body = body%{"cls_wrapper_type" : cls_wrapper_type,
- #~ "cls_wrapper" : cls_wrapper,
- #~ "self" : selfname,
- #~ "base_name" : self.base_name() }
- #~ return body
-
- #~ def create_function(self):
- #~ answer = [ self.create_declaration(self.declaration.name) + '{' ]
- #~ answer.append( self.indent( self.create_virtual_body() ) )
- #~ answer.append( '}' )
- #~ return os.linesep.join( answer )
-
- #~ def create_base_function( self ):
- #~ answer = [ self.create_declaration("base_"+self.declaration.name, False) + '{' ]
- #~ body = "%(return_)s%(wrapped_class)s::%(name)s( %(args)s );"
- #~ answer.append( self.indent( self.create_base_body() ) )
- #~ answer.append( '}' )
- #~ return os.linesep.join( answer )
-
- #~ def create_default_function( self ):
-
- #~ header = 'static $RET_TYPE %s( $ARG_LIST_DEF ) {'%self.default_name()
- #~ header = self._subst_manager.subst_wrapper(header)
-
- #~ answer = [ header ]
- #~ answer.append( self.indent( self.create_default_body() ) )
- #~ answer.append( '}' )
- #~ return os.linesep.join( answer )
-
- #~ def _create_impl(self):
-
- #~ answer = [ self.create_function() ]
- #~ answer.append( os.linesep )
- #~ answer.append( self.create_base_function() )
- #~ answer.append( os.linesep )
- #~ answer.append( self.create_default_function() )
- #~ answer = os.linesep.join( answer )
-
- #~ # Replace the argument list of the declaration so that in the
- #~ # case that keywords are created, the correct arguments will be
- #~ # picked up (i.e. the modified argument list and not the original
- #~ # argument list)
- #~ self.declaration.arguments = self._subst_manager.wrapper_func.arg_list
-
- #~ return answer
-
+ def resolve_function_ref( self ):
+ if self.controller.inst_arg:
+ return self.controller.inst_arg.name + '.' + self.declaration.name
+ else:
+ return declarations.full_name( self.declaration )
Modified: pyplusplus_dev_ft/pyplusplus/decl_wrappers/calldef_wrapper.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-11-26 06:23:23 UTC (rev 753)
+++ pyplusplus_dev_ft/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-11-26 19:22:48 UTC (rev 754)
@@ -168,7 +168,7 @@
if len( self.arguments ) > calldef_t.BOOST_PYTHON_MAX_ARITY:
tmp = [ "The function has more than %d arguments ( %d ). " ]
tmp.append( "You should adjust BOOST_PYTHON_MAX_ARITY macro." )
- tmp.append( "For more information see: http://mail.python.org/pipermail/c++-sig/2002-June/001554.html" )
+ tmp.append( "For more information see: http://www.boost.org/libs/python/doc/v2/configuration.html" )
tmp = ' '.join( tmp )
msgs.append( tmp % ( calldef_t.BOOST_PYTHON_MAX_ARITY, len( self.arguments ) ) )
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-26 06:23:23 UTC (rev 753)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-26 19:22:48 UTC (rev 754)
@@ -114,6 +114,15 @@
return self.function.return_type
@property
+ def wrapper_call_policies( self ):
+ #prevent recursive import
+ from pyplusplus import decl_wrappers
+ if 'boost::python::tuple' == self.wrapper_return_type.decl_string:
+ return decl_wrappers.default_call_policies()
+ else:
+ return self.function.call_policies
+
+ @property
def return_variables( self ):
return self.__return_variables
@@ -136,14 +145,8 @@
def set_input_param( self, index, var_name_or_expr ):
self.__input_params[ index ] = var_name_or_expr
-
- @property
- def return_stmt( self ):
- return self.__return_stmt
-
- def set_return_stmt( self, stmt ):
- self.__return_stmt = stmt
+
class mem_fun_controller_t( non_virtual_fun_controller_t ):
def __init__( self, function ):
non_virtual_fun_controller_t.__init__( self, function )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-26 06:23:25
|
Revision: 753
http://svn.sourceforge.net/pygccxml/?rev=753&view=rev
Author: roman_yakovenko
Date: 2006-11-25 22:23:23 -0800 (Sat, 25 Nov 2006)
Log Message:
-----------
fixing MSVC 7.1 compilation bug
Modified Paths:
--------------
pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
Modified: pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-25 19:25:49 UTC (rev 752)
+++ pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-26 06:23:23 UTC (rev 753)
@@ -83,7 +83,7 @@
}
static void distance( const point3d_t& pt, double& dist ){
- dist = sqrt( pt.x*pt.x + pt.y*pt.y + pt.z*pt.z );
+ dist = sqrt( double( pt.x*pt.x + pt.y*pt.y + pt.z*pt.z ) );
}
int x, y, z;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-25 19:25:50
|
Revision: 752
http://svn.sourceforge.net/pygccxml/?rev=752&view=rev
Author: roman_yakovenko
Date: 2006-11-25 11:25:49 -0800 (Sat, 25 Nov 2006)
Log Message:
-----------
adding ft for free functions
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/__init__.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
pyplusplus_dev_ft/pyplusplus/function_transformers/transformer.py
pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
pyplusplus_dev_ft/pyplusplus/module_creator/creator.py
pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/__init__.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/__init__.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/__init__.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -78,6 +78,9 @@
from calldef_transformed import mem_fun_transformed_t
from calldef_transformed import mem_fun_transformed_wrapper_t
+from calldef_transformed import free_fun_transformed_t
+from calldef_transformed import free_fun_transformed_wrapper_t
+
#~ from calldef_transformed import mem_fun_v_transformed_t
#~ from calldef_transformed import mem_fun_v_transformed_wrapper_t
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -21,14 +21,22 @@
def remove_duplicate_linesep( code ):
return __REMOVE_DUPLICAET_LINESEP.sub( os.linesep, code )
-class mem_fun_transformed_t( calldef_t ):
+class non_virtual_fun_transformed_t( calldef_t ):
"""Creates code for public non-virtual member functions.
"""
def __init__( self, function, wrapper=None ):
calldef_t.__init__( self, function=function, wrapper=wrapper )
+ if isinstance( self.declaration.parent, declarations.namespace_t ):
+ self.works_on_instance = False
#map( lambda transformer: transformer.configure_mem_fun
-
+
+ def create_def_code( self ):
+ if isinstance( self.declaration.parent, declarations.namespace_t ):
+ return self.def_identifier()
+ else:
+ return super( non_virtual_fun_transformed_t, self ).create_def_code()
+
@property
def ft( self ): #function transformation
return self.declaration.transformations[0]
@@ -65,7 +73,7 @@
return arg_utils.keywords_args()
-class mem_fun_transformed_wrapper_t( calldef_wrapper_t ):
+class non_virtual_fun_transformed_wrapper_t( calldef_wrapper_t ):
def __init__( self, function ):
"""Constructor.
@@ -74,27 +82,26 @@
"""
calldef_wrapper_t.__init__( self, function=function )
- this_arg_type = declarations.declarated_t( self.declaration.parent )
- if self.declaration.has_const:
- this_arg_type = declarations.const_t( this_arg_type )
- this_arg_type = declarations.reference_t( this_arg_type )
-
- self.__this_arg = declarations.argument_t(
- name=self.ft.controller.register_variable_name( 'inst' )
- , type=this_arg_type )
-
def __is_global( self ):
return not isinstance( self.parent, class_declaration.class_wrapper_t )
+ def inst_arg( self ):
+ if isinstance( self.declaration.parent, declarations.class_t ):
+ return self.ft.controller.inst_arg
+ else:
+ return None
+
@property
def ft( self ): #function transformation
return self.declaration.transformations[0]
def function_type(self):
+ args = map( lambda arg: arg.type, self.ft.controller.wrapper_args )
+ if self.inst_arg():
+ args.insert( 0, self.inst_arg().type )
return declarations.free_function_type_t(
- return_type=self.ft.controller.wrapper_return_type
- , arguments_types=[ self.__this_arg.type ]
- + map( lambda arg: arg.type, self.ft.controller.wrapper_args ) )
+ return_type=self.ft.controller.wrapper_return_type
+ , arguments_types=args )
def wrapper_name( self ):
if self.__is_global():
@@ -113,10 +120,13 @@
return self.parent.full_name + '::' + self.wrapper_name()
def args_declaration( self ):
+ args = self.ft.controller.wrapper_args[:]
+ if self.inst_arg():
+ args.insert( 0, self.inst_arg() )
arg_utils = calldef_utils.argument_utils_t(
self.declaration
, algorithm.make_id_creator( self )
- , [ self.__this_arg ] + self.ft.controller.wrapper_args )
+ , args )
return arg_utils.args_declaration()
def create_declaration(self, name):
@@ -171,13 +181,20 @@
pass
if return_stmt:
return_stmt = 'return ' + return_stmt + ';'
+
+ f_invokation = None
+ if self.inst_arg():
+ f_invokation = self.inst_arg().name + '.' + self.declaration.name
+ else:
+ f_invokation = declarations.full_name( self.declaration )
+
return cntrl.template.substitute({
'declare_variables' : os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
, 'pre_call' : os.linesep.join( cntrl.pre_call )
, 'post_call' : post_call
, 'save_result' : result_var_assign
- , 'function' : self.__this_arg.name + '.' + self.declaration.name
+ , 'function' : f_invokation
, 'arg_expressions' : self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
, 'return' : return_stmt
})
@@ -191,6 +208,11 @@
answer.append( '}' )
return os.linesep.join( answer )
+mem_fun_transformed_t = non_virtual_fun_transformed_t
+mem_fun_transformed_wrapper_t = non_virtual_fun_transformed_wrapper_t
+free_fun_transformed_t = non_virtual_fun_transformed_t
+free_fun_transformed_wrapper_t = non_virtual_fun_transformed_wrapper_t
+
#~ ######################################################################
#~ class mem_fun_v_transformed_t( calldef_t ):
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -44,4 +44,4 @@
def output_array( *args, **keywd ):
def creator( function ):
return transformers.output_array_t( function, *args, **keywd )
- return creator
+ return creator
\ No newline at end of file
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -63,8 +63,8 @@
def apply( self, transformations ):
raise NotImplementedError()
-class mem_fun_controller_t( controller_base_t ):
-
+class non_virtual_fun_controller_t( controller_base_t ):
+ #base class for free and member function controllers
def __init__( self, function ):
controller_base_t.__init__( self, function )
self.__wrapper_args = [ arg.clone() for arg in function.arguments ]
@@ -75,9 +75,6 @@
self.__post_call = []
self.__arg_expressions = [ arg.name for arg in function.arguments ]
- def apply( self, transformations ):
- map( lambda t: t.configure_mem_fun( self ), transformations )
-
@property
def result_variable( self ):
return self.__result_var
@@ -147,4 +144,31 @@
def set_return_stmt( self, stmt ):
self.__return_stmt = stmt
+class mem_fun_controller_t( non_virtual_fun_controller_t ):
+ def __init__( self, function ):
+ non_virtual_fun_controller_t.__init__( self, function )
+
+ inst_arg_type = declarations.declarated_t( self.function.parent )
+ if self.function.has_const:
+ inst_arg_type = declarations.const_t( inst_arg_type )
+ inst_arg_type = declarations.reference_t( inst_arg_type )
+
+ self.__inst_arg = None
+ if not self.function.has_static:
+ self.__inst_arg = declarations.argument_t( name=self.register_variable_name( 'inst' )
+ , type=inst_arg_type )
+ def apply( self, transformations ):
+ map( lambda t: t.configure_mem_fun( self ), transformations )
+
+ @property
+ def inst_arg( self ):
+ return self.__inst_arg
+
+class free_fun_controller_t( non_virtual_fun_controller_t ):
+ def __init__( self, function ):
+ non_virtual_fun_controller_t.__init__( self, function )
+
+ def apply( self, transformations ):
+ map( lambda t: t.configure_free_fun( self ), transformations )
+
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -7,13 +7,18 @@
"""
import md5
import controllers
+from pygccxml import declarations
from pyplusplus import code_repository
class function_transformation_t:
def __init__(self, function, transformer_creator, **keywd):
"""Constructor. """
self.__function = function
- self.__controller = controllers.mem_fun_controller_t( function )
+ self.__controller = None
+ if isinstance( function.parent, declarations.class_t ):
+ self.__controller = controllers.mem_fun_controller_t( function )
+ else:
+ self.__controller = controllers.free_fun_controller_t( function )
self.__transformers = map( lambda tr_creator: tr_creator( function ), transformer_creator )
self.__thread_safe = keywd.get( 'thread_safe', False )
self.__controller.apply( self.__transformers )
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -11,6 +11,16 @@
# function_name - C++ function name
# function_alias - function name that Python user will see
+class free_fun:
+ body = Template( os.linesep.join([
+ '$declare_variables'
+ , '$pre_call'
+ , '$save_result$function($arg_expressions);'
+ , '$post_call'
+ , '$return'
+ ]))
+
+
class mem_fun:
body = Template( os.linesep.join([
'$declare_variables'
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/transformer.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/transformer.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/transformer.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -60,4 +60,9 @@
return self.get_argument( reference ).type
def configure_mem_fun( self, controller ):
- pass
\ No newline at end of file
+ pass
+
+ def configure_free_fun( self, controller ):
+ pass
+
+
\ No newline at end of file
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -68,8 +68,7 @@
def __str__(self):
return "output(%d)"%(self.arg_index)
- def configure_mem_fun( self, controller ):
- assert isinstance( controller, controllers.mem_fun_controller_t )
+ def __configure_non_virtual( self, controller ):
#removing arg from the function wrapper definition
controller.remove_wrapper_arg( self.arg.name )
#declaring new variable, which will keep result
@@ -79,6 +78,12 @@
#adding the variable to return variables list
controller.return_variable( var_name )
+ def configure_mem_fun( self, controller ):
+ self.__configure_non_virtual( controller )
+
+ def configure_free_fun(self, controller ):
+ self.__configure_non_virtual( controller )
+
# input_t
class input_t(transformer.transformer_t):
"""Handles a single input variable.
@@ -107,11 +112,16 @@
def __str__(self):
return "input(%d)"%(self.idx)
- def configure_mem_fun( self, controller ):
- assert isinstance( controller, controllers.mem_fun_controller_t )
+ def __configure_non_virtual( self, controller ):
w_arg = controller.find_wrapper_arg( self.arg.name )
w_arg.type = remove_ref_or_ptr( self.arg.type )
+ def configure_mem_fun( self, controller ):
+ self.__configure_non_virtual( controller )
+
+ def configure_free_fun(self, controller ):
+ self.__configure_non_virtual( controller )
+
# inout_t
class inout_t(transformer.transformer_t):
"""Handles a single input/output variable.
@@ -138,14 +148,19 @@
def __str__(self):
return "inout(%d)"%(self.arg_index)
- def configure_mem_fun(self, controller):
- assert isinstance( controller, controllers.mem_fun_controller_t )
+ def __configure_non_virtual(self, controller):
w_arg = controller.find_wrapper_arg( self.arg.name )
w_arg.type = remove_ref_or_ptr( self.arg.type )
#adding the variable to return variables list
controller.return_variable( w_arg.name )
+ def configure_mem_fun( self, controller ):
+ self.__configure_non_virtual( controller )
+
+ def configure_free_fun(self, controller ):
+ self.__configure_non_virtual( controller )
+
class input_array_t(transformer.transformer_t):
"""Handles an input array with fixed size.
@@ -185,9 +200,7 @@
pre_call.append( 'pyplus_conv::copy_sequence( $pylist, pyplus_conv::array_inserter( $native_array, $array_size ) );' )
return string.Template( os.linesep.join( pre_call ) )
- def configure_mem_fun(self, controller):
- assert isinstance( controller, controllers.mem_fun_controller_t )
-
+ def __configure_non_virtual(self, controller):
w_arg = controller.find_wrapper_arg( self.arg.name )
w_arg.type = declarations.dummy_type_t( "boost::python::object" )
@@ -205,6 +218,11 @@
controller.modify_argument_expression( self.arg_index, native_array )
+ def configure_mem_fun( self, controller ):
+ self.__configure_non_virtual( controller )
+
+ def configure_free_fun(self, controller ):
+ self.__configure_non_virtual( controller )
# output_array_t
class output_array_t(transformer.transformer_t):
@@ -244,8 +262,7 @@
def post_call_tmpl( self ):
return string.Template( 'pyplus_conv::copy_container( $native_array, $native_array + $array_size, pyplus_conv::list_inserter( $pylist ) );' )
- def configure_mem_fun(self, controller):
- assert isinstance( controller, controllers.mem_fun_controller_t )
+ def __configure_non_virtual(self, controller):
#removing arg from the function wrapper definition
controller.remove_wrapper_arg( self.arg.name )
@@ -269,4 +286,10 @@
#adding the variable to return variables list
controller.return_variable( pylist )
+
+ def configure_mem_fun( self, controller ):
+ self.__configure_non_virtual( controller )
+
+ def configure_free_fun(self, controller ):
+ self.__configure_non_virtual( controller )
Modified: pyplusplus_dev_ft/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/module_creator/creator.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/pyplusplus/module_creator/creator.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -533,7 +533,14 @@
self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl )
self.__on_demand_include_call_policies( self.curr_decl.call_policies )
- maker = code_creators.free_function_t( function=self.curr_decl )
+ maker = None
+ if self.curr_decl.transformations:
+ wrapper = code_creators.free_fun_transformed_wrapper_t( self.curr_decl )
+ self.__extmodule.adopt_declaration_creator( wrapper )
+ maker = code_creators.free_fun_transformed_t( self.curr_decl, wrapper )
+ maker.associated_decl_creators.append( wrapper )
+ else:
+ maker = code_creators.free_function_t( function=self.curr_decl )
self.curr_code_creator.adopt_creator( maker )
self.__opaque_types_manager.register_opaque( maker, self.curr_decl )
Modified: pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-25 19:25:49 UTC (rev 752)
@@ -6,8 +6,15 @@
#ifndef __function_transformations_to_be_exported_hpp__
#define __function_transformations_to_be_exported_hpp__
+#include <cmath>
+#include <string>
+
namespace ft2{
+void hello_world( std::string& hw ){
+ hw = "hello world!";
+}
+
//used to check output transformer
struct calculator_t{
calculator_t(){
@@ -57,6 +64,7 @@
};
struct point3d_t{
+
point3d_t()
: x( 0 ), y(0), z(0)
{}
@@ -74,6 +82,10 @@
v[2] = z;
}
+ static void distance( const point3d_t& pt, double& dist ){
+ dist = sqrt( pt.x*pt.x + pt.y*pt.y + pt.z*pt.z );
+ }
+
int x, y, z;
};
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-23 20:26:16 UTC (rev 751)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-25 19:25:49 UTC (rev 752)
@@ -5,6 +5,7 @@
import os
import sys
+import math
import unittest
import fundamental_tester_base
from pyplusplus import function_transformers as ft
@@ -24,6 +25,9 @@
mb.global_ns.calldefs().create_with_signature = True
+ hello_world = mb.free_fun( 'hello_world' )
+ hello_world.add_transformation( ft.output(0) )
+
calc = mb.class_('calculator_t' )
assign_funs = calc.mem_funs( lambda decl: decl.name.startswith( 'assign' ) )
assign_funs.add_transformation( ft.output(0), ft.output(1) )
@@ -40,6 +44,7 @@
point3d.add_wrapper_code( '' )
point3d.mem_fun( 'initialize' ).add_transformation( ft.input_array(0, size=3) )
point3d.mem_fun( 'position' ).add_transformation( ft.output_array(0, size=3) )
+ point3d.mem_fun( 'distance' ).add_transformation( ft.output(1) )
#~ image = mb.class_( "image_t" )
#~ image.include()
@@ -91,6 +96,9 @@
result = point3d.initialize( [ 1,2,3 ] )
self.failUnless( result== 1*2*3 and point3d.x == 1 and point3d.y==2 and point3d.z==3 )
self.failUnless( [1,2,3] == point3d.position()[0] )
+ self.failUnless( module.point3d_t.distance( point3d )[0] == math.sqrt( 1*1 + 2*2 + 3*3 ) )
+
+ self.failUnless( module.hello_world()[0] == "hello world!" )
#~ img = module.image_t( 2, 6)
# Check a method that returns two values by reference
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-23 20:26:15
|
Revision: 751
http://svn.sourceforge.net/pygccxml/?rev=751&view=rev
Author: roman_yakovenko
Date: 2006-11-23 12:26:16 -0800 (Thu, 23 Nov 2006)
Log Message:
-----------
adding ft tester to test_all.py
Modified Paths:
--------------
pyplusplus_dev_ft/unittests/test_all.py
Modified: pyplusplus_dev_ft/unittests/test_all.py
===================================================================
--- pyplusplus_dev_ft/unittests/test_all.py 2006-11-23 20:04:44 UTC (rev 750)
+++ pyplusplus_dev_ft/unittests/test_all.py 2006-11-23 20:26:16 UTC (rev 751)
@@ -67,6 +67,7 @@
import convenience_tester
import inner_class_bug_tester
import declarations_order_bug_tester
+import function_transformations_tester
def create_suite(times):
testers = [
@@ -130,6 +131,7 @@
, convenience_tester
, inner_class_bug_tester
, declarations_order_bug_tester
+ , function_transformations_tester
]
main_suite = unittest.TestSuite()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-23 20:04:49
|
Revision: 750
http://svn.sourceforge.net/pygccxml/?rev=750&view=rev
Author: roman_yakovenko
Date: 2006-11-23 12:04:44 -0800 (Thu, 23 Nov 2006)
Log Message:
-----------
adding ability to create member function in the global namespace
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/code_creators/declaration_based.py
pyplusplus_dev_ft/pyplusplus/code_repository/call_policies.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-23 08:09:53 UTC (rev 749)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-23 20:04:44 UTC (rev 750)
@@ -33,6 +33,9 @@
def ft( self ): #function transformation
return self.declaration.transformations[0]
+ def _get_alias_impl( self ):
+ return self.wrapper.ft.alias
+
def create_function_type_alias_code( self, exported_class_alias=None ):
ftype = self.wrapper.function_type()
return 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias )
@@ -79,7 +82,10 @@
self.__this_arg = declarations.argument_t(
name=self.ft.controller.register_variable_name( 'inst' )
, type=this_arg_type )
-
+
+ def __is_global( self ):
+ return not isinstance( self.parent, class_declaration.class_wrapper_t )
+
@property
def ft( self ): #function transformation
return self.declaration.transformations[0]
@@ -90,8 +96,21 @@
, arguments_types=[ self.__this_arg.type ]
+ map( lambda arg: arg.type, self.ft.controller.wrapper_args ) )
+ def wrapper_name( self ):
+ if self.__is_global():
+ return self.ft.unique_name
+ else:
+ if self.declaration.overloads:
+ #it is possible that other functions will have same signature
+ return self.ft.unique_name
+ else:
+ return self.declaration.name
+
def full_name(self):
- return self.parent.full_name + '::' + self.declaration.name
+ if self.__is_global():
+ return self.ft.unique_name
+ else:
+ return self.parent.full_name + '::' + self.wrapper_name()
def args_declaration( self ):
arg_utils = calldef_utils.argument_utils_t(
@@ -105,7 +124,7 @@
return template % {
'return_type' : self.ft.controller.wrapper_return_type.decl_string
- , 'name' : self.declaration.name
+ , 'name' : self.wrapper_name()
, 'args' : self.args_declaration()
}
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/declaration_based.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/declaration_based.py 2006-11-23 08:09:53 UTC (rev 749)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/declaration_based.py 2006-11-23 20:04:44 UTC (rev 750)
@@ -30,9 +30,13 @@
doc="""The declaration this code creator is based on.
@type: L{decl_wrapper_t<decl_wrappers.decl_wrapper_t>}
""")
+
+ def _get_alias_impl( self ):
+ return self.declaration.alias
def _get_alias(self):
- return self.declaration.alias
+ return self._get_alias_impl()
+
def _set_alias(self, alias):
self.declaration.alias = alias
alias = property( _get_alias, _set_alias )
Modified: pyplusplus_dev_ft/pyplusplus/code_repository/call_policies.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_repository/call_policies.py 2006-11-23 08:09:53 UTC (rev 749)
+++ pyplusplus_dev_ft/pyplusplus/code_repository/call_policies.py 2006-11-23 20:04:44 UTC (rev 750)
@@ -73,7 +73,7 @@
template< typename CallPolicies, class T >
bpl::object make_object( T const & x ){
//constructs object using CallPolicies result_converter
- typedef typename CallPolicies::result_converter::apply< T >::type result_converter_t;
+ typedef BOOST_DEDUCED_TYPENAME CallPolicies::result_converter:: template apply< T >::type result_converter_t;
result_converter_t rc;
return bpl::object( bpl::handle<>( rc( x ) ) );
}
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-23 08:09:53 UTC (rev 749)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-23 20:04:44 UTC (rev 750)
@@ -73,7 +73,6 @@
self.__return_variables = []
self.__pre_call = []
self.__post_call = []
- self.__save_return_value_stmt = None
self.__arg_expressions = [ arg.name for arg in function.arguments ]
def apply( self, transformations ):
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-23 08:09:53 UTC (rev 749)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-23 20:04:44 UTC (rev 750)
@@ -5,7 +5,7 @@
"""This module contains the class L{function_transformation_t}.
"""
-
+import md5
import controllers
from pyplusplus import code_repository
@@ -17,8 +17,27 @@
self.__transformers = map( lambda tr_creator: tr_creator( function ), transformer_creator )
self.__thread_safe = keywd.get( 'thread_safe', False )
self.__controller.apply( self.__transformers )
+ self.__unique_name = None
+ self.__alias = keywd.get( 'alias', None )
@property
+ def unique_name( self ):
+ if None is self.__unique_name:
+ obj = md5.new()
+ obj.update( self.__function.mangled )
+ self.__unique_name = self.__function.name + '_' + obj.hexdigest()
+ return self.__unique_name
+
+ @property
+ def alias( self ):
+ if None is self.__alias:
+ if self.__function.overloads:
+ self.__alias = self.unique_name
+ else:
+ self.__alias = self.__function.alias
+ return self.__alias
+
+ @property
def transformers( self ):
return self.__transformers
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-23 08:09:53 UTC (rev 749)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-23 20:04:44 UTC (rev 750)
@@ -25,7 +25,6 @@
mb.global_ns.calldefs().create_with_signature = True
calc = mb.class_('calculator_t' )
- calc.add_wrapper_code( '' )
assign_funs = calc.mem_funs( lambda decl: decl.name.startswith( 'assign' ) )
assign_funs.add_transformation( ft.output(0), ft.output(1) )
@@ -34,7 +33,6 @@
clone_and_assign_5.call_policies = call_policies.return_value_policy( call_policies.manage_new_object )
window = mb.class_( 'window_t' )
- window.add_wrapper_code( '' )
window.mem_fun( 'resize' ).add_transformation( ft.input(0), ft.input(1) )
window.mem_fun( 'resize_in_out' ).add_transformation( ft.inout(0), ft.inout(1) )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-23 08:09:54
|
Revision: 749
http://svn.sourceforge.net/pygccxml/?rev=749&view=rev
Author: roman_yakovenko
Date: 2006-11-23 00:09:53 -0800 (Thu, 23 Nov 2006)
Log Message:
-----------
fixing few bugs + adding missing transformers
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/code_repository/convenience.py
pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py
pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-22 15:20:49 UTC (rev 748)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-23 08:09:53 UTC (rev 749)
@@ -14,6 +14,9 @@
import pyplusplus.function_transformers as function_transformers
from pyplusplus import code_repository
+#TODO: constructors also can have transformation defined. We should use make _init
+# function for this purpose
+
__REMOVE_DUPLICAET_LINESEP = re.compile( '(%s){2,}' % os.linesep )
def remove_duplicate_linesep( code ):
return __REMOVE_DUPLICAET_LINESEP.sub( os.linesep, code )
@@ -74,7 +77,7 @@
this_arg_type = declarations.reference_t( this_arg_type )
self.__this_arg = declarations.argument_t(
- name=self.ft.controller.register_variable_name( 'self' )
+ name=self.ft.controller.register_variable_name( 'inst' )
, type=this_arg_type )
@property
@@ -83,8 +86,8 @@
def function_type(self):
return declarations.free_function_type_t(
- return_type=self.declaration.return_type
- , arguments_types=[ declarations.dummy_type_t( self.parent.full_name ) ]
+ return_type=self.ft.controller.wrapper_return_type
+ , arguments_types=[ self.__this_arg.type ]
+ map( lambda arg: arg.type, self.ft.controller.wrapper_args ) )
def full_name(self):
Modified: pyplusplus_dev_ft/pyplusplus/code_repository/convenience.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_repository/convenience.py 2006-11-22 15:20:49 UTC (rev 748)
+++ pyplusplus_dev_ft/pyplusplus/code_repository/convenience.py 2006-11-23 08:09:53 UTC (rev 749)
@@ -137,6 +137,7 @@
} /*pyplusplus*/ } /*convenience*/
+namespace pyplus_conv = pyplusplus::convenience;
#endif//__convenience_pyplusplus_hpp__
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py 2006-11-22 15:20:49 UTC (rev 748)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py 2006-11-23 08:09:53 UTC (rev 749)
@@ -36,12 +36,12 @@
return transformers.inout_t( function, *args, **keywd )
return creator
-#def input_array( *args, **keywd ):
- #def creator( function ):
- #return transformers.input_array_t( function, *args, **keywd )
- #return creator
+def input_array( *args, **keywd ):
+ def creator( function ):
+ return transformers.input_array_t( function, *args, **keywd )
+ return creator
-#def output_array( *args, **keywd ):
- #def creator( function ):
- #return transformers.output_array_t( function, *args, **keywd )
- #return creator
+def output_array( *args, **keywd ):
+ def creator( function ):
+ return transformers.output_array_t( function, *args, **keywd )
+ return creator
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-22 15:20:49 UTC (rev 748)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-23 08:09:53 UTC (rev 749)
@@ -16,6 +16,7 @@
- L{output_array_t}
"""
import os
+import string
import transformer
import controllers
from pygccxml import declarations
@@ -137,169 +138,135 @@
def __str__(self):
return "inout(%d)"%(self.arg_index)
- def init_funcs(self, sm):
+ def configure_mem_fun(self, controller):
assert isinstance( controller, controllers.mem_fun_controller_t )
w_arg = controller.find_wrapper_arg( self.arg.name )
w_arg.type = remove_ref_or_ptr( self.arg.type )
#adding the variable to return variables list
- controller.return_variable( w_arg )
+ controller.return_variable( w_arg.name )
-#~ # input_array_t
-#~ class input_array_t(transformer.transformer_t):
- #~ """Handles an input array with fixed size.
+class input_array_t(transformer.transformer_t):
+ """Handles an input array with fixed size.
- #~ void setVec3(double* v) -> setVec3(object v)
- #~ # v must be a sequence of 3 floats
- #~ """
+ void setVec3(double* v) -> setVec3(object v)
+ # v must be a sequence of 3 floats
+ """
- #~ def __init__(self, function, arg_ref, array_size):
- #~ """Constructor.
+ def __init__(self, function, arg_ref, size):
+ """Constructor.
- #~ @param size: The fixed size of the input array
- #~ @type size: int
- #~ """
- #~ transformer.transformer_t.__init__( self, function )
+ @param size: The fixed size of the input array
+ @type size: int
+ """
+ transformer.transformer_t.__init__( self, function )
- #~ self.arg = self.get_argument( arg_ref )
- #~ self.arg_index = self.function.arguments.index( self.arg )
+ self.arg = self.get_argument( arg_ref )
+ self.arg_index = self.function.arguments.index( self.arg )
+
+ if not is_ptr_or_array( self.arg.type ):
+ raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
+ % ( function, self.arg_ref.name, arg.type)
- #~ if not is_ptr_or_array( self.arg.type ):
- #~ raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
- #~ % ( function, self.arg_ref.name, arg.type)
+ self.array_size = size
+ self.array_item_type = declarations.array_item_type( self.arg.type )
- #~ self.array_size = array_size
- #~ self.native_array = None
- #~ self.pylist = None
+ def __str__(self):
+ return "input_array(%s,%d)"%( self.arg.name, self.array_size)
- #~ def __str__(self):
- #~ return "input_array(%s,%d)"%( self.arg.name, self.array_size)
+ def required_headers( self ):
+ """Returns list of header files that transformer generated code depends on."""
+ return [ code_repository.convenience.file_name ]
- #~ def required_headers( self ):
- #~ """Returns list of header files that transformer generated code depends on."""
- #~ return [ code_repository.convenience.file_name ]
+ @property
+ def pre_call_tmpl( self ):
+ pre_call = []
+ pre_call.append( 'pyplus_conv::ensure_uniform_sequence< $type >( $pylist, $array_size );' )
+ pre_call.append( 'pyplus_conv::copy_sequence( $pylist, pyplus_conv::array_inserter( $native_array, $array_size ) );' )
+ return string.Template( os.linesep.join( pre_call ) )
- #~ def init_funcs(self, sm):
- #~ # Remove the original argument...
- #~ sm.remove_arg(self.arg_index + 1)
+ def configure_mem_fun(self, controller):
+ assert isinstance( controller, controllers.mem_fun_controller_t )
+
+ w_arg = controller.find_wrapper_arg( self.arg.name )
+ w_arg.type = declarations.dummy_type_t( "boost::python::object" )
- #~ # Declare a variable that will hold the Python list
- #~ # (this will be the input of the Python call in the virtual function)
- #~ self.pylist = sm.virtual_func.declare_variable("py_" + self.arg.name, "boost::python::list")
+ # Declare a variable that will hold the C array...
+ native_array = controller.declare_variable( self.array_item_type
+ , "native_" + self.arg.name
+ , '[%d]' % self.array_size )
+
+ seq2arr = self.pre_call_tmpl.substitute( type=self.array_item_type
+ , pylist=w_arg.name
+ , array_size=self.array_size
+ , native_array=native_array )
+
+ controller.add_pre_call_code( seq2arr )
+
+ controller.modify_argument_expression( self.arg_index, native_array )
- #~ # Replace the removed argument with a Python object.
- #~ newarg = self.arg.clone( type=declarations.dummy_type_t("boost::python::object") )
- #~ sm.insert_arg(self.arg_index+1, newarg, self.pylist)
- #~ # Declare a variable that will hold the C array...
- #~ self.native_array = sm.wrapper_func.declare_variable(
- #~ "native_" + self.arg.name
- #~ , declarations.array_item_type( self.arg.type )
- #~ , '[%d]' % self.array_size)
+# output_array_t
+class output_array_t(transformer.transformer_t):
+ """Handles an output array of a fixed size.
- #~ # Replace the input parameter with the C array
- #~ sm.wrapper_func.input_params[self.arg_index] = self.native_array
+ void getVec3(double* v) -> v = getVec3()
+ # v will be a list with 3 floats
+ """
- #~ def wrapper_pre_call(self, sm):
- #~ """Wrapper function code.
- #~ """
- #~ tmpl = []
- #~ tmpl.append( '%(pypp_con)s::ensure_uniform_sequence< %(type)s >( %(pylist)s, %(array_size)d );' )
- #~ tmpl.append( '%(pypp_con)s::copy_sequence( %(pylist)s, %(pypp_con)s::array_inserter( %(native_array)s, %(array_size)d ) );' )
- #~ return os.linesep.join( tmpl ) % {
- #~ 'type' : declarations.array_item_type( self.arg.type )
- #~ , 'pypp_con' : 'pyplusplus::convenience'
- #~ , 'pylist' : self.arg.name
- #~ , 'array_size' : self.array_size
- #~ , 'native_array' : self.native_array
- #~ }
+ def __init__(self, function, arg_ref, size):
+ """Constructor.
- #~ def virtual_pre_call(self, sm):
- #~ """Virtual function code."""
- #~ tmpl = '%(pypp_con)s::copy_container( %(native_array)s, %(native_array)s + %(array_size)d, %(pypp_con)s::list_inserter( %(pylist)s ) );'
- #~ return tmpl % {
- #~ 'pypp_con' : 'pyplusplus::convenience'
- #~ , 'native_array' : self.arg.name
- #~ , 'array_size' : self.array_size
- #~ , 'pylist' : self.pylist
- #~ }
+ @param idx: Index of the argument that is an output array (the first arg has index 1).
+ @type idx: int
+ @param size: The fixed size of the output array
+ @type size: int
+ """
+ transformer.transformer_t.__init__( self, function )
+ self.arg = self.get_argument( arg_ref )
+ self.arg_index = self.function.arguments.index( self.arg )
+ if not is_ptr_or_array( self.arg.type ):
+ raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
+ % ( function, self.arg_ref.name, arg.type)
-#~ # output_array_t
-#~ class output_array_t(transformer.transformer_t):
- #~ """Handles an output array of a fixed size.
+ self.array_size = size
+ self.array_item_type = declarations.array_item_type( self.arg.type )
- #~ void getVec3(double* v) -> v = getVec3()
- #~ # v will be a list with 3 floats
- #~ """
+ def __str__(self):
+ return "output_array(%s,%d)"%( self.arg.name, self.array_size)
- #~ def __init__(self, function, arg_ref, size):
- #~ """Constructor.
+ def required_headers( self ):
+ """Returns list of header files that transformer generated code depends on."""
+ return [ code_repository.convenience.file_name ]
- #~ @param idx: Index of the argument that is an output array (the first arg has index 1).
- #~ @type idx: int
- #~ @param size: The fixed size of the output array
- #~ @type size: int
- #~ """
- #~ transformer.transformer_t.__init__( self, function )
- #~ self.arg = self.get_argument( arg_ref )
- #~ self.arg_index = self.function.arguments.index( self.arg )
+ @property
+ def post_call_tmpl( self ):
+ return string.Template( 'pyplus_conv::copy_container( $native_array, $native_array + $array_size, pyplus_conv::list_inserter( $pylist ) );' )
- #~ if not is_ptr_or_array( self.arg.type ):
- #~ raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
- #~ % ( function, self.arg_ref.name, arg.type)
+ def configure_mem_fun(self, controller):
+ assert isinstance( controller, controllers.mem_fun_controller_t )
+ #removing arg from the function wrapper definition
+ controller.remove_wrapper_arg( self.arg.name )
- #~ self.array_size = size
- #~ self.native_array = None
- #~ self.pylist = None
+ # Declare a variable that will hold the C array...
+ native_array = controller.declare_variable( self.array_item_type
+ , "native_" + self.arg.name
+ , '[%d]' % self.array_size )
- #~ def __str__(self):
- #~ return "output_array(%s,%d)"%( self.arg.name, self.array_size)
+ #adding just declared variable to the original function call expression
+ controller.modify_argument_expression( self.arg_index, native_array )
- #~ def required_headers( self ):
- #~ """Returns list of header files that transformer generated code depends on."""
- #~ return [ code_repository.convenience.file_name ]
-
- #~ def init_funcs(self, sm):
- #~ # Remove the original argument...
- #~ sm.remove_arg(self.arg_index + 1)
-
- #~ # Declare a variable that will hold the C array...
- #~ self.native_array = sm.wrapper_func.declare_variable(
- #~ "native_" + self.arg.name
- #~ , declarations.array_item_type( self.arg.type )
- #~ , '[%d]' % self.array_size)
-
- #~ # Declare a Python list which will receive the output...
- #~ self.pylist = sm.wrapper_func.declare_variable(
- #~ 'py_' + self.arg.name
- #~ , "boost::python::list" )
+ # Declare a Python list which will receive the output...
+ pylist = controller.declare_variable( declarations.dummy_type_t( "boost::python::list" )
+ , 'py_' + self.arg.name )
+
+ arr2seq = self.post_call_tmpl.substitute( native_array=native_array
+ , array_size=self.array_size
+ , pylist=pylist )
- #~ # ...and add it to the result
- #~ sm.wrapper_func.result_exprs.append(self.pylist)
+ controller.add_post_call_code( arr2seq )
- #~ sm.wrapper_func.input_params[ self.arg_index ] = self.native_array
+ #adding the variable to return variables list
+ controller.return_variable( pylist )
- #~ self.virtual_pylist = sm.virtual_func.declare_variable("py_"+self.arg.name, "boost::python::object")
-
- #~ def wrapper_post_call(self, sm):
- #~ tmpl = '%(pypp_con)s::copy_container( %(native_array)s, %(native_array)s + %(array_size)d, %(pypp_con)s::list_inserter( %(pylist)s ) );'
- #~ return tmpl % {
- #~ 'pypp_con' : 'pyplusplus::convenience'
- #~ , 'native_array' : self.native_array
- #~ , 'array_size' : self.array_size
- #~ , 'pylist' : self.pylist
- #~ }
-
- #~ def virtual_post_call(self, sm):
- #~ tmpl = []
- #~ tmpl.append( '%(pypp_con)s::ensure_uniform_sequence< %(type)s >( %(pylist)s, %(array_size)d );' )
- #~ tmpl.append( '%(pypp_con)s::copy_sequence( %(pylist)s, %(pypp_con)s::array_inserter( %(native_array)s, %(array_size)d ) );' )
- #~ return os.linesep.join( tmpl ) % {
- #~ 'type' : declarations.array_item_type( self.arg.type )
- #~ , 'pypp_con' : 'pyplusplus::convenience'
- #~ , 'pylist' : sm.py_result_expr(self.pylist)
- #~ , 'array_size' : self.array_size
- #~ , 'native_array' : self.arg.name
- #~ }
-
Modified: pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-22 15:20:49 UTC (rev 748)
+++ pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-23 08:09:53 UTC (rev 749)
@@ -6,18 +6,14 @@
#ifndef __function_transformations_to_be_exported_hpp__
#define __function_transformations_to_be_exported_hpp__
-#include <iostream>
-
namespace ft2{
//used to check output transformer
struct calculator_t{
calculator_t(){
- std::cout << std::endl << "=> calculator_t created";
}
virtual ~calculator_t(){
- std::cout << std::endl << "=> calculator_t destroyed" << std::endl;
}
int assign_0_1_2( int& one, int& two ){
@@ -36,7 +32,7 @@
}
};
-//used to check input transformer
+//used to check input\inout transformers
struct window_t{
window_t()
: height( 0 )
@@ -48,11 +44,39 @@
width = w;
}
+ int resize_in_out( int& h, int& w){
+ height *= h;
+ h = height;
+ width *= w;
+ w = width;
+ return h*w;
+ }
+
int height;
int width;
};
-
+struct point3d_t{
+ point3d_t()
+ : x( 0 ), y(0), z(0)
+ {}
+
+ int initialize( int v[3] ){
+ x = v[0];
+ y = v[1];
+ z = v[2];
+ return x*y*z;
+ }
+
+ void position( int v[3] ){
+ v[0] = x;
+ v[1] = y;
+ v[2] = z;
+ }
+
+ int x, y, z;
+};
+
}
//~ namespace ft{
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-22 15:20:49 UTC (rev 748)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-23 08:09:53 UTC (rev 749)
@@ -21,6 +21,9 @@
, *args )
def customize( self, mb ):
+
+ mb.global_ns.calldefs().create_with_signature = True
+
calc = mb.class_('calculator_t' )
calc.add_wrapper_code( '' )
assign_funs = calc.mem_funs( lambda decl: decl.name.startswith( 'assign' ) )
@@ -33,7 +36,12 @@
window = mb.class_( 'window_t' )
window.add_wrapper_code( '' )
window.mem_fun( 'resize' ).add_transformation( ft.input(0), ft.input(1) )
+ window.mem_fun( 'resize_in_out' ).add_transformation( ft.inout(0), ft.inout(1) )
+ point3d = mb.class_( 'point3d_t' )
+ point3d.add_wrapper_code( '' )
+ point3d.mem_fun( 'initialize' ).add_transformation( ft.input_array(0, size=3) )
+ point3d.mem_fun( 'position' ).add_transformation( ft.output_array(0, size=3) )
#~ image = mb.class_( "image_t" )
#~ image.include()
@@ -75,9 +83,16 @@
window = module.window_t()
window.height = 0
window.width = 0
- window.resize( h=1, w=2 )
+ window.resize( 1, 2 )
self.failUnless( window.height==1 and window.width==2 )
+ square, h, w = window.resize_in_out( 3, 7 )
+ self.failUnless( square == 1*3*2*7 and h==3 and w==2*7 )
+ self.failUnless( window.height==3 and window.width==2*7 )
+ point3d = module.point3d_t()
+ result = point3d.initialize( [ 1,2,3 ] )
+ self.failUnless( result== 1*2*3 and point3d.x == 1 and point3d.y==2 and point3d.z==3 )
+ self.failUnless( [1,2,3] == point3d.position()[0] )
#~ img = module.image_t( 2, 6)
# Check a method that returns two values by reference
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-22 15:20:50
|
Revision: 748
http://svn.sourceforge.net/pygccxml/?rev=748&view=rev
Author: roman_yakovenko
Date: 2006-11-22 07:20:49 -0800 (Wed, 22 Nov 2006)
Log Message:
-----------
adding transformers and improving generated code
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-22 09:26:21 UTC (rev 747)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-22 15:20:49 UTC (rev 748)
@@ -3,6 +3,7 @@
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
+import re
import os
import algorithm
import code_creator
@@ -13,8 +14,10 @@
import pyplusplus.function_transformers as function_transformers
from pyplusplus import code_repository
-######################################################################
-
+__REMOVE_DUPLICAET_LINESEP = re.compile( '(%s){2,}' % os.linesep )
+def remove_duplicate_linesep( code ):
+ return __REMOVE_DUPLICAET_LINESEP.sub( os.linesep, code )
+
class mem_fun_transformed_t( calldef_t ):
"""Creates code for public non-virtual member functions.
"""
@@ -133,10 +136,13 @@
, declarations.call_invocation.join(
declarations.templates.join( make_object, [c_p_alias] )
, [cntrl.result_variable.name] ) )
- return_stmt = declarations.call_invocation.join(
- make_tuple
- , return_vars
- , os.linesep + self.indent( self.PARAM_SEPARATOR, 6 ) )
+
+ return_stmt = declarations.call_invocation.join( make_tuple, return_vars )
+ if self.LINE_LENGTH < len( return_stmt ):
+ return_stmt = declarations.call_invocation.join(
+ make_tuple
+ , return_vars
+ , os.linesep + self.indent( self.PARAM_SEPARATOR, 6 ) )
elif not declarations.is_void( self.declaration.return_type ):
return_stmt = cntrl.result_variable.name
else:
@@ -157,7 +163,9 @@
def _create_impl(self):
answer = ['// Transformed wrapper function for "%s"' % self.declaration ]
answer.append( self.create_declaration(self.declaration.alias) + '{')
- answer.append( self.indent( self.create_body() ) )
+ body = self.create_body()
+ body = remove_duplicate_linesep( body )
+ answer.append( self.indent( body ) )
answer.append( '}' )
return os.linesep.join( answer )
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py 2006-11-22 09:26:21 UTC (rev 747)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py 2006-11-22 15:20:49 UTC (rev 748)
@@ -26,15 +26,15 @@
return transformers.output_t( function, *args, **keywd )
return creator
-#def input( *args, **keywd ):
- #def creator( function ):
- #return transformers.input_t( function, *args, **keywd )
- #return creator
+def input( *args, **keywd ):
+ def creator( function ):
+ return transformers.input_t( function, *args, **keywd )
+ return creator
-#def inout( *args, **keywd ):
- #def creator( function ):
- #return transformers.inout_t( function, *args, **keywd )
- #return creator
+def inout( *args, **keywd ):
+ def creator( function ):
+ return transformers.inout_t( function, *args, **keywd )
+ return creator
#def input_array( *args, **keywd ):
#def creator( function ):
@@ -44,4 +44,4 @@
#def output_array( *args, **keywd ):
#def creator( function ):
#return transformers.output_array_t( function, *args, **keywd )
- #return creator
\ No newline at end of file
+ #return creator
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-22 09:26:21 UTC (rev 747)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-22 15:20:49 UTC (rev 748)
@@ -67,9 +67,9 @@
def __init__( self, function ):
controller_base_t.__init__( self, function )
- self.__wrapper_args = function.arguments[:]
+ self.__wrapper_args = [ arg.clone() for arg in function.arguments ]
self.__result_var = variable_t( self.function.return_type
- , self.register_variable_name( 'result' ) )
+ , self.register_variable_name( 'result' ) )
self.__return_variables = []
self.__pre_call = []
self.__post_call = []
@@ -91,13 +91,17 @@
def wrapper_args( self ):
return self.__wrapper_args
+ def find_wrapper_arg( self, name ):
+ for arg in self.wrapper_args:
+ if arg.name == name:
+ return arg
+ return None
+
def remove_wrapper_arg( self, name ):
- for index, arg in enumerate( self.wrapper_args ):
- if arg.name == name:
- del self.wrapper_args[ index ]
- return
- else:
+ arg = self.find_wrapper_arg( name )
+ if not arg:
raise LookupError( "Unable to remove '%s' argument - not found!" % name )
+ del self.wrapper_args[ self.wrapper_args.index(arg) ]
@property
def arg_expressions( self ):
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-22 09:26:21 UTC (rev 747)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-22 15:20:49 UTC (rev 748)
@@ -77,3 +77,229 @@
controller.modify_argument_expression( self.arg_index, var_name )
#adding the variable to return variables list
controller.return_variable( var_name )
+
+# input_t
+class input_t(transformer.transformer_t):
+ """Handles a single input variable.
+
+ The reference on the specified variable is removed.
+
+ void setValue(int& v) -> setValue(v)
+ """
+
+ def __init__(self, function, arg_ref):
+ """Constructor.
+
+ The specified argument must be a reference or a pointer.
+
+ @param idx: Index of the argument that is an output value (the first arg has index 1).
+ @type idx: int
+ """
+ transformer.transformer_t.__init__( self, function )
+ self.arg = self.get_argument( arg_ref )
+ self.arg_index = self.function.arguments.index( self.arg )
+
+ if not is_ref_or_ptr( self.arg.type ):
+ raise ValueError( '%s\nin order to use "input" transformation, argument %s type must be a reference or a pointer (got %s).' ) \
+ % ( function, self.arg_ref.name, arg.type)
+
+ def __str__(self):
+ return "input(%d)"%(self.idx)
+
+ def configure_mem_fun( self, controller ):
+ assert isinstance( controller, controllers.mem_fun_controller_t )
+ w_arg = controller.find_wrapper_arg( self.arg.name )
+ w_arg.type = remove_ref_or_ptr( self.arg.type )
+
+# inout_t
+class inout_t(transformer.transformer_t):
+ """Handles a single input/output variable.
+
+ void foo(int& v) -> v = foo(v)
+ """
+
+ def __init__(self, function, arg_ref):
+ """Constructor.
+
+ The specified argument must be a reference or a pointer.
+
+ @param idx: Index of the argument that is an in/out value (the first arg has index 1).
+ @type idx: int
+ """
+ transformer.transformer_t.__init__( self, function )
+ self.arg = self.get_argument( arg_ref )
+ self.arg_index = self.function.arguments.index( self.arg )
+
+ if not is_ref_or_ptr( self.arg.type ):
+ raise ValueError( '%s\nin order to use "inout" transformation, argument %s type must be a reference or a pointer (got %s).' ) \
+ % ( function, self.arg_ref.name, arg.type)
+
+ def __str__(self):
+ return "inout(%d)"%(self.arg_index)
+
+ def init_funcs(self, sm):
+ assert isinstance( controller, controllers.mem_fun_controller_t )
+ w_arg = controller.find_wrapper_arg( self.arg.name )
+ w_arg.type = remove_ref_or_ptr( self.arg.type )
+ #adding the variable to return variables list
+ controller.return_variable( w_arg )
+
+
+#~ # input_array_t
+#~ class input_array_t(transformer.transformer_t):
+ #~ """Handles an input array with fixed size.
+
+ #~ void setVec3(double* v) -> setVec3(object v)
+ #~ # v must be a sequence of 3 floats
+ #~ """
+
+ #~ def __init__(self, function, arg_ref, array_size):
+ #~ """Constructor.
+
+ #~ @param size: The fixed size of the input array
+ #~ @type size: int
+ #~ """
+ #~ transformer.transformer_t.__init__( self, function )
+
+ #~ self.arg = self.get_argument( arg_ref )
+ #~ self.arg_index = self.function.arguments.index( self.arg )
+
+ #~ if not is_ptr_or_array( self.arg.type ):
+ #~ raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
+ #~ % ( function, self.arg_ref.name, arg.type)
+
+ #~ self.array_size = array_size
+ #~ self.native_array = None
+ #~ self.pylist = None
+
+ #~ def __str__(self):
+ #~ return "input_array(%s,%d)"%( self.arg.name, self.array_size)
+
+ #~ def required_headers( self ):
+ #~ """Returns list of header files that transformer generated code depends on."""
+ #~ return [ code_repository.convenience.file_name ]
+
+ #~ def init_funcs(self, sm):
+ #~ # Remove the original argument...
+ #~ sm.remove_arg(self.arg_index + 1)
+
+ #~ # Declare a variable that will hold the Python list
+ #~ # (this will be the input of the Python call in the virtual function)
+ #~ self.pylist = sm.virtual_func.declare_variable("py_" + self.arg.name, "boost::python::list")
+
+ #~ # Replace the removed argument with a Python object.
+ #~ newarg = self.arg.clone( type=declarations.dummy_type_t("boost::python::object") )
+ #~ sm.insert_arg(self.arg_index+1, newarg, self.pylist)
+
+ #~ # Declare a variable that will hold the C array...
+ #~ self.native_array = sm.wrapper_func.declare_variable(
+ #~ "native_" + self.arg.name
+ #~ , declarations.array_item_type( self.arg.type )
+ #~ , '[%d]' % self.array_size)
+
+ #~ # Replace the input parameter with the C array
+ #~ sm.wrapper_func.input_params[self.arg_index] = self.native_array
+
+ #~ def wrapper_pre_call(self, sm):
+ #~ """Wrapper function code.
+ #~ """
+ #~ tmpl = []
+ #~ tmpl.append( '%(pypp_con)s::ensure_uniform_sequence< %(type)s >( %(pylist)s, %(array_size)d );' )
+ #~ tmpl.append( '%(pypp_con)s::copy_sequence( %(pylist)s, %(pypp_con)s::array_inserter( %(native_array)s, %(array_size)d ) );' )
+ #~ return os.linesep.join( tmpl ) % {
+ #~ 'type' : declarations.array_item_type( self.arg.type )
+ #~ , 'pypp_con' : 'pyplusplus::convenience'
+ #~ , 'pylist' : self.arg.name
+ #~ , 'array_size' : self.array_size
+ #~ , 'native_array' : self.native_array
+ #~ }
+
+ #~ def virtual_pre_call(self, sm):
+ #~ """Virtual function code."""
+ #~ tmpl = '%(pypp_con)s::copy_container( %(native_array)s, %(native_array)s + %(array_size)d, %(pypp_con)s::list_inserter( %(pylist)s ) );'
+ #~ return tmpl % {
+ #~ 'pypp_con' : 'pyplusplus::convenience'
+ #~ , 'native_array' : self.arg.name
+ #~ , 'array_size' : self.array_size
+ #~ , 'pylist' : self.pylist
+ #~ }
+
+
+#~ # output_array_t
+#~ class output_array_t(transformer.transformer_t):
+ #~ """Handles an output array of a fixed size.
+
+ #~ void getVec3(double* v) -> v = getVec3()
+ #~ # v will be a list with 3 floats
+ #~ """
+
+ #~ def __init__(self, function, arg_ref, size):
+ #~ """Constructor.
+
+ #~ @param idx: Index of the argument that is an output array (the first arg has index 1).
+ #~ @type idx: int
+ #~ @param size: The fixed size of the output array
+ #~ @type size: int
+ #~ """
+ #~ transformer.transformer_t.__init__( self, function )
+ #~ self.arg = self.get_argument( arg_ref )
+ #~ self.arg_index = self.function.arguments.index( self.arg )
+
+ #~ if not is_ptr_or_array( self.arg.type ):
+ #~ raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
+ #~ % ( function, self.arg_ref.name, arg.type)
+
+ #~ self.array_size = size
+ #~ self.native_array = None
+ #~ self.pylist = None
+
+ #~ def __str__(self):
+ #~ return "output_array(%s,%d)"%( self.arg.name, self.array_size)
+
+ #~ def required_headers( self ):
+ #~ """Returns list of header files that transformer generated code depends on."""
+ #~ return [ code_repository.convenience.file_name ]
+
+ #~ def init_funcs(self, sm):
+ #~ # Remove the original argument...
+ #~ sm.remove_arg(self.arg_index + 1)
+
+ #~ # Declare a variable that will hold the C array...
+ #~ self.native_array = sm.wrapper_func.declare_variable(
+ #~ "native_" + self.arg.name
+ #~ , declarations.array_item_type( self.arg.type )
+ #~ , '[%d]' % self.array_size)
+
+ #~ # Declare a Python list which will receive the output...
+ #~ self.pylist = sm.wrapper_func.declare_variable(
+ #~ 'py_' + self.arg.name
+ #~ , "boost::python::list" )
+
+ #~ # ...and add it to the result
+ #~ sm.wrapper_func.result_exprs.append(self.pylist)
+
+ #~ sm.wrapper_func.input_params[ self.arg_index ] = self.native_array
+
+ #~ self.virtual_pylist = sm.virtual_func.declare_variable("py_"+self.arg.name, "boost::python::object")
+
+ #~ def wrapper_post_call(self, sm):
+ #~ tmpl = '%(pypp_con)s::copy_container( %(native_array)s, %(native_array)s + %(array_size)d, %(pypp_con)s::list_inserter( %(pylist)s ) );'
+ #~ return tmpl % {
+ #~ 'pypp_con' : 'pyplusplus::convenience'
+ #~ , 'native_array' : self.native_array
+ #~ , 'array_size' : self.array_size
+ #~ , 'pylist' : self.pylist
+ #~ }
+
+ #~ def virtual_post_call(self, sm):
+ #~ tmpl = []
+ #~ tmpl.append( '%(pypp_con)s::ensure_uniform_sequence< %(type)s >( %(pylist)s, %(array_size)d );' )
+ #~ tmpl.append( '%(pypp_con)s::copy_sequence( %(pylist)s, %(pypp_con)s::array_inserter( %(native_array)s, %(array_size)d ) );' )
+ #~ return os.linesep.join( tmpl ) % {
+ #~ 'type' : declarations.array_item_type( self.arg.type )
+ #~ , 'pypp_con' : 'pyplusplus::convenience'
+ #~ , 'pylist' : sm.py_result_expr(self.pylist)
+ #~ , 'array_size' : self.array_size
+ #~ , 'native_array' : self.arg.name
+ #~ }
+
Modified: pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-22 09:26:21 UTC (rev 747)
+++ pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-22 15:20:49 UTC (rev 748)
@@ -10,6 +10,7 @@
namespace ft2{
+//used to check output transformer
struct calculator_t{
calculator_t(){
std::cout << std::endl << "=> calculator_t created";
@@ -35,6 +36,23 @@
}
};
+//used to check input transformer
+struct window_t{
+ window_t()
+ : height( 0 )
+ , width( 0 )
+ {}
+
+ void resize( int& h, int& w ){
+ height = h;
+ width = w;
+ }
+
+ int height;
+ int width;
+};
+
+
}
//~ namespace ft{
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-22 09:26:21 UTC (rev 747)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-22 15:20:49 UTC (rev 748)
@@ -30,6 +30,11 @@
clone_and_assign_5.add_transformation( ft.output(0) )
clone_and_assign_5.call_policies = call_policies.return_value_policy( call_policies.manage_new_object )
+ window = mb.class_( 'window_t' )
+ window.add_wrapper_code( '' )
+ window.mem_fun( 'resize' ).add_transformation( ft.input(0), ft.input(1) )
+
+
#~ image = mb.class_( "image_t" )
#~ image.include()
#~ image.add_wrapper_code( '' )
@@ -67,6 +72,11 @@
#test make_object function
self.failUnless( sys.getrefcount( calc ) == sys.getrefcount( calc2 ) )
+ window = module.window_t()
+ window.height = 0
+ window.width = 0
+ window.resize( h=1, w=2 )
+ self.failUnless( window.height==1 and window.width==2 )
#~ img = module.image_t( 2, 6)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-22 09:26:21
|
Revision: 747
http://svn.sourceforge.net/pygccxml/?rev=747&view=rev
Author: roman_yakovenko
Date: 2006-11-22 01:26:21 -0800 (Wed, 22 Nov 2006)
Log Message:
-----------
adding ability to create wrapper function for function with non default call policies
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/code_repository/call_policies.py
pyplusplus_dev_ft/pyplusplus/decl_wrappers/call_policies.py
pyplusplus_dev_ft/pyplusplus/decl_wrappers/calldef_wrapper.py
pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py 2006-11-22 09:14:13 UTC (rev 746)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py 2006-11-22 09:26:21 UTC (rev 747)
@@ -47,10 +47,15 @@
def param_sep(self):
return os.linesep + self.indent( self.PARAM_SEPARATOR )
- def keywords_args(self):
+ def create_keywords_args(self):
arg_utils = calldef_utils.argument_utils_t( self.declaration, algorithm.make_id_creator( self ) )
return arg_utils.keywords_args()
+ def create_call_policies( self ):
+ if self.declaration.call_policies.is_default():
+ return ''
+ return self.declaration.call_policies.create( self )
+
def create_def_code( self ):
if not self.works_on_instance:
return '%s.def' % self.parent.class_var_name
@@ -93,17 +98,16 @@
result.append( self.create_function_ref_code( not self.works_on_instance ) )
if self.declaration.use_keywords:
- keywd_args = self.keywords_args()
+ keywd_args = self.create_keywords_args()
if keywd_args:
result.append( self.param_sep() )
result.append( keywd_args )
if self.declaration.call_policies:
- if not self.declaration.call_policies.is_default():
+ c_p_code = self.create_call_policies()
+ if c_p_code:
result.append( self.param_sep() )
- result.append( self.declaration.call_policies.create( self ) )
- else:
- pass#don't generate default_call_policies
+ result.append( c_p_code )
else:
result.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) )
@@ -778,7 +782,7 @@
answer.append( '(' )
keywords_args = None
if self.declaration.use_keywords:
- keywords_args = self.keywords_args()
+ keywords_args = self.create_keywords_args()
answer.append( '%s' % keywords_args )
if self.documentation:
if keywords_args:
@@ -1176,7 +1180,7 @@
def create_end_def_code( self ):
raise NotImplementedError()
- def keywords_args(self):
+ def create_keywords_args(self):
result = [ algorithm.create_identifier( self, '::boost::python::args' ) ]
result.append( '( ' )
args = []
@@ -1198,7 +1202,7 @@
def create_overloads_cls( self ):
result = [ self.overloads_class.name ]
result.append( '( ' )
- result.append( os.linesep + self.indent( self.keywords_args(), 3 ) )
+ result.append( os.linesep + self.indent( self.create_keywords_args(), 3 ) )
if self.overloads_class.max_function.documentation:
result.append( os.linesep + self.indent( self.PARAM_SEPARATOR, 3 ) )
result.append( self.overloads_class.max_function.documentation )
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-22 09:14:13 UTC (rev 746)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-22 09:26:21 UTC (rev 747)
@@ -43,7 +43,13 @@
else:
return '&%s' % full_name
- def keywords_args(self):
+ def create_call_policies( self ):
+ if self.ft.controller.return_variables:
+ return ''
+ else:
+ return super( mem_fun_transformed_t, self ).create_call_policies()
+
+ def create_keywords_args(self):
arg_utils = calldef_utils.argument_utils_t( self.declaration
, algorithm.make_id_creator( self )
, self.ft.controller.wrapper_args )
@@ -100,18 +106,37 @@
def create_body(self):
cntrl = self.ft.controller
+ make_object = algorithm.create_identifier( self, 'pyplusplus::call_policies::make_object' )
+ make_tuple = algorithm.create_identifier( self, 'boost::python::make_tuple' )
+
result_var_assign = ''
if not declarations.is_void( self.declaration.return_type ):
result_var_assign = '%(type)s %(name)s = ' \
% { 'type': cntrl.result_variable.type.decl_string
, 'name' : cntrl.result_variable.name }
+ post_call = os.linesep.join( cntrl.post_call )
+
return_stmt = ''
if cntrl.return_variables:
return_vars = cntrl.return_variables[:]
if not declarations.is_void( self.declaration.return_type ):
- return_vars.insert( 0, cntrl.result_variable.name )
- return_stmt = declarations.call_invocation.join( 'boost::python::make_tuple', return_vars )
+ if self.declaration.call_policies.is_default():
+ return_vars.insert( 0, cntrl.result_variable.name )
+ else:
+ c_p_alias = cntrl.register_variable_name( 'call_policies_t' )
+ c_p_typedef = 'typedef %s %s;' \
+ % ( self.declaration.call_policies.create_template_arg( self )
+ , c_p_alias )
+ post_call = os.linesep.join( [post_call, c_p_typedef] )
+ return_vars.insert( 0
+ , declarations.call_invocation.join(
+ declarations.templates.join( make_object, [c_p_alias] )
+ , [cntrl.result_variable.name] ) )
+ return_stmt = declarations.call_invocation.join(
+ make_tuple
+ , return_vars
+ , os.linesep + self.indent( self.PARAM_SEPARATOR, 6 ) )
elif not declarations.is_void( self.declaration.return_type ):
return_stmt = cntrl.result_variable.name
else:
@@ -122,7 +147,7 @@
return cntrl.template.substitute({
'declare_variables' : os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
, 'pre_call' : os.linesep.join( cntrl.pre_call )
- , 'post_call' : os.linesep.join( cntrl.post_call )
+ , 'post_call' : post_call
, 'save_result' : result_var_assign
, 'function' : self.__this_arg.name + '.' + self.declaration.name
, 'arg_expressions' : self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
Modified: pyplusplus_dev_ft/pyplusplus/code_repository/call_policies.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_repository/call_policies.py 2006-11-22 09:14:13 UTC (rev 746)
+++ pyplusplus_dev_ft/pyplusplus/code_repository/call_policies.py 2006-11-22 09:26:21 UTC (rev 747)
@@ -70,6 +70,14 @@
};
+template< typename CallPolicies, class T >
+bpl::object make_object( T const & x ){
+ //constructs object using CallPolicies result_converter
+ typedef typename CallPolicies::result_converter::apply< T >::type result_converter_t;
+ result_converter_t rc;
+ return bpl::object( bpl::handle<>( rc( x ) ) );
+}
+
} /*pyplusplus*/ } /*call_policies*/
Modified: pyplusplus_dev_ft/pyplusplus/decl_wrappers/call_policies.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/decl_wrappers/call_policies.py 2006-11-22 09:14:13 UTC (rev 746)
+++ pyplusplus_dev_ft/pyplusplus/decl_wrappers/call_policies.py 2006-11-22 09:26:21 UTC (rev 747)
@@ -38,6 +38,9 @@
code = code + '()'
return code
+ def create_template_arg( self, function_creator ):
+ return self.create( function_creator, CREATION_POLICY.AS_TEMPLATE_ARGUMENT )
+
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
@@ -227,4 +230,4 @@
"""returns True is policy represents return_value_policy<return_pointee_value>, False otherwise"""
return isinstance( policy, return_value_policy_t ) \
and policy.result_converter_generator == return_pointee_value
-
\ No newline at end of file
+
Modified: pyplusplus_dev_ft/pyplusplus/decl_wrappers/calldef_wrapper.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-11-22 09:14:13 UTC (rev 746)
+++ pyplusplus_dev_ft/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-11-22 09:26:21 UTC (rev 747)
@@ -171,7 +171,11 @@
tmp.append( "For more information see: http://mail.python.org/pipermail/c++-sig/2002-June/001554.html" )
tmp = ' '.join( tmp )
msgs.append( tmp % ( calldef_t.BOOST_PYTHON_MAX_ARITY, len( self.arguments ) ) )
-
+
+ if self.transformations:
+ #if user defined transformation, than I think it took care of the problems
+ return msgs
+
if suspicious_type( self.return_type ) and None is self.call_policies:
msgs.append( 'The function "%s" returns non-const reference to C++ fundamental type - value can not be modified from Python.' % str( self ) )
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-22 09:14:13 UTC (rev 746)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-22 09:26:21 UTC (rev 747)
@@ -7,6 +7,7 @@
"""
import controllers
+from pyplusplus import code_repository
class function_transformation_t:
def __init__(self, function, transformer_creator, **keywd):
@@ -29,6 +30,8 @@
headers = []
map( lambda transformer: headers.extend( transformer.required_headers() )
, self.transformers )
+ if self.__function.call_policies:
+ headers.append( code_repository.call_policies.file_name )
return headers
@property
Modified: pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-22 09:14:13 UTC (rev 746)
+++ pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-22 09:26:21 UTC (rev 747)
@@ -6,9 +6,18 @@
#ifndef __function_transformations_to_be_exported_hpp__
#define __function_transformations_to_be_exported_hpp__
+#include <iostream>
+
namespace ft2{
struct calculator_t{
+ calculator_t(){
+ std::cout << std::endl << "=> calculator_t created";
+ }
+
+ virtual ~calculator_t(){
+ std::cout << std::endl << "=> calculator_t destroyed" << std::endl;
+ }
int assign_0_1_2( int& one, int& two ){
one = 1;
@@ -20,6 +29,10 @@
assign_0_1_2( one, two );
}
+ calculator_t* clone_and_assign_5( int& five ){
+ five = 5;
+ return new calculator_t();
+ }
};
}
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-22 09:14:13 UTC (rev 746)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-22 09:26:21 UTC (rev 747)
@@ -9,6 +9,8 @@
import fundamental_tester_base
from pyplusplus import function_transformers as ft
from pyplusplus.module_builder import call_policies
+
+
class tester_t(fundamental_tester_base.fundamental_tester_base_t):
EXTENSION_NAME = 'function_transformations'
@@ -23,6 +25,10 @@
calc.add_wrapper_code( '' )
assign_funs = calc.mem_funs( lambda decl: decl.name.startswith( 'assign' ) )
assign_funs.add_transformation( ft.output(0), ft.output(1) )
+
+ clone_and_assign_5 = calc.mem_fun( 'clone_and_assign_5' )
+ clone_and_assign_5.add_transformation( ft.output(0) )
+ clone_and_assign_5.call_policies = call_policies.return_value_policy( call_policies.manage_new_object )
#~ image = mb.class_( "image_t" )
#~ image.include()
@@ -55,6 +61,13 @@
calc = module.calculator_t()
self.failUnless( ( 0, 1, 2 ) == calc.assign_0_1_2() )
self.failUnless( ( 1, 2 ) == calc.assign_1_2() )
+ calc2, five = calc.clone_and_assign_5()
+ self.failUnless( five == 5 )
+ self.failUnless( calc2 )
+ #test make_object function
+ self.failUnless( sys.getrefcount( calc ) == sys.getrefcount( calc2 ) )
+
+
#~ img = module.image_t( 2, 6)
# Check a method that returns two values by reference
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-22 09:14:13
|
Revision: 746
http://svn.sourceforge.net/pygccxml/?rev=746&view=rev
Author: roman_yakovenko
Date: 2006-11-22 01:14:13 -0800 (Wed, 22 Nov 2006)
Log Message:
-----------
adding arg_separator with default value
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/call_invocation.py
pygccxml_dev/pygccxml/declarations/pattern_parser.py
Modified: pygccxml_dev/pygccxml/declarations/call_invocation.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/call_invocation.py 2006-11-21 21:59:01 UTC (rev 745)
+++ pygccxml_dev/pygccxml/declarations/call_invocation.py 2006-11-22 09:14:13 UTC (rev 746)
@@ -72,7 +72,7 @@
global __THE_PARSER
return __THE_PARSER.split_recursive( decl_string )
-def join( name, args ):
+def join( name, args, arg_separator=None ):
"""returns name( argument_1, argument_2, ..., argument_n )"""
global __THE_PARSER
- return __THE_PARSER.join( name, args )
\ No newline at end of file
+ return __THE_PARSER.join( name, args, arg_separator )
Modified: pygccxml_dev/pygccxml/declarations/pattern_parser.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/pattern_parser.py 2006-11-21 21:59:01 UTC (rev 745)
+++ pygccxml_dev/pygccxml/declarations/pattern_parser.py 2006-11-22 09:14:13 UTC (rev 746)
@@ -112,8 +112,10 @@
to_go.append( arg )
return answer
- def join( self, name, args ):
+ def join( self, name, args, arg_separator=None ):
"""implementation details"""
+ if None is arg_separator:
+ arg_separator = ', '
args = filter( None, args)
args_str = ''
if not args:
@@ -121,7 +123,7 @@
elif 1 == len( args ):
args_str = ' ' + args[0] + ' '
else:
- args_str = ' ' + ', '.join( args ) + ' '
+ args_str = ' ' + arg_separator.join( args ) + ' '
return ''.join( [ name, self.__begin, args_str, self.__end ] )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-21 21:59:02
|
Revision: 745
http://svn.sourceforge.net/pygccxml/?rev=745&view=rev
Author: roman_yakovenko
Date: 2006-11-21 13:59:01 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
generated code now works as expected
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 20:48:45 UTC (rev 744)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 21:59:01 UTC (rev 745)
@@ -99,22 +99,35 @@
def create_body(self):
cntrl = self.ft.controller
- save_return_value_stmt = ''
- if not cntrl.save_return_value_stmt \
- and not declarations.is_void( self.declaration.return_type ):
- save_return_value_stmt = '%(type)s %(name)s = ' \
- % { 'type': cntrl.result_variable.type.decl_string
- , 'name' : cntrl.result_variable.name }
+
+ result_var_assign = ''
+ if not declarations.is_void( self.declaration.return_type ):
+ result_var_assign = '%(type)s %(name)s = ' \
+ % { 'type': cntrl.result_variable.type.decl_string
+ , 'name' : cntrl.result_variable.name }
+
+ return_stmt = ''
+ if cntrl.return_variables:
+ return_vars = cntrl.return_variables[:]
+ if not declarations.is_void( self.declaration.return_type ):
+ return_vars.insert( 0, cntrl.result_variable.name )
+ return_stmt = declarations.call_invocation.join( 'boost::python::make_tuple', return_vars )
+ elif not declarations.is_void( self.declaration.return_type ):
+ return_stmt = cntrl.result_variable.name
+ else:
+ pass
+ if return_stmt:
+ return_stmt = 'return ' + return_stmt + ';'
- return cntrl.template.substitute(
- declare_variables=os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
- , pre_call=os.linesep.join( cntrl.pre_call )
- , post_call=os.linesep.join( cntrl.post_call )
- , save_return_value_stmt=save_return_value_stmt
- , function=self.__this_arg.name + '.' + self.declaration.name
- , arg_expressions=self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
- , return_stmt=''
- )
+ return cntrl.template.substitute({
+ 'declare_variables' : os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
+ , 'pre_call' : os.linesep.join( cntrl.pre_call )
+ , 'post_call' : os.linesep.join( cntrl.post_call )
+ , 'save_result' : result_var_assign
+ , 'function' : self.__this_arg.name + '.' + self.declaration.name
+ , 'arg_expressions' : self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
+ , 'return' : return_stmt
+ })
def _create_impl(self):
answer = ['// Transformed wrapper function for "%s"' % self.declaration ]
@@ -446,4 +459,4 @@
#~ self.declaration.arguments = self._subst_manager.wrapper_func.arg_list
#~ return answer
-
\ No newline at end of file
+
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 20:48:45 UTC (rev 744)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 21:59:01 UTC (rev 745)
@@ -68,7 +68,6 @@
def __init__( self, function ):
controller_base_t.__init__( self, function )
self.__wrapper_args = function.arguments[:]
- self.__wrapper_return_type = function.return_type
self.__result_var = variable_t( self.function.return_type
, self.register_variable_name( 'result' ) )
self.__return_variables = []
@@ -76,7 +75,6 @@
self.__post_call = []
self.__save_return_value_stmt = None
self.__arg_expressions = [ arg.name for arg in function.arguments ]
- self.__return_stmt = None
def apply( self, transformations ):
map( lambda t: t.configure_mem_fun( self ), transformations )
@@ -107,14 +105,13 @@
def modify_argument_expression( self, index, expression ):
self.arg_expressions[ index ] = expression
-
- def __get_wrapper_return_type( self ):
- return self.__wrapper_return_type
- def __set_wrapper_return_type( self, type_ ):
- if isinstane( type, types.StringTypes ):
- type_ = declarations.dummy_type_t( type_ )
- self.__wrapper_return_type = type_
- wrapper_return_type = property( __get_wrapper_return_type, __set_wrapper_return_type )
+
+ @property
+ def wrapper_return_type( self ):
+ if len( self.return_variables ):
+ return declarations.dummy_type_t( 'boost::python::tuple' )
+ else:
+ return self.function.return_type
@property
def return_variables( self ):
@@ -136,12 +133,6 @@
def add_post_call_code( self, code ):
self.__post_call.append( code )
-
- def __get_save_return_value_stmt( self ):
- return self.__save_return_value_stmt
- def __set_save_return_value_stmt( self, expr ):
- self.__save_return_value_stmt = expr
- save_return_value_stmt = property( __get_save_return_value_stmt, __set_save_return_value_stmt )
def set_input_param( self, index, var_name_or_expr ):
self.__input_params[ index ] = var_name_or_expr
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-21 20:48:45 UTC (rev 744)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-21 21:59:01 UTC (rev 745)
@@ -15,9 +15,9 @@
body = Template( os.linesep.join([
'$declare_variables'
, '$pre_call'
- , '$save_return_value_stmt$function($arg_expressions);'
+ , '$save_result$function($arg_expressions);'
, '$post_call'
- , '$return_stmt'
+ , '$return'
]))
class mem_fun_v:
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 20:48:45 UTC (rev 744)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 21:59:01 UTC (rev 745)
@@ -52,7 +52,9 @@
"""
####### Do the tests directly on the wrapper C++ class ########
-
+ calc = module.calculator_t()
+ self.failUnless( ( 0, 1, 2 ) == calc.assign_0_1_2() )
+ self.failUnless( ( 1, 2 ) == calc.assign_1_2() )
#~ img = module.image_t( 2, 6)
# Check a method that returns two values by reference
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-21 20:48:49
|
Revision: 744
http://svn.sourceforge.net/pygccxml/?rev=744&view=rev
Author: roman_yakovenko
Date: 2006-11-21 12:48:45 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
adding shortcuts
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/namespace.py
pygccxml_dev/pygccxml/declarations/scopedef.py
Modified: pygccxml_dev/pygccxml/declarations/namespace.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/namespace.py 2006-11-21 20:47:59 UTC (rev 743)
+++ pygccxml_dev/pygccxml/declarations/namespace.py 2006-11-21 20:48:45 UTC (rev 744)
@@ -92,7 +92,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive )
-
+ free_fun = free_function
+
def free_functions( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None, allow_empty=None ):
"""returns a set of free function declarations, that are matched defined criterias"""
return self._find_multiple( scopedef.scopedef_t._impl_matchers[ namespace_t.free_function ]
@@ -105,6 +106,7 @@
, header_file=header_file
, recursive=recursive
, allow_empty=allow_empty)
+ free_funs = free_functions
def free_operator( self, name=None, function=None, symbol=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""returns reference to free operator declaration, that is matched defined criterias"""
Modified: pygccxml_dev/pygccxml/declarations/scopedef.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/scopedef.py 2006-11-21 20:47:59 UTC (rev 743)
+++ pygccxml_dev/pygccxml/declarations/scopedef.py 2006-11-21 20:48:45 UTC (rev 744)
@@ -398,7 +398,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive)
-
+ var = variable #small alias
+
def variables( self, name=None, function=None, type=None, header_dir=None, header_file=None, recursive=None, allow_empty=None ):
"""returns a set of variable declarations, that are matched defined criterias"""
return self._find_multiple( self._impl_matchers[ scopedef_t.variable ]
@@ -409,7 +410,8 @@
, header_file=header_file
, recursive=recursive
, allow_empty=allow_empty)
-
+ vars = variables #small alias
+
def calldef( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""returns reference to "calldef" declaration, that is matched defined criterias"""
return self._find_single( self._impl_matchers[ scopedef_t.calldef ]
@@ -473,7 +475,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive )
-
+ mem_fun = member_function
+
def member_functions( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None, allow_empty=None ):
"""returns a set of member function declarations, that are matched defined criterias"""
return self._find_multiple( self._impl_matchers[ scopedef_t.member_function ]
@@ -486,7 +489,8 @@
, header_file=header_file
, recursive=recursive
, allow_empty=allow_empty)
-
+ mem_funs = member_functions
+
def constructor( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""returns reference to constructor declaration, that is matched defined criterias"""
return self._find_single( self._impl_matchers[ scopedef_t.constructor ]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-21 20:48:01
|
Revision: 743
http://svn.sourceforge.net/pygccxml/?rev=743&view=rev
Author: roman_yakovenko
Date: 2006-11-21 12:47:59 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
the generated code could be compiled
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
pyplusplus_dev_ft/pyplusplus/module_builder/builder.py
pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -93,8 +93,10 @@
result.append( self.create_function_ref_code( not self.works_on_instance ) )
if self.declaration.use_keywords:
- result.append( self.param_sep() )
- result.append( self.keywords_args() )
+ keywd_args = self.keywords_args()
+ if keywd_args:
+ result.append( self.param_sep() )
+ result.append( keywd_args )
if self.declaration.call_policies:
if not self.declaration.call_policies.is_default():
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -21,7 +21,8 @@
def __init__( self, function, wrapper=None ):
calldef_t.__init__( self, function=function, wrapper=wrapper )
-
+ #map( lambda transformer: transformer.configure_mem_fun
+
@property
def ft( self ): #function transformation
return self.declaration.transformations[0]
@@ -98,16 +99,18 @@
def create_body(self):
cntrl = self.ft.controller
- arg_utils = calldef_utils.argument_utils_t(
- self.declaration
- , algorithm.make_id_creator( self )
- , cntrl.wrapper_args )
-
+ save_return_value_stmt = ''
+ if not cntrl.save_return_value_stmt \
+ and not declarations.is_void( self.declaration.return_type ):
+ save_return_value_stmt = '%(type)s %(name)s = ' \
+ % { 'type': cntrl.result_variable.type.decl_string
+ , 'name' : cntrl.result_variable.name }
+
return cntrl.template.substitute(
- declare_variables=map( lambda var: var.declare_var_string(), cntrl.variables )
+ declare_variables=os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
, pre_call=os.linesep.join( cntrl.pre_call )
, post_call=os.linesep.join( cntrl.post_call )
- , save_return_value_stmt=cntrl.save_return_value_stmt
+ , save_return_value_stmt=save_return_value_stmt
, function=self.__this_arg.name + '.' + self.declaration.name
, arg_expressions=self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
, return_stmt=''
@@ -443,4 +446,4 @@
#~ self.declaration.arguments = self._subst_manager.wrapper_func.arg_list
#~ return answer
-
+
\ No newline at end of file
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -39,6 +39,8 @@
return False
def keywords_args(self):
+ if not self.__args:
+ return ''
boost_arg = self.__id_creator( '::boost::python::arg' )
boost_obj = self.__id_creator( '::boost::python::object' )
result = ['( ']
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -3,7 +3,7 @@
from pygccxml import declarations
class variable_t( object ):
- def __init__( self, name, type, initialize_expr='' ):
+ def __init__( self, type, name, initialize_expr='' ):
self.__name = name
self.__type = type
self.__initialize_expr = initialize_expr
@@ -30,7 +30,7 @@
def __init__( self, function ):
object.__init__( self )
self.__function = function
- self.__variables = {} #name : variable
+ self.__variables = [] #variables
self.__names_in_use = set( map( lambda arg: arg.name, self.function.arguments ) )
@property
@@ -43,7 +43,8 @@
def declare_variable( self, type, name, initialize_expr='' ):
unique_name = self.__create_unique_var_name( name )
- self.__variables[ unique_name ] = variable_t( type, unique_name, initialize_expr )
+ self.__variables.append( variable_t( type, unique_name, initialize_expr ) )
+ return unique_name
def register_variable_name( self, name ):
return self.__create_unique_var_name( name )
@@ -53,19 +54,23 @@
unique_name = name
while 1:
if unique_name in self.__names_in_use:
- unique_name = "%s_%d" % ( name, n )
+ unique_name = "%s%d" % ( name, n )
n += 1
else:
self.__names_in_use.add( unique_name )
return unique_name
+ def apply( self, transformations ):
+ raise NotImplementedError()
+
class mem_fun_controller_t( controller_base_t ):
def __init__( self, function ):
controller_base_t.__init__( self, function )
self.__wrapper_args = function.arguments[:]
self.__wrapper_return_type = function.return_type
-
+ self.__result_var = variable_t( self.function.return_type
+ , self.register_variable_name( 'result' ) )
self.__return_variables = []
self.__pre_call = []
self.__post_call = []
@@ -73,6 +78,12 @@
self.__arg_expressions = [ arg.name for arg in function.arguments ]
self.__return_stmt = None
+ def apply( self, transformations ):
+ map( lambda t: t.configure_mem_fun( self ), transformations )
+
+ @property
+ def result_variable( self ):
+ return self.__result_var
@property
def template( self ):
@@ -110,7 +121,7 @@
return self.__return_variables
def return_variable( self, variable_name ):
- self.__return_variables.append( name )
+ self.__return_variables.append( variable_name )
@property
def pre_call( self ):
@@ -142,3 +153,4 @@
def set_return_stmt( self, stmt ):
self.__return_stmt = stmt
+
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -15,6 +15,7 @@
self.__controller = controllers.mem_fun_controller_t( function )
self.__transformers = map( lambda tr_creator: tr_creator( function ), transformer_creator )
self.__thread_safe = keywd.get( 'thread_safe', False )
+ self.__controller.apply( self.__transformers )
@property
def transformers( self ):
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -77,4 +77,3 @@
controller.modify_argument_expression( self.arg_index, var_name )
#adding the variable to return variables list
controller.return_variable( var_name )
-
Modified: pyplusplus_dev_ft/pyplusplus/module_builder/builder.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/module_builder/builder.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/module_builder/builder.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -378,7 +378,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive)
-
+ var = variable
+
def variables( self, name=None, function=None, type=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.scopedef_t} class documentation"""
return self.global_ns.variables( name=name
@@ -387,7 +388,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive)
-
+ vars = variables
+
def calldef( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.scopedef_t} class documentation"""
return self.global_ns.calldef( name=name
@@ -441,6 +443,7 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive )
+ mem_fun = member_function
def member_functions( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.scopedef_t} class documentation"""
@@ -452,6 +455,8 @@
, header_file=header_file
, recursive=recursive)
+ mem_funs = member_functions
+
def constructor( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.scopedef_t} class documentation"""
return self.global_ns.constructor( name=name
@@ -554,7 +559,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive )
-
+ free_fun = free_function
+
def free_functions( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.namespace_t} class documentation"""
return self.global_ns.free_functions( name=name
@@ -564,7 +570,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive)
-
+ free_funs = free_functions
+
def free_operator( self, name=None, function=None, symbol=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.namespace_t} class documentation"""
return self.global_ns.free_operator( name=name
Modified: pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-21 20:47:59 UTC (rev 743)
@@ -6,98 +6,116 @@
#ifndef __function_transformations_to_be_exported_hpp__
#define __function_transformations_to_be_exported_hpp__
-namespace ft{
+namespace ft2{
+
+struct calculator_t{
+
+ int assign_0_1_2( int& one, int& two ){
+ one = 1;
+ two = 2;
+ return 0;
+ }
+
+ void assign_1_2( int& one, int& two ){
+ assign_0_1_2( one, two );
+ }
+
+};
-struct image_t{
+}
- image_t( unsigned int h, unsigned int w )
- : m_height( h )
- , m_width( w )
- {}
+//~ namespace ft{
- // Made the method 'virtual' for now because func transformers
- // are currently only taken into account on virtual functions.
- void get_size( unsigned int& h, unsigned int& w ){
- h = m_height;
- w = m_width;
- }
+//~ struct image_t{
- // Return only one value
- virtual void get_one_value(unsigned int& h) {
- h = m_height;
- }
+ //~ image_t( unsigned int h, unsigned int w )
+ //~ : m_height( h )
+ //~ , m_width( w )
+ //~ {}
- // Like get_size() but with a return type and an additional argument
- // that has to be kept in the signature
- virtual int get_size2( unsigned int& h, unsigned int& w, int noref=0 ){
- h = m_height;
- w = m_width;
- return noref;
- }
+ //~ // Made the method 'virtual' for now because func transformers
+ //~ // are currently only taken into account on virtual functions.
+ //~ void get_size( unsigned int& h, unsigned int& w ){
+ //~ h = m_height;
+ //~ w = m_width;
+ //~ }
- // A method with an input argument
- virtual int input_arg(int& in){
- return in;
- }
+ //~ // Return only one value
+ //~ virtual void get_one_value(unsigned int& h) {
+ //~ h = m_height;
+ //~ }
- // A method taking an input array of fixed size
- virtual int fixed_input_array(int v[3]) {
- return v[0]+v[1]+v[2];
- }
+ //~ // Like get_size() but with a return type and an additional argument
+ //~ // that has to be kept in the signature
+ //~ virtual int get_size2( unsigned int& h, unsigned int& w, int noref=0 ){
+ //~ h = m_height;
+ //~ w = m_width;
+ //~ return noref;
+ //~ }
- // A method with a output array of fixed size
- virtual void fixed_output_array(int v[3]) {
- v[0] = 1;
- v[1] = 2;
- v[2] = 3;
- }
+ //~ // A method with an input argument
+ //~ virtual int input_arg(int& in){
+ //~ return in;
+ //~ }
- unsigned int m_width;
- unsigned int m_height;
+ //~ // A method taking an input array of fixed size
+ //~ virtual int fixed_input_array(int v[3]) {
+ //~ return v[0]+v[1]+v[2];
+ //~ }
-};
+ //~ // A method with a output array of fixed size
+ //~ virtual void fixed_output_array(int v[3]) {
+ //~ v[0] = 1;
+ //~ v[1] = 2;
+ //~ v[2] = 3;
+ //~ }
-// Provide an instance created in C++ (i.e. this is not a wrapper instance)
-image_t cpp_instance(12,13);
-image_t& get_cpp_instance() {
- return cpp_instance;
-}
+ //~ unsigned int m_width;
+ //~ unsigned int m_height;
-inline void
-get_image_size( image_t& img, unsigned int& h, unsigned int& w ){
- img.get_size( h, w );
-}
+//~ };
-// This is used for calling img.get_one_value() on an instance passed
-// in by Python.
-unsigned int get_image_one_value( image_t& img ) {
- unsigned int v;
- img.get_one_value(v);
- return v;
-}
+//~ // Provide an instance created in C++ (i.e. this is not a wrapper instance)
+//~ image_t cpp_instance(12,13);
+//~ image_t& get_cpp_instance() {
+ //~ return cpp_instance;
+//~ }
-// This is used for calling img.fixed_output_array() on an instance passed
-// in by Python.
-int image_fixed_output_array( image_t& img) {
- int v[3];
- img.fixed_output_array(v);
- return v[0]+v[1]+v[2];
-}
+//~ inline void
+//~ get_image_size( image_t& img, unsigned int& h, unsigned int& w ){
+ //~ img.get_size( h, w );
+//~ }
-//////////////////////////////////////////////////////////////////////
+//~ // This is used for calling img.get_one_value() on an instance passed
+//~ // in by Python.
+//~ unsigned int get_image_one_value( image_t& img ) {
+ //~ unsigned int v;
+ //~ img.get_one_value(v);
+ //~ return v;
+//~ }
-// A class without any virtual members
-struct no_virtual_members_t
-{
- bool member(int& v) { v=17; return true; }
-};
+//~ // This is used for calling img.fixed_output_array() on an instance passed
+//~ // in by Python.
+//~ int image_fixed_output_array( image_t& img) {
+ //~ int v[3];
+ //~ img.fixed_output_array(v);
+ //~ return v[0]+v[1]+v[2];
+//~ }
-struct ft_private_destructor_t{
- static void get_value( int& x ){ x = 21; }
-private:
- ~ft_private_destructor_t(){}
-};
+//~ //////////////////////////////////////////////////////////////////////
-}
+//~ // A class without any virtual members
+//~ struct no_virtual_members_t
+//~ {
+ //~ bool member(int& v) { v=17; return true; }
+//~ };
+//~ struct ft_private_destructor_t{
+ //~ static void get_value( int& x ){ x = 21; }
+//~ private:
+ //~ ~ft_private_destructor_t(){}
+//~ };
+
+//~ }
+
#endif//__function_transformations_to_be_exported_hpp__
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -19,13 +19,17 @@
, *args )
def customize( self, mb ):
- mb.namespace( 'ft' ).exclude()
- image = mb.class_( "image_t" )
- image.include()
- image.add_wrapper_code( '' )
- image.member_functions().exclude()
- image.member_function( "get_size" ).include()
- image.member_function( "get_size" ).add_transformation( ft.output(0), ft.output(1) )
+ calc = mb.class_('calculator_t' )
+ calc.add_wrapper_code( '' )
+ assign_funs = calc.mem_funs( lambda decl: decl.name.startswith( 'assign' ) )
+ assign_funs.add_transformation( ft.output(0), ft.output(1) )
+
+ #~ image = mb.class_( "image_t" )
+ #~ image.include()
+ #~ image.add_wrapper_code( '' )
+ #~ image.member_functions().exclude()
+ #~ image.member_function( "get_size" ).include()
+ #~ image.member_function( "get_size" ).add_transformation( ft.output(0), ft.output(1) )
#~ image.member_function( "get_one_value" ).add_transformation( ft.output(0) )
#~ image.member_function( "get_size2" ).add_transformation( ft.output(0), ft.output(1) )
#~ image.member_function( "input_arg" ).add_transformation( ft.input(0) )
@@ -49,10 +53,10 @@
####### Do the tests directly on the wrapper C++ class ########
- img = module.image_t( 2, 6)
+ #~ img = module.image_t( 2, 6)
# Check a method that returns two values by reference
- self.assertEqual(img.get_size(), (2,6))
+ #~ self.assertEqual(img.get_size(), (2,6))
#~ # Check a method that only returns one value by reference
#~ self.assertEqual(img.get_one_value(), 2)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-21 13:00:32
|
Revision: 742
http://svn.sourceforge.net/pygccxml/?rev=742&view=rev
Author: roman_yakovenko
Date: 2006-11-21 05:00:32 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/__init__.py
pyplusplus_dev_ft/pyplusplus/code_creators/algorithm.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
pyplusplus_dev_ft/pyplusplus/function_transformers/transformer.py
pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/__init__.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/__init__.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/__init__.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -78,8 +78,8 @@
from calldef_transformed import mem_fun_transformed_t
from calldef_transformed import mem_fun_transformed_wrapper_t
-from calldef_transformed import mem_fun_v_transformed_t
-from calldef_transformed import mem_fun_v_transformed_wrapper_t
+#~ from calldef_transformed import mem_fun_v_transformed_t
+#~ from calldef_transformed import mem_fun_v_transformed_wrapper_t
from global_variable import global_variable_base_t
from global_variable import global_variable_t
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/algorithm.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/algorithm.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/algorithm.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -99,3 +99,6 @@
if recursive:
search_area = make_flatten_generator( where )
return filter( lambda inst: isinstance( inst, what ), search_area )
+
+def make_id_creator( code_creator ):
+ return lambda decl_string: create_identifier( code_creator, decl_string )
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -19,9 +19,6 @@
#protected member functions - call, override
#private - override
-def make_id_creator( code_creator ):
- return lambda decl_string: algorithm.create_identifier( code_creator, decl_string )
-
class calldef_t( registration_based.registration_based_t
, declaration_based.declaration_based_t ):
def __init__(self, function, wrapper=None ):
@@ -51,7 +48,7 @@
return os.linesep + self.indent( self.PARAM_SEPARATOR )
def keywords_args(self):
- arg_utils = calldef_utils.argument_utils_t( self.declaration, make_id_creator( self ) )
+ arg_utils = calldef_utils.argument_utils_t( self.declaration, algorithm.make_id_creator( self ) )
return arg_utils.keywords_args()
def create_def_code( self ):
@@ -139,11 +136,11 @@
return algorithm.create_identifier( self, '::boost::python::override' )
def function_call_args( self ):
- arg_utils = calldef_utils.argument_utils_t( self.declaration, make_id_creator( self ) )
+ arg_utils = calldef_utils.argument_utils_t( self.declaration, algorithm.make_id_creator( self ) )
return arg_utils.call_args()
def args_declaration( self ):
- arg_utils = calldef_utils.argument_utils_t( self.declaration, make_id_creator( self ) )
+ arg_utils = calldef_utils.argument_utils_t( self.declaration, algorithm.make_id_creator( self ) )
return arg_utils.args_declaration()
def wrapped_class_identifier( self ):
@@ -841,7 +838,7 @@
def _create_constructor_call( self ):
answer = [ algorithm.create_identifier( self, self.parent.declaration.decl_string ) ]
answer.append( '( ' )
- arg_utils = calldef_utils.argument_utils_t( self.declaration, make_id_creator( self ) )
+ arg_utils = calldef_utils.argument_utils_t( self.declaration, algorithm.make_id_creator( self ) )
params = arg_utils.call_args()
answer.append( params )
if params:
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -4,8 +4,9 @@
# http://www.boost.org/LICENSE_1_0.txt)
import os
-#import algorithm
-#import code_creator
+import algorithm
+import code_creator
+import calldef_utils
import class_declaration
from pygccxml import declarations
from calldef import calldef_t, calldef_wrapper_t
@@ -21,42 +22,34 @@
def __init__( self, function, wrapper=None ):
calldef_t.__init__( self, function=function, wrapper=wrapper )
+ @property
+ def ft( self ): #function transformation
+ return self.declaration.transformations[0]
+
def create_function_type_alias_code( self, exported_class_alias=None ):
- if self.wrapper==None:
- ftype = self.declaration.function_type()
- else:
- ftype = self.wrapper.function_type()
- res = 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias )
- return res
+ ftype = self.wrapper.function_type()
+ return 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias )
def create_function_ref_code(self, use_function_alias=False):
- if self.wrapper:
- full_name = self.wrapper.full_name()
- else:
- full_name = declarations.full_name( self.declaration )
+ full_name = self.wrapper.full_name()
if use_function_alias:
return '%s( &%s )' \
% ( self.function_type_alias, full_name )
elif self.declaration.create_with_signature:
- if self.wrapper:
- func_type = self.wrapper.function_type()
- else:
- func_type = self.declaration.function_type().decl_string
- return '(%s)( &%s )' \
- % ( func_type, full_name )
+ func_type = self.wrapper.function_type()
+ return '(%s)( &%s )' % ( func_type, full_name )
else:
return '&%s' % full_name
+ def keywords_args(self):
+ arg_utils = calldef_utils.argument_utils_t( self.declaration
+ , algorithm.make_id_creator( self )
+ , self.ft.controller.wrapper_args )
+ return arg_utils.keywords_args()
-class mem_fun_transformed_wrapper_t( calldef_wrapper_t ):
- """Creates wrapper code for (public) non-virtual member functions.
- The generated function is either used as a static member inside the
- wrapper class (when self.parent is not None) or as a free function
- (when self.parent is None).
- """
-
+class mem_fun_transformed_wrapper_t( calldef_wrapper_t ):
def __init__( self, function ):
"""Constructor.
@@ -64,422 +57,390 @@
@type function: calldef_t
"""
calldef_wrapper_t.__init__( self, function=function )
+
+ this_arg_type = declarations.declarated_t( self.declaration.parent )
+ if self.declaration.has_const:
+ this_arg_type = declarations.const_t( this_arg_type )
+ this_arg_type = declarations.reference_t( this_arg_type )
+
+ self.__this_arg = declarations.argument_t(
+ name=self.ft.controller.register_variable_name( 'self' )
+ , type=this_arg_type )
+
+ @property
+ def ft( self ): #function transformation
+ return self.declaration.transformations[0]
- # Create the substitution manager
- sm = function_transformers.substitution_manager_t( function
- , transformers=function.transformations[0].transformers)
- sm.init_funcs()
- self._subst_manager = sm
-
def function_type(self):
- """Return the type of the wrapper function.
-
- @rtype: type_t
- """
- template = '$RET_TYPE'
- rettype = self._subst_manager.subst_wrapper(template)
- rettype = declarations.dummy_type_t(rettype)
-
return declarations.free_function_type_t(
- return_type=rettype
- , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) )
+ return_type=self.declaration.return_type
+ , arguments_types=[ declarations.dummy_type_t( self.parent.full_name ) ]
+ + map( lambda arg: arg.type, self.ft.controller.wrapper_args ) )
- def wrapper_name(self):
- """Return the name of the wrapper function.
-
- This is just the local name without any scope information.
- """
- # A list with the individual components of the name
- components = ["_py"]
- # Is the wrapper placed outside a wrapper class?
- if not isinstance(self.parent, class_declaration.class_wrapper_t):
- # Incorporate the original class name into the name
- components.append(self.declaration.parent.name)
- components.append(self.declaration.alias)
- return "_".join(components)
-
def full_name(self):
- """Return the full name of the wrapper function.
+ return self.parent.full_name + '::' + self.declaration.name
- The returned name also includes the class name (if there is any).
+ def args_declaration( self ):
+ arg_utils = calldef_utils.argument_utils_t(
+ self.declaration
+ , algorithm.make_id_creator( self )
+ , [ self.__this_arg ] + self.ft.controller.wrapper_args )
+ return arg_utils.args_declaration()
- @rtype: str
- """
- if isinstance(self.parent, class_declaration.class_wrapper_t):
- return self.parent.full_name + '::' + self.wrapper_name()
- else:
- return self.wrapper_name()
-
def create_declaration(self, name):
- """Create the function header.
- """
- template = 'static $RET_TYPE %(name)s( $ARG_LIST_DEF ) %(throw)s'
+ template = 'static %(return_type)s %(name)s( %(args)s )'
- # Substitute the $-variables
- template = self._subst_manager.subst_wrapper(template)
-
return template % {
- 'name' : self.wrapper_name()
- , 'throw' : self.throw_specifier_code()
+ 'return_type' : self.ft.controller.wrapper_return_type.decl_string
+ , 'name' : self.declaration.name
+ , 'args' : self.args_declaration()
}
def create_body(self):
- body = os.linesep.join([
- '$DECLARATIONS'
- , '$PRE_CALL'
- , '$RESULT_VAR_ASSIGNMENT$CALL_FUNC_NAME($INPUT_PARAMS);'
- , '$POST_CALL'
- , '$RETURN_STMT'
- ])
+ cntrl = self.ft.controller
+ arg_utils = calldef_utils.argument_utils_t(
+ self.declaration
+ , algorithm.make_id_creator( self )
+ , cntrl.wrapper_args )
- # Replace the $-variables
- body = self._subst_manager.subst_wrapper(body)
-
- return body
-
- def create_function(self):
- answer = [70*"/"]
- answer.append("// Transformed wrapper function for:")
- answer.append("// %s"%self.declaration)
- answer.append(70*"/")
+ return cntrl.template.substitute(
+ declare_variables=map( lambda var: var.declare_var_string(), cntrl.variables )
+ , pre_call=os.linesep.join( cntrl.pre_call )
+ , post_call=os.linesep.join( cntrl.post_call )
+ , save_return_value_stmt=cntrl.save_return_value_stmt
+ , function=self.__this_arg.name + '.' + self.declaration.name
+ , arg_expressions=self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
+ , return_stmt=''
+ )
+
+ def _create_impl(self):
+ answer = ['// Transformed wrapper function for "%s"' % self.declaration ]
answer.append( self.create_declaration(self.declaration.alias) + '{')
answer.append( self.indent( self.create_body() ) )
answer.append( '}' )
return os.linesep.join( answer )
- def _create_impl(self):
+#~ ######################################################################
- answer = self.create_function()
+#~ class mem_fun_v_transformed_t( calldef_t ):
+ #~ """Creates code for (public) virtual member functions.
+ #~ """
- # Replace the argument list of the declaration so that in the
- # case that keywords are created, the correct arguments will be
- # picked up (i.e. the modified argument list and not the original
- # argument list)
- self.declaration.arguments = self._subst_manager.wrapper_func.arg_list
+ #~ def __init__( self, function, wrapper=None ):
+ #~ calldef_t.__init__( self, function=function, wrapper=wrapper )
+ #~ self.default_function_type_alias = 'default_' + self.function_type_alias
- return answer
+ #~ def create_function_type_alias_code( self, exported_class_alias=None ):
+ #~ if self.wrapper==None:
+ #~ ftype = self.declaration.function_type()
+ #~ else:
+ #~ ftype = self.wrapper.function_type()
-######################################################################
+ #~ result = []
+ #~ result.append( 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) )
+ #~ return ''.join( result )
-class mem_fun_v_transformed_t( calldef_t ):
- """Creates code for (public) virtual member functions.
- """
+ #~ def create_doc(self):
+ #~ return None
- def __init__( self, function, wrapper=None ):
- calldef_t.__init__( self, function=function, wrapper=wrapper )
- self.default_function_type_alias = 'default_' + self.function_type_alias
+ #~ def create_function_ref_code(self, use_function_alias=False):
+ #~ if self.wrapper:
+ #~ full_name = self.wrapper.default_full_name()
+ #~ else:
+ #~ full_name = declarations.full_name( self.declaration )
- def create_function_type_alias_code( self, exported_class_alias=None ):
- if self.wrapper==None:
- ftype = self.declaration.function_type()
- else:
- ftype = self.wrapper.function_type()
+ #~ result = []
+ #~ if use_function_alias:
+ #~ result.append( '%s(&%s)'
+ #~ % ( self.function_type_alias, full_name ) )
+ #~ elif self.declaration.create_with_signature:
+ #~ if self.wrapper:
+ #~ func_type = self.wrapper.function_type()
+ #~ else:
+ #~ func_type = self.declaration.function_type().decl_string
+ #~ result.append( '(%s)(&%s)'
+ #~ % ( func_type, full_name ) )
+ #~ else:
+ #~ result.append( '&%s' % full_name )
- result = []
- result.append( 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) )
- return ''.join( result )
+ #~ return ''.join( result )
- def create_doc(self):
- return None
- def create_function_ref_code(self, use_function_alias=False):
- if self.wrapper:
- full_name = self.wrapper.default_full_name()
- else:
- full_name = declarations.full_name( self.declaration )
+#~ class mem_fun_v_transformed_wrapper_t( calldef_wrapper_t ):
+ #~ """Creates wrapper code for (public) virtual member functions.
- result = []
- if use_function_alias:
- result.append( '%s(&%s)'
- % ( self.function_type_alias, full_name ) )
- elif self.declaration.create_with_signature:
- if self.wrapper:
- func_type = self.wrapper.function_type()
- else:
- func_type = self.declaration.function_type().decl_string
- result.append( '(%s)(&%s)'
- % ( func_type, full_name ) )
- else:
- result.append( '&%s' % full_name )
+ #~ The generated code consists of two functions: the virtual function
+ #~ and the 'default' function.
+ #~ """
- return ''.join( result )
+ #~ def __init__( self, function ):
+ #~ """Constructor.
+ #~ @param function: Function declaration
+ #~ @type function: calldef_t
+ #~ """
+ #~ calldef_wrapper_t.__init__( self, function=function )
-class mem_fun_v_transformed_wrapper_t( calldef_wrapper_t ):
- """Creates wrapper code for (public) virtual member functions.
-
- The generated code consists of two functions: the virtual function
- and the 'default' function.
- """
-
- def __init__( self, function ):
- """Constructor.
-
- @param function: Function declaration
- @type function: calldef_t
- """
- calldef_wrapper_t.__init__( self, function=function )
-
- # Create the substitution manager
- sm = function_transformers.substitution_manager_t(function
- , transformers=function.transformations[0].transformers )
+ #~ # Create the substitution manager
+ #~ sm = function_transformers.substitution_manager_t(function
+ #~ , transformers=function.transformations[0].transformers )
- sm.init_funcs()
- self._subst_manager = sm
+ #~ sm.init_funcs()
+ #~ self._subst_manager = sm
- # Stores the name of the variable that holds the override
- self._override_var \
- = sm.virtual_func.declare_variable(function.alias + "_callable", 'boost::python::override')
- # Stores the name of the 'gstate' variable
- self._gstate_var \
- = sm.virtual_func.declare_variable("gstate", 'pyplusplus::threading ::gil_guard_t' )
+ #~ # Stores the name of the variable that holds the override
+ #~ self._override_var \
+ #~ = sm.virtual_func.declare_variable(function.alias + "_callable", 'boost::python::override')
+ #~ # Stores the name of the 'gstate' variable
+ #~ self._gstate_var \
+ #~ = sm.virtual_func.declare_variable("gstate", 'pyplusplus::threading ::gil_guard_t' )
- def default_name(self):
- """Return the name of the 'default' function.
+ #~ def default_name(self):
+ #~ """Return the name of the 'default' function.
- @rtype: str
- """
- return "default_" + self.declaration.alias
+ #~ @rtype: str
+ #~ """
+ #~ return "default_" + self.declaration.alias
- def default_full_name(self):
- """Return the full name of the 'default' function.
+ #~ def default_full_name(self):
+ #~ """Return the full name of the 'default' function.
- The returned name also includes the class name.
+ #~ The returned name also includes the class name.
- @rtype: str
- """
- return self.parent.full_name + '::default_' + self.declaration.alias
+ #~ @rtype: str
+ #~ """
+ #~ return self.parent.full_name + '::default_' + self.declaration.alias
- def virtual_name(self):
- """Return the name of the 'virtual' function.
+ #~ def virtual_name(self):
+ #~ """Return the name of the 'virtual' function.
- @rtype: str
- """
- return self.declaration.name
+ #~ @rtype: str
+ #~ """
+ #~ return self.declaration.name
- def base_name(self):
- """Return the name of the 'base' function.
+ #~ def base_name(self):
+ #~ """Return the name of the 'base' function.
- @rtype: str
- """
- return "base_" + self.declaration.name
+ #~ @rtype: str
+ #~ """
+ #~ return "base_" + self.declaration.name
- def function_type(self):
- template = '$RET_TYPE'
- rettype = self._subst_manager.subst_wrapper(template)
- rettype = declarations.dummy_type_t(rettype)
+ #~ def function_type(self):
+ #~ template = '$RET_TYPE'
+ #~ rettype = self._subst_manager.subst_wrapper(template)
+ #~ rettype = declarations.dummy_type_t(rettype)
- return declarations.free_function_type_t(
- return_type=rettype
- , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) )
+ #~ return declarations.free_function_type_t(
+ #~ return_type=rettype
+ #~ , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) )
- return declarations.member_function_type_t(
- return_type=self.declaration.return_type
- , class_inst=declarations.dummy_type_t( self.parent.full_name )
- , arguments_types=map( lambda arg: arg.type, self.declaration.arguments )
- , has_const=self.declaration.has_const )
+ #~ return declarations.member_function_type_t(
+ #~ return_type=self.declaration.return_type
+ #~ , class_inst=declarations.dummy_type_t( self.parent.full_name )
+ #~ , arguments_types=map( lambda arg: arg.type, self.declaration.arguments )
+ #~ , has_const=self.declaration.has_const )
- def create_declaration(self, name, virtual=True):
- """Create the function header.
+ #~ def create_declaration(self, name, virtual=True):
+ #~ """Create the function header.
- This method is used for the virtual function (and the base_ function),
- but not for the default function.
- """
- template = '%(virtual)s$RET_TYPE %(name)s( $ARG_LIST_DEF )%(constness)s %(throw)s'
+ #~ This method is used for the virtual function (and the base_ function),
+ #~ but not for the default function.
+ #~ """
+ #~ template = '%(virtual)s$RET_TYPE %(name)s( $ARG_LIST_DEF )%(constness)s %(throw)s'
- # Substitute the $-variables
- template = self._subst_manager.subst_virtual(template)
+ #~ # Substitute the $-variables
+ #~ template = self._subst_manager.subst_virtual(template)
- virtualspec = ''
- if virtual:
- virtualspec = 'virtual '
+ #~ virtualspec = ''
+ #~ if virtual:
+ #~ virtualspec = 'virtual '
- constness = ''
- if self.declaration.has_const:
- constness = ' const '
+ #~ constness = ''
+ #~ if self.declaration.has_const:
+ #~ constness = ' const '
- return template % {
- 'virtual' : virtualspec
- , 'name' : name
- , 'constness' : constness
- , 'throw' : self.throw_specifier_code()
- }
+ #~ return template % {
+ #~ 'virtual' : virtualspec
+ #~ , 'name' : name
+ #~ , 'constness' : constness
+ #~ , 'throw' : self.throw_specifier_code()
+ #~ }
- def create_base_body(self):
- body = "%(return_)s%(wrapped_class)s::%(name)s( %(args)s );"
+ #~ def create_base_body(self):
+ #~ body = "%(return_)s%(wrapped_class)s::%(name)s( %(args)s );"
- return_ = ''
- if not declarations.is_void( self.declaration.return_type ):
- return_ = 'return '
+ #~ return_ = ''
+ #~ if not declarations.is_void( self.declaration.return_type ):
+ #~ return_ = 'return '
- return body % {
- 'name' : self.declaration.name
- , 'args' : self.function_call_args()
- , 'return_' : return_
- , 'wrapped_class' : self.wrapped_class_identifier()
- }
+ #~ return body % {
+ #~ 'name' : self.declaration.name
+ #~ , 'args' : self.function_call_args()
+ #~ , 'return_' : return_
+ #~ , 'wrapped_class' : self.wrapped_class_identifier()
+ #~ }
- def create_virtual_body(self):
+ #~ def create_virtual_body(self):
- thread_safe = self.declaration.transformations[0].thread_safe
+ #~ thread_safe = self.declaration.transformations[0].thread_safe
- if thread_safe:
- body = """
-pyplusplus::threading::gil_guard_t %(gstate_var)s;
+ #~ if thread_safe:
+ #~ body = """
+#~ pyplusplus::threading::gil_guard_t %(gstate_var)s;
-%(gstate_var)s.ensure();
-boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
-%(gstate_var)s.release();
+#~ %(gstate_var)s.ensure();
+#~ boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
+#~ %(gstate_var)s.release();
-if( %(override_var)s )
-{
- // The corresponding release() is done in the destructor of %(gstate_var)s
- %(gstate_var)s.ensure();
+#~ if( %(override_var)s )
+#~ {
+ #~ // The corresponding release() is done in the destructor of %(gstate_var)s
+ #~ %(gstate_var)s.ensure();
- $DECLARATIONS
+ #~ $DECLARATIONS
- try {
- $PRE_CALL
+ #~ try {
+ #~ $PRE_CALL
- ${RESULT_VAR_ASSIGNMENT}boost::python::call<$RESULT_TYPE>($INPUT_PARAMS);
+ #~ ${RESULT_VAR_ASSIGNMENT}boost::python::call<$RESULT_TYPE>($INPUT_PARAMS);
- $POST_CALL
+ #~ $POST_CALL
- $RETURN_STMT
- }
- catch(...)
- {
- if (PyErr_Occurred())
- {
- PyErr_Print();
- }
+ #~ $RETURN_STMT
+ #~ }
+ #~ catch(...)
+ #~ {
+ #~ if (PyErr_Occurred())
+ #~ {
+ #~ PyErr_Print();
+ #~ }
- $CLEANUP
+ #~ $CLEANUP
- $EXCEPTION_HANDLER_EXIT
- }
-}
-else
-{
- %(inherited)s
-}
-"""
+ #~ $EXCEPTION_HANDLER_EXIT
+ #~ }
+#~ }
+#~ else
+#~ {
+ #~ %(inherited)s
+#~ }
+#~ """
- if not thread_safe:
- body = """
-boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
+ #~ if not thread_safe:
+ #~ body = """
+#~ boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
-if( %(override_var)s )
-{
- $DECLARATIONS
+#~ if( %(override_var)s )
+#~ {
+ #~ $DECLARATIONS
- $PRE_CALL
+ #~ $PRE_CALL
- ${RESULT_VAR_ASSIGNMENT}boost::python::call<$RESULT_TYPE>($INPUT_PARAMS);
+ #~ ${RESULT_VAR_ASSIGNMENT}boost::python::call<$RESULT_TYPE>($INPUT_PARAMS);
- $POST_CALL
+ #~ $POST_CALL
- $RETURN_STMT
-}
-else
-{
- %(inherited)s
-}
-"""
+ #~ $RETURN_STMT
+#~ }
+#~ else
+#~ {
+ #~ %(inherited)s
+#~ }
+#~ """
- vf = self._subst_manager.virtual_func
- arg0 = "%s.ptr()"%self._override_var
- if vf.INPUT_PARAMS=="":
- vf.INPUT_PARAMS = arg0
- else:
- vf.INPUT_PARAMS = arg0+", "+vf.INPUT_PARAMS
+ #~ vf = self._subst_manager.virtual_func
+ #~ arg0 = "%s.ptr()"%self._override_var
+ #~ if vf.INPUT_PARAMS=="":
+ #~ vf.INPUT_PARAMS = arg0
+ #~ else:
+ #~ vf.INPUT_PARAMS = arg0+", "+vf.INPUT_PARAMS
- # Replace the $-variables
- body = self._subst_manager.subst_virtual(body)
+ #~ # Replace the $-variables
+ #~ body = self._subst_manager.subst_virtual(body)
- return body % {
- 'override_var' : self._override_var
- , 'gstate_var' : self._gstate_var
- , 'alias' : self.declaration.alias
- , 'inherited' : self.create_base_body()
- }
+ #~ return body % {
+ #~ 'override_var' : self._override_var
+ #~ , 'gstate_var' : self._gstate_var
+ #~ , 'alias' : self.declaration.alias
+ #~ , 'inherited' : self.create_base_body()
+ #~ }
- def create_default_body(self):
- cls_wrapper_type = self.parent.full_name
- cls_wrapper = self._subst_manager.wrapper_func.declare_variable("cls_wrapper", cls_wrapper_type);
- # The name of the 'self' variable (i.e. first argument)
- selfname = self._subst_manager.wrapper_func.arg_list[0].name
+ #~ def create_default_body(self):
+ #~ cls_wrapper_type = self.parent.full_name
+ #~ cls_wrapper = self._subst_manager.wrapper_func.declare_variable("cls_wrapper", cls_wrapper_type);
+ #~ # The name of the 'self' variable (i.e. first argument)
+ #~ selfname = self._subst_manager.wrapper_func.arg_list[0].name
- body = """$DECLARATIONS
+ #~ body = """$DECLARATIONS
-$PRE_CALL
+#~ $PRE_CALL
-%(cls_wrapper_type)s* %(cls_wrapper)s = dynamic_cast<%(cls_wrapper_type)s*>(boost::addressof(%(self)s));
-if (%(cls_wrapper)s==0)
-{
- // The following call is done on an instance created in C++,
- // so it won't invoke Python code.
- $RESULT_VAR_ASSIGNMENT$CALL_FUNC_NAME($INPUT_PARAMS);
-}
-else
-{
- // The following call is done on an instance created in Python,
- // i.e. a wrapper instance. This call might invoke Python code.
- $RESULT_VAR_ASSIGNMENT%(cls_wrapper)s->%(base_name)s($INPUT_PARAMS);
-}
+#~ %(cls_wrapper_type)s* %(cls_wrapper)s = dynamic_cast<%(cls_wrapper_type)s*>(boost::addressof(%(self)s));
+#~ if (%(cls_wrapper)s==0)
+#~ {
+ #~ // The following call is done on an instance created in C++,
+ #~ // so it won't invoke Python code.
+ #~ $RESULT_VAR_ASSIGNMENT$CALL_FUNC_NAME($INPUT_PARAMS);
+#~ }
+#~ else
+#~ {
+ #~ // The following call is done on an instance created in Python,
+ #~ // i.e. a wrapper instance. This call might invoke Python code.
+ #~ $RESULT_VAR_ASSIGNMENT%(cls_wrapper)s->%(base_name)s($INPUT_PARAMS);
+#~ }
-$POST_CALL
+#~ $POST_CALL
-$RETURN_STMT
-"""
+#~ $RETURN_STMT
+#~ """
- # Replace the $-variables
- body = self._subst_manager.subst_wrapper(body)
+ #~ # Replace the $-variables
+ #~ body = self._subst_manager.subst_wrapper(body)
- # Replace the remaining parameters
- body = body%{"cls_wrapper_type" : cls_wrapper_type,
- "cls_wrapper" : cls_wrapper,
- "self" : selfname,
- "base_name" : self.base_name() }
- return body
+ #~ # Replace the remaining parameters
+ #~ body = body%{"cls_wrapper_type" : cls_wrapper_type,
+ #~ "cls_wrapper" : cls_wrapper,
+ #~ "self" : selfname,
+ #~ "base_name" : self.base_name() }
+ #~ return body
- def create_function(self):
- answer = [ self.create_declaration(self.declaration.name) + '{' ]
- answer.append( self.indent( self.create_virtual_body() ) )
- answer.append( '}' )
- return os.linesep.join( answer )
+ #~ def create_function(self):
+ #~ answer = [ self.create_declaration(self.declaration.name) + '{' ]
+ #~ answer.append( self.indent( self.create_virtual_body() ) )
+ #~ answer.append( '}' )
+ #~ return os.linesep.join( answer )
- def create_base_function( self ):
- answer = [ self.create_declaration("base_"+self.declaration.name, False) + '{' ]
- body = "%(return_)s%(wrapped_class)s::%(name)s( %(args)s );"
- answer.append( self.indent( self.create_base_body() ) )
- answer.append( '}' )
- return os.linesep.join( answer )
+ #~ def create_base_function( self ):
+ #~ answer = [ self.create_declaration("base_"+self.declaration.name, False) + '{' ]
+ #~ body = "%(return_)s%(wrapped_class)s::%(name)s( %(args)s );"
+ #~ answer.append( self.indent( self.create_base_body() ) )
+ #~ answer.append( '}' )
+ #~ return os.linesep.join( answer )
- def create_default_function( self ):
+ #~ def create_default_function( self ):
- header = 'static $RET_TYPE %s( $ARG_LIST_DEF ) {'%self.default_name()
- header = self._subst_manager.subst_wrapper(header)
+ #~ header = 'static $RET_TYPE %s( $ARG_LIST_DEF ) {'%self.default_name()
+ #~ header = self._subst_manager.subst_wrapper(header)
- answer = [ header ]
- answer.append( self.indent( self.create_default_body() ) )
- answer.append( '}' )
- return os.linesep.join( answer )
+ #~ answer = [ header ]
+ #~ answer.append( self.indent( self.create_default_body() ) )
+ #~ answer.append( '}' )
+ #~ return os.linesep.join( answer )
- def _create_impl(self):
+ #~ def _create_impl(self):
- answer = [ self.create_function() ]
- answer.append( os.linesep )
- answer.append( self.create_base_function() )
- answer.append( os.linesep )
- answer.append( self.create_default_function() )
- answer = os.linesep.join( answer )
+ #~ answer = [ self.create_function() ]
+ #~ answer.append( os.linesep )
+ #~ answer.append( self.create_base_function() )
+ #~ answer.append( os.linesep )
+ #~ answer.append( self.create_default_function() )
+ #~ answer = os.linesep.join( answer )
- # Replace the argument list of the declaration so that in the
- # case that keywords are created, the correct arguments will be
- # picked up (i.e. the modified argument list and not the original
- # argument list)
- self.declaration.arguments = self._subst_manager.wrapper_func.arg_list
+ #~ # Replace the argument list of the declaration so that in the
+ #~ # case that keywords are created, the correct arguments will be
+ #~ # picked up (i.e. the modified argument list and not the original
+ #~ # argument list)
+ #~ self.declaration.arguments = self._subst_manager.wrapper_func.arg_list
- return answer
-
\ No newline at end of file
+ #~ return answer
+
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/__init__.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -26,22 +26,22 @@
return transformers.output_t( function, *args, **keywd )
return creator
-def input( *args, **keywd ):
- def creator( function ):
- return transformers.input_t( function, *args, **keywd )
- return creator
+#def input( *args, **keywd ):
+ #def creator( function ):
+ #return transformers.input_t( function, *args, **keywd )
+ #return creator
-def inout( *args, **keywd ):
- def creator( function ):
- return transformers.inout_t( function, *args, **keywd )
- return creator
+#def inout( *args, **keywd ):
+ #def creator( function ):
+ #return transformers.inout_t( function, *args, **keywd )
+ #return creator
-def input_array( *args, **keywd ):
- def creator( function ):
- return transformers.input_array_t( function, *args, **keywd )
- return creator
+#def input_array( *args, **keywd ):
+ #def creator( function ):
+ #return transformers.input_array_t( function, *args, **keywd )
+ #return creator
-def output_array( *args, **keywd ):
- def creator( function ):
- return transformers.output_array_t( function, *args, **keywd )
- return creator
+#def output_array( *args, **keywd ):
+ #def creator( function ):
+ #return transformers.output_array_t( function, *args, **keywd )
+ #return creator
\ No newline at end of file
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -32,7 +32,15 @@
self.__function = function
self.__variables = {} #name : variable
self.__names_in_use = set( map( lambda arg: arg.name, self.function.arguments ) )
+
+ @property
+ def function( self ):
+ return self.__function
+ @property
+ def variables( self ):
+ return self.__variables
+
def declare_variable( self, type, name, initialize_expr='' ):
unique_name = self.__create_unique_var_name( name )
self.__variables[ unique_name ] = variable_t( type, unique_name, initialize_expr )
@@ -52,6 +60,7 @@
return unique_name
class mem_fun_controller_t( controller_base_t ):
+
def __init__( self, function ):
controller_base_t.__init__( self, function )
self.__wrapper_args = function.arguments[:]
@@ -64,7 +73,12 @@
self.__arg_expressions = [ arg.name for arg in function.arguments ]
self.__return_stmt = None
+
@property
+ def template( self ):
+ return templates.mem_fun.body
+
+ @property
def wrapper_args( self ):
return self.__wrapper_args
@@ -106,7 +120,7 @@
self.__pre_call.append( code )
@property
- def pos_call( self ):
+ def post_call( self ):
return self.__post_call
def add_post_call_code( self, code ):
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -3,15 +3,16 @@
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
-
"""This module contains the class L{function_transformation_t}.
"""
+import controllers
class function_transformation_t:
def __init__(self, function, transformer_creator, **keywd):
"""Constructor. """
self.__function = function
+ self.__controller = controllers.mem_fun_controller_t( function )
self.__transformers = map( lambda tr_creator: tr_creator( function ), transformer_creator )
self.__thread_safe = keywd.get( 'thread_safe', False )
@@ -19,6 +20,10 @@
def transformers( self ):
return self.__transformers
+ @property
+ def controller( self ):
+ return self.__controller
+
def required_headers( self ):
headers = []
map( lambda transformer: headers.extend( transformer.required_headers() )
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -15,7 +15,7 @@
body = Template( os.linesep.join([
'$declare_variables'
, '$pre_call'
- , '$save_return_value_stmt$function_name($input_params);'
+ , '$save_return_value_stmt$function($arg_expressions);'
, '$post_call'
, '$return_stmt'
]))
@@ -26,7 +26,7 @@
override_body = Template( os.linesep.join([
'$declare_variables'
- , '$declare_override_function = this->get_override( "$function_alias" );'
+ , 'boost::python::override $override_function_var_name = this->get_override( "$function_alias" );'
, 'if( $override_function_var_name ){'
, ' $declare_override_variables'
, ' $override_pre_call'
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/transformer.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/transformer.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/transformer.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -59,82 +59,5 @@
else:
return self.get_argument( reference ).type
- def init_funcs(self, sm):
- """Wrapper initialization.
-
- This method is called before the actual wrapper source code is
- generated. This is the place where you can modify the signature
- of the C++ wrapper function or allocate local variables.
-
- @param sm: Substitution manager instance
- @type sm: L{substitution_manager_t}
- """
- pass
-
- def wrapper_pre_call(self, sm):
- """Generate the C++ code that should be executed before the actual function call.
-
- The code from this method will be put into the wrapper function.
-
- @param sm: Substitution manager instance
- @type sm: L{substitution_manager_t}
- @return: C++ code or None
- @rtype: str
- """
- pass
-
- def wrapper_post_call(self, sm):
- """Generate the C++ code that should be executed after the actual function call.
-
- The code from this method will be put into the wrapper function.
-
- @param sm: Substitution manager instance
- @type sm: L{substitution_manager_t}
- @return: C++ code or None
- @rtype: str
- """
- pass
-
- def wrapper_cleanup(self, sm):
- """Generate code that should be executed in the case of an error.
-
- This method has to assume that the preCall code was executed but
- the postCall code won't be executed because something went wrong.
-
- <not used yet>
-
- @param sm: Substitution manager instance
- @type sm: L{substitution_manager_t}
- @return: C++ code or None
- @rtype: str
- """
- pass
-
- def virtual_pre_call(self, sm):
- """Generate the C++ code that should be executed before the actual function call.
-
- The code from this method will be put into the virtual function.
-
- @param sm: Substitution manager instance
- @type sm: L{substitution_manager_t}
- @return: C++ code or None
- @rtype: str
- """
- pass
-
- def virtual_post_call(self, sm):
- """Generate the C++ code that should be executed after the actual function call.
-
- The code from this method will be put into the virtual function.
-
- @param sm: Substitution manager instance
- @type sm: L{substitution_manager_t}
- @return: C++ code or None
- @rtype: str
- """
- pass
-
- def virtual_cleanup(self, sm):
- pass
-
-
+ def configure_mem_fun( self, controller ):
+ pass
\ No newline at end of file
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -17,6 +17,7 @@
"""
import os
import transformer
+import controllers
from pygccxml import declarations
from pyplusplus import code_repository
@@ -58,8 +59,7 @@
"""
self.arg = self.get_argument( arg_ref )
self.arg_index = self.function.arguments.index( self.arg )
- self.local_var = "<not initialized>"
-
+
if not is_ref_or_ptr( self.arg.type ):
raise ValueError( '%s\nin order to use "output" transformation, argument %s type must be a reference or a pointer (got %s).' ) \
% ( function, self.arg_ref.name, arg.type)
@@ -67,286 +67,14 @@
def __str__(self):
return "output(%d)"%(self.arg_index)
- def init_funcs(self, sm):
- # Remove the specified output argument from the wrapper function
- sm.remove_arg(self.arg_index+1)
+ def configure_mem_fun( self, controller ):
+ assert isinstance( controller, controllers.mem_fun_controller_t )
+ #removing arg from the function wrapper definition
+ controller.remove_wrapper_arg( self.arg.name )
+ #declaring new variable, which will keep result
+ var_name = controller.declare_variable( remove_ref_or_ptr( self.arg.type ), self.arg.name )
+ #adding just declared variable to the original function call expression
+ controller.modify_argument_expression( self.arg_index, var_name )
+ #adding the variable to return variables list
+ controller.return_variable( var_name )
- # Declare a local variable that will receive the output value
- self.local_var = sm.wrapper_func.declare_variable( self.arg.name, str( remove_ref_or_ptr( self.arg.type ) ) )
- # Append the output to the result tuple
- sm.wrapper_func.result_exprs.append(self.local_var)
-
- # Replace the expression in the C++ function call
- input_param = self.local_var
- if declarations.is_pointer( self.arg.type ):
- input_param = "&%s" % self.local_var
-
- sm.wrapper_func.input_params[self.arg_index] = input_param
-
-
- def virtual_post_call(self, sm):
- """Extract the C++ value after the call to the Python function."""
- res = []
- if declarations.is_pointer( self.arg.type ):
- res.append( "*" )
- res.append( "%s = boost::python::extract<%s>(%s);" \
- % ( self.arg.name
- , remove_ref_or_ptr( self.arg.type )
- , sm.py_result_expr(self.local_var) ) )
- return ''.join( res )
-
-# input_t
-class input_t(transformer.transformer_t):
- """Handles a single input variable.
-
- The reference on the specified variable is removed.
-
- void setValue(int& v) -> setValue(v)
- """
-
- def __init__(self, function, arg_ref):
- """Constructor.
-
- The specified argument must be a reference or a pointer.
-
- @param idx: Index of the argument that is an output value (the first arg has index 1).
- @type idx: int
- """
- transformer.transformer_t.__init__( self, function )
- self.arg = self.get_argument( arg_ref )
- self.arg_index = self.function.arguments.index( self.arg )
-
- if not is_ref_or_ptr( self.arg.type ):
- raise ValueError( '%s\nin order to use "input" transformation, argument %s type must be a reference or a pointer (got %s).' ) \
- % ( function, self.arg_ref.name, arg.type)
-
- def __str__(self):
- return "input(%d)"%(self.idx)
-
- def init_funcs(self, sm):
- # Remove the specified input argument from the wrapper function
- sm.remove_arg(self.arg_index + 1)
-
- # Create an equivalent argument that is not a reference type
- noref_arg = self.arg.clone( type=remove_ref_or_ptr( self.arg.type ) )
- # Insert the noref argument
- sm.insert_arg(self.arg_index + 1, noref_arg, self.arg.name)
-
-# inout_t
-class inout_t(transformer.transformer_t):
- """Handles a single input/output variable.
-
- void foo(int& v) -> v = foo(v)
- """
-
- def __init__(self, function, arg_ref):
- """Constructor.
-
- The specified argument must be a reference or a pointer.
-
- @param idx: Index of the argument that is an in/out value (the first arg has index 1).
- @type idx: int
- """
- transformer.transformer_t.__init__( self, function )
- self.arg = self.get_argument( arg_ref )
- self.arg_index = self.function.arguments.index( self.arg )
- self.local_var = "<not initialized>"
-
- if not is_ref_or_ptr( self.arg.type ):
- raise ValueError( '%s\nin order to use "inout" transformation, argument %s type must be a reference or a pointer (got %s).' ) \
- % ( function, self.arg_ref.name, arg.type)
-
- def __str__(self):
- return "inout(%d)"%(self.arg_index)
-
- def init_funcs(self, sm):
- # Remove the specified input argument from the wrapper function
- sm.remove_arg(self.arg_index + 1)
-
- # Create an equivalent argument that is not a reference type
- noref_arg = self.arg.clone( type=remove_ref_or_ptr( self.arg.type ) )
-
- # Insert the noref argument
- sm.insert_arg(self.idx+1, noref_arg, arg.name)
-
- # Use the input arg to also store the output
- self.local_var = noref_arg.name
- # Append the output to the result tuple
- sm.wrapper_func.result_exprs.append(self.local_var)
-
- # Replace the expression in the C++ function call
- input_param = self.local_var
- if declarations.is_pointer( self.arg.type ):
- input_param = "&%s" % self.local_var
-
- sm.wrapper_func.input_params[self.arg_index] = input_param
-
- def virtual_post_call(self, sm):
- """Extract the C++ value after the call to the Python function."""
- res = []
- if isinstance(arg.type, declarations.pointer_t):
- res.append( "*" )
- res.append( "%s = boost::python::extract<%s>(%s);"
- % ( self.arg.name
- , remove_ref_or_ptr( self.arg.type )
- , sm.py_result_expr( self.local_var ) ) )
- return ''.join( res )
-
-# input_array_t
-class input_array_t(transformer.transformer_t):
- """Handles an input array with fixed size.
-
- void setVec3(double* v) -> setVec3(object v)
- # v must be a sequence of 3 floats
- """
-
- def __init__(self, function, arg_ref, array_size):
- """Constructor.
-
- @param size: The fixed size of the input array
- @type size: int
- """
- transformer.transformer_t.__init__( self, function )
-
- self.arg = self.get_argument( arg_ref )
- self.arg_index = self.function.arguments.index( self.arg )
-
- if not is_ptr_or_array( self.arg.type ):
- raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
- % ( function, self.arg_ref.name, arg.type)
-
- self.array_size = array_size
- self.native_array = None
- self.pylist = None
-
- def __str__(self):
- return "input_array(%s,%d)"%( self.arg.name, self.array_size)
-
- def required_headers( self ):
- """Returns list of header files that transformer generated code depends on."""
- return [ code_repository.convenience.file_name ]
-
- def init_funcs(self, sm):
- # Remove the original argument...
- sm.remove_arg(self.arg_index + 1)
-
- # Declare a variable that will hold the Python list
- # (this will be the input of the Python call in the virtual function)
- self.pylist = sm.virtual_func.declare_variable("py_" + self.arg.name, "boost::python::list")
-
- # Replace the removed argument with a Python object.
- newarg = self.arg.clone( type=declarations.dummy_type_t("boost::python::object") )
- sm.insert_arg(self.arg_index+1, newarg, self.pylist)
-
- # Declare a variable that will hold the C array...
- self.native_array = sm.wrapper_func.declare_variable(
- "native_" + self.arg.name
- , declarations.array_item_type( self.arg.type )
- , '[%d]' % self.array_size)
-
- # Replace the input parameter with the C array
- sm.wrapper_func.input_params[self.arg_index] = self.native_array
-
- def wrapper_pre_call(self, sm):
- """Wrapper function code.
- """
- tmpl = []
- tmpl.append( '%(pypp_con)s::ensure_uniform_sequence< %(type)s >( %(pylist)s, %(array_size)d );' )
- tmpl.append( '%(pypp_con)s::copy_sequence( %(pylist)s, %(pypp_con)s::array_inserter( %(native_array)s, %(array_size)d ) );' )
- return os.linesep.join( tmpl ) % {
- 'type' : declarations.array_item_type( self.arg.type )
- , 'pypp_con' : 'pyplusplus::convenience'
- , 'pylist' : self.arg.name
- , 'array_size' : self.array_size
- , 'native_array' : self.native_array
- }
-
- def virtual_pre_call(self, sm):
- """Virtual function code."""
- tmpl = '%(pypp_con)s::copy_container( %(native_array)s, %(native_array)s + %(array_size)d, %(pypp_con)s::list_inserter( %(pylist)s ) );'
- return tmpl % {
- 'pypp_con' : 'pyplusplus::convenience'
- , 'native_array' : self.arg.name
- , 'array_size' : self.array_size
- , 'pylist' : self.pylist
- }
-
-
-# output_array_t
-class output_array_t(transformer.transformer_t):
- """Handles an output array of a fixed size.
-
- void getVec3(double* v) -> v = getVec3()
- # v will be a list with 3 floats
- """
-
- def __init__(self, function, arg_ref, size):
- """Constructor.
-
- @param idx: Index of the argument that is an output array (the first arg has index 1).
- @type idx: int
- @param size: The fixed size of the output array
- @type size: int
- """
- transformer.transformer_t.__init__( self, function )
- self.arg = self.get_argument( arg_ref )
- self.arg_index = self.function.arguments.index( self.arg )
-
- if not is_ptr_or_array( self.arg.type ):
- raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
- % ( function, self.arg_ref.name, arg.type)
-
- self.array_size = size
- self.native_array = None
- self.pylist = None
-
- def __str__(self):
- return "output_array(%s,%d)"%( self.arg.name, self.array_size)
-
- def required_headers( self ):
- """Returns list of header files that transformer generated code depends on."""
- return [ code_repository.convenience.file_name ]
-
- def init_funcs(self, sm):
- # Remove the original argument...
- sm.remove_arg(self.arg_index + 1)
-
- # Declare a variable that will hold the C array...
- self.native_array = sm.wrapper_func.declare_variable(
- "native_" + self.arg.name
- , declarations.array_item_type( self.arg.type )
- , '[%d]' % self.array_size)
-
- # Declare a Python list which will receive the output...
- self.pylist = sm.wrapper_func.declare_variable(
- 'py_' + self.arg.name
- , "boost::python::list" )
-
- # ...and add it to the result
- sm.wrapper_func.result_exprs.append(self.pylist)
-
- sm.wrapper_func.input_params[ self.arg_index ] = self.native_array
-
- self.virtual_pylist = sm.virtual_func.declare_variable("py_"+self.arg.name, "boost::python::object")
-
- def wrapper_post_call(self, sm):
- tmpl = '%(pypp_con)s::copy_container( %(native_array)s, %(native_array)s + %(array_size)d, %(pypp_con)s::list_inserter( %(pylist)s ) );'
- return tmpl % {
- 'pypp_con' : 'pyplusplus::convenience'
- , 'native_array' : self.native_array
- , 'array_size' : self.array_size
- , 'pylist' : self.pylist
- }
-
- def virtual_post_call(self, sm):
- tmpl = []
- tmpl.append( '%(pypp_con)s::ensure_uniform_sequence< %(type)s >( %(pylist)s, %(array_size)d );' )
- tmpl.append( '%(pypp_con)s::copy_sequence( %(pylist)s, %(pypp_con)s::array_inserter( %(native_array)s, %(array_size)d ) );' )
- return os.linesep.join( tmpl ) % {
- 'type' : declarations.array_item_type( self.arg.type )
- , 'pypp_con' : 'pyplusplus::convenience'
- , 'pylist' : sm.py_result_expr(self.pylist)
- , 'array_size' : self.array_size
- , 'native_array' : self.arg.name
- }
-
Modified: pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-21 13:00:32 UTC (rev 742)
@@ -17,7 +17,7 @@
// Made the method 'virtual' for now because func transformers
// are currently only taken into account on virtual functions.
- virtual void get_size( unsigned int& h, unsigned int& w ){
+ void get_size( unsigned int& h, unsigned int& w ){
h = m_height;
w = m_width;
}
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 09:10:20 UTC (rev 741)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 13:00:32 UTC (rev 742)
@@ -19,24 +19,29 @@
, *args )
def customize( self, mb ):
+ mb.namespace( 'ft' ).exclude()
image = mb.class_( "image_t" )
+ image.include()
+ image.add_wrapper_code( '' )
+ image.member_functions().exclude()
+ image.member_function( "get_size" ).include()
image.member_function( "get_size" ).add_transformation( ft.output(0), ft.output(1) )
- image.member_function( "get_one_value" ).add_transformation( ft.output(0) )
- image.member_function( "get_size2" ).add_transformation( ft.output(0), ft.output(1) )
- image.member_function( "input_arg" ).add_transformation( ft.input(0) )
- image.member_function( "fixed_input_array" ).add_transformation( ft.input_array(0,3) )
- image.member_function( "fixed_output_array" ).add_transformation( ft.output_array(0,3) )
- mb.free_function("get_cpp_instance").call_policies \
- = call_policies.return_value_policy(call_policies.reference_existing_object)
- mb.variable( "cpp_instance" ).exclude()
+ #~ image.member_function( "get_one_value" ).add_transformation( ft.output(0) )
+ #~ image.member_function( "get_size2" ).add_transformation( ft.output(0), ft.output(1) )
+ #~ image.member_function( "input_arg" ).add_transformation( ft.input(0) )
+ #~ image.member_function( "fixed_input_array" ).add_transformation( ft.input_array(0,3) )
+ #~ image.member_function( "fixed_output_array" ).add_transformation( ft.output_array(0,3) )
+ #~ mb.free_function("get_cpp_instance").call_policies \
+ #~ = call_policies.return_value_policy(call_policies.reference_existing_object)
+ #~ mb.variable( "cpp_instance" ).exclude()
- cls = mb.class_("no_virtual_members_t")
- cls.member_function("member").add_transformation( ft.output(0) )
+ #~ cls = mb.class_("no_virtual_members_t")
+ #~ cls.member_function("member").add_transformation( ft.output(0) )
- cls = mb.class_("ft_private_destructor_t")
- cls.member_function("get_value").add_transformation( ft.output(0) )
+ #~ cls = mb.class_("ft_private_destructor_t")
+ #~ cls.member_function("get_value").add_transformation( ft.output(0) )
- mb.decls(lambda decl: decl.name[0]=="_").exclude()
+ #~ mb.decls(lambda decl: decl.name[0]=="_").exclude()
def run_tests(self, module):
"""Run the actual unit tests.
@@ -49,101 +54,101 @@
# Check a method that returns two values by reference
self.assertEqual(img.get_size(), (2,6))
- # Check a method that only returns one value by reference
- self.a...
[truncated message content] |
|
From: <rom...@us...> - 2006-11-21 09:10:20
|
Revision: 741
http://svn.sourceforge.net/pygccxml/?rev=741&view=rev
Author: roman_yakovenko
Date: 2006-11-21 01:10:20 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
just a simple check to see that branch is working properly
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 09:06:32 UTC (rev 740)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 09:10:20 UTC (rev 741)
@@ -54,29 +54,48 @@
class mem_fun_controller_t( controller_base_t ):
def __init__( self, function ):
controller_base_t.__init__( self, function )
- self.__transformed_args = function.arguments[:]
- self.__transformed_return_type = function.return_type
+ self.__wrapper_args = function.arguments[:]
+ self.__wrapper_return_type = function.return_type
self.__return_variables = []
self.__pre_call = []
self.__post_call = []
self.__save_return_value_stmt = None
- self.__input_params = [ arg.name for arg in function.arguments ]
+ self.__arg_expressions = [ arg.name for arg in function.arguments ]
self.__return_stmt = None
@property
- def transformed_args( self ):
- return self.__transformed_args
-
- def __get_transformed_return_type( self ):
- return self.__transformed_return_type
- def __set_transformed_return_type( self, type_ ):
+ def wrapper_args( self ):
+ return self.__wrapper_args
+
+ def remove_wrapper_arg( self, name ):
+ for index, arg in enumerate( self.wrapper_args ):
+ if arg.name == name:
+ del self.wrapper_args[ index ]
+ return
+ else:
+ raise LookupError( "Unable to remove '%s' argument - not found!" % name )
+
+ @property
+ def arg_expressions( self ):
+ return self.__arg_expressions
+
+ def modify_argument_expression( self, index, expression ):
+ self.arg_expressions[ index ] = expression
+
+ def __get_wrapper_return_type( self ):
+ return self.__wrapper_return_type
+ def __set_wrapper_return_type( self, type_ ):
if isinstane( type, types.StringTypes ):
type_ = declarations.dummy_type_t( type_ )
- self.__transformed_return_type = type_
- transformed_return_type = property( __get_transformed_return_type, __set_transformed_return_type )
+ self.__wrapper_return_type = type_
+ wrapper_return_type = property( __get_wrapper_return_type, __set_wrapper_return_type )
+
+ @property
+ def return_variables( self ):
+ return self.__return_variables
- def add_return_variable( self, variable_name ):
+ def return_variable( self, variable_name ):
self.__return_variables.append( name )
@property
@@ -103,6 +122,9 @@
self.__input_params[ index ] = var_name_or_expr
@property
- def return_stmt
+ def return_stmt( self ):
+ return self.__return_stmt
-
+ def set_return_stmt( self, stmt ):
+ self.__return_stmt = stmt
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-21 09:06:36
|
Revision: 740
http://svn.sourceforge.net/pygccxml/?rev=740&view=rev
Author: roman_yakovenko
Date: 2006-11-21 01:06:32 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
I am going to break working code related to FT feature.
Added Paths:
-----------
pyplusplus_dev_ft/
Copied: pyplusplus_dev_ft (from rev 739, pyplusplus_dev)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-21 08:45:51
|
Revision: 739
http://svn.sourceforge.net/pygccxml/?rev=739&view=rev
Author: roman_yakovenko
Date: 2006-11-21 00:45:50 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
switching to Python 2.5
Modified Paths:
--------------
pyplusplus_dev/environment.py
Modified: pyplusplus_dev/environment.py
===================================================================
--- pyplusplus_dev/environment.py 2006-11-21 08:44:59 UTC (rev 738)
+++ pyplusplus_dev/environment.py 2006-11-21 08:45:50 UTC (rev 739)
@@ -1,43 +1,43 @@
import os
-import sys
-import getpass
-
-class boost:
- libs = ''
- include = ''
-
-class python:
- libs = ''
- include = ''
+import sys
+import getpass
-class gccxml:
- executable = ''
+class boost:
+ libs = ''
+ include = ''
+
+class python:
+ libs = ''
+ include = ''
+class gccxml:
+ executable = ''
+
class scons:
suffix = ''
cmd_build = ''
cmd_clean = ''
ccflags = []
-
+
if 'roman' in getpass.getuser():
scons.cmd_build = 'scons --file=%s'
scons.cmd_clean = 'scons --clean --file=%s'
-
+
if sys.platform == 'win32':
- scons.suffix = '.dll'
- scons.ccflags = ['/MD', '/EHsc', '/GR', '/Zc:wchar_t', '/Zc:forScope' ]
- boost.libs = 'd:/boost_cvs/bin'
+ scons.suffix = '.pyd'
+ scons.ccflags = ['/MD', '/EHsc', '/GR', '/Zc:wchar_t', '/Zc:forScope' ]
+ boost.libs = 'd:/boost_cvs/bin'
boost.include = 'd:/boost_cvs'
- python.libs = 'e:/python24/libs'
- python.include = 'e:/python24/include'
- gccxml.executable = 'd:/gccxml_cvs/gccxml-build/bin/release/gccxml.exe'
+ python.libs = 'e:/python25/libs'
+ python.include = 'e:/python25/include'
+ gccxml.executable = 'd:/gccxml_cvs/gccxml-build/bin/release/gccxml.exe'
else:
- scons.suffix = '.so'
- boost.libs = '/home/roman/boost_cvs/bin'
- boost.include = '/home/roman/boost_cvs'
+ scons.suffix = '.so'
+ boost.libs = '/home/roman/boost_cvs/bin'
+ boost.include = '/home/roman/boost_cvs'
python.include = '/usr/include/python2.4'
- gccxml.executable = '/home/roman/gccxml-build/bin/gccxml'
+ gccxml.executable = '/home/roman/gccxml-build/bin/gccxml'
_my_path = None
@@ -60,4 +60,4 @@
print 'pygccxml DEVELOPMENT version will be used'
import pyplusplus
-
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-21 08:45:01
|
Revision: 738
http://svn.sourceforge.net/pygccxml/?rev=738&view=rev
Author: roman_yakovenko
Date: 2006-11-21 00:44:59 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
small refactoring, which will allow FT to be implemented without side effects
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/calldef.py
Added Paths:
-----------
pyplusplus_dev/pyplusplus/code_creators/calldef_utils.py
Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-11-20 20:20:17 UTC (rev 737)
+++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-11-21 08:44:59 UTC (rev 738)
@@ -6,27 +6,22 @@
import os
import algorithm
import code_creator
+import calldef_utils
import declaration_based
import registration_based
import class_declaration
from pygccxml import declarations
from pyplusplus import decl_wrappers
-#virtual functions that returns const reference to something
-#could not be overriden by Python. The reason is simple:
-#in boost::python::override::operator(...) result of marshaling
-#(Python 2 C++) is saved on stack, after functions returns the result
-#will be reference to no where - access violetion.
-#For example see temporal variable tester
-
-use_enum_workaround = False
-
#TODO:
#Add to docs:
#public memebr functions - call, override, call base implementation
#protected member functions - call, override
#private - override
+def make_id_creator( code_creator ):
+ return lambda decl_string: algorithm.create_identifier( code_creator, decl_string )
+
class calldef_t( registration_based.registration_based_t
, declaration_based.declaration_based_t ):
def __init__(self, function, wrapper=None ):
@@ -55,44 +50,9 @@
def param_sep(self):
return os.linesep + self.indent( self.PARAM_SEPARATOR )
- def should_use_enum_wa( self, arg ):
- global use_enum_workaround
- if not declarations.is_enum( arg.type ):
- return False
- if use_enum_workaround:
- return True
- #enum belongs to the class we are working on
- if self.declaration.parent is declarations.enum_declaration( arg.type ).parent \
- and isinstance( self.declaration, declarations.constructor_t ):
- return True
- return False
-
def keywords_args(self):
- boost_arg = algorithm.create_identifier( self, '::boost::python::arg' )
- boost_obj = algorithm.create_identifier( self, '::boost::python::object' )
- result = ['( ']
- for arg in self.declaration.arguments:
- if 1 < len( result ):
- result.append( self.PARAM_SEPARATOR )
- result.append( boost_arg )
- result.append( '("%s")' % arg.name )
- if self.declaration.use_default_arguments and arg.default_value:
- if not declarations.is_pointer( arg.type ) or arg.default_value != '0':
- arg_type_no_alias = declarations.remove_alias( arg.type )
- if declarations.is_fundamental( arg_type_no_alias ) \
- and declarations.is_integral( arg_type_no_alias ) \
- and not arg.default_value.startswith( arg_type_no_alias.decl_string ):
- result.append( '=(%s)(%s)' % ( arg_type_no_alias.decl_string, arg.default_value ) )
- elif self.should_use_enum_wa( arg ):
- #Work around for bug/missing functionality in boost.python.
- #registration order
- result.append( '=(long)(%s)' % arg.default_value )
- else:
- result.append( '=%s' % arg.default_value )
- else:
- result.append( '=%s()' % boost_obj )
- result.append( ' )' )
- return ''.join( result )
+ arg_utils = calldef_utils.argument_utils_t( self.declaration, make_id_creator( self ) )
+ return arg_utils.keywords_args()
def create_def_code( self ):
if not self.works_on_instance:
@@ -175,33 +135,17 @@
code_creator.code_creator_t.__init__( self )
declaration_based.declaration_based_t.__init__( self, declaration=function )
- def argument_name( self, index ):
- arg = self.declaration.arguments[ index ]
- if arg.name:
- return arg.name
- else:
- return 'p%d' % index
-
- def args_declaration( self ):
- args = []
- for index, arg in enumerate( self.declaration.arguments ):
- result = arg.type.decl_string + ' ' + self.argument_name(index)
- if arg.default_value:
- result += '=%s' % arg.default_value
- args.append( result )
- if len( args ) == 1:
- return args[ 0 ]
- return ', '.join( args )
-
def override_identifier(self):
return algorithm.create_identifier( self, '::boost::python::override' )
def function_call_args( self ):
- params = []
- for index, arg in enumerate( self.declaration.arguments ):
- params.append( decl_wrappers.python_traits.call_traits( arg.type ) % self.argument_name( index ) )
- return ', '.join( params )
+ arg_utils = calldef_utils.argument_utils_t( self.declaration, make_id_creator( self ) )
+ return arg_utils.call_args()
+ def args_declaration( self ):
+ arg_utils = calldef_utils.argument_utils_t( self.declaration, make_id_creator( self ) )
+ return arg_utils.args_declaration()
+
def wrapped_class_identifier( self ):
return algorithm.create_identifier( self, declarations.full_name( self.declaration.parent ) )
@@ -897,10 +841,9 @@
def _create_constructor_call( self ):
answer = [ algorithm.create_identifier( self, self.parent.declaration.decl_string ) ]
answer.append( '( ' )
- params = []
- for index in range( len( self.declaration.arguments ) ):
- params.append( self.argument_name( index ) )
- answer.append( ', '.join( params ) )
+ arg_utils = calldef_utils.argument_utils_t( self.declaration, make_id_creator( self ) )
+ params = arg_utils.call_args()
+ answer.append( params )
if params:
answer.append(' ')
answer.append( ')' )
Added: pyplusplus_dev/pyplusplus/code_creators/calldef_utils.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/calldef_utils.py (rev 0)
+++ pyplusplus_dev/pyplusplus/code_creators/calldef_utils.py 2006-11-21 08:44:59 UTC (rev 738)
@@ -0,0 +1,93 @@
+# Copyright 2004 Roman Yakovenko
+# Distributed under 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)
+
+import code_creator
+from pygccxml import declarations
+from pyplusplus import decl_wrappers
+#virtual functions that returns const reference to something
+#could not be overriden by Python. The reason is simple:
+#in boost::python::override::operator(...) result of marshaling
+#(Python 2 C++) is saved on stack, after functions returns the result
+#will be reference to no where - access violetion.
+#For example see temporal variable tester
+
+use_enum_workaround = False
+
+class argument_utils_t:
+
+ PARAM_SEPARATOR = code_creator.code_creator_t.PARAM_SEPARATOR
+
+ def __init__( self, declaration, identifier_creator, arguments=None ):
+ self.__decl = declaration
+ if None is arguments:
+ arguments = self.__decl.arguments
+ self.__args = arguments
+ self.__id_creator = identifier_creator
+
+ def __should_use_enum_wa( self, arg ):
+ global use_enum_workaround
+ if not declarations.is_enum( arg.type ):
+ return False
+ if use_enum_workaround:
+ return True
+ #enum belongs to the class we are working on
+ if self.__decl.parent is declarations.enum_declaration( arg.type ).parent \
+ and isinstance( self.__decl, declarations.constructor_t ):
+ return True
+ return False
+
+ def keywords_args(self):
+ boost_arg = self.__id_creator( '::boost::python::arg' )
+ boost_obj = self.__id_creator( '::boost::python::object' )
+ result = ['( ']
+ for arg in self.__args:
+ if 1 < len( result ):
+ result.append( self.PARAM_SEPARATOR )
+ result.append( boost_arg )
+ result.append( '("%s")' % arg.name )
+ if self.__decl.use_default_arguments and arg.default_value:
+ if not declarations.is_pointer( arg.type ) or arg.default_value != '0':
+ arg_type_no_alias = declarations.remove_alias( arg.type )
+ if declarations.is_fundamental( arg_type_no_alias ) \
+ and declarations.is_integral( arg_type_no_alias ) \
+ and not arg.default_value.startswith( arg_type_no_alias.decl_string ):
+ result.append( '=(%s)(%s)' % ( arg_type_no_alias.decl_string, arg.default_value ) )
+ elif self.__should_use_enum_wa( arg ):
+ #Work around for bug/missing functionality in boost.python.
+ #registration order
+ result.append( '=(long)(%s)' % arg.default_value )
+ else:
+ result.append( '=%s' % arg.default_value )
+ else:
+ result.append( '=%s()' % boost_obj )
+ result.append( ' )' )
+ return ''.join( result )
+
+ def argument_name( self, index ):
+ arg = self.__args[ index ]
+ if arg.name:
+ return arg.name
+ else:
+ return 'p%d' % index
+
+ def args_declaration( self ):
+ args = []
+ for index, arg in enumerate( self.__args ):
+ result = arg.type.decl_string + ' ' + self.argument_name(index)
+ if arg.default_value:
+ result += '=%s' % arg.default_value
+ args.append( result )
+ if len( args ) == 1:
+ return args[ 0 ]
+ return self.PARAM_SEPARATOR.join( args )
+
+ def call_args( self ):
+ params = []
+ for index, arg in enumerate( self.__args ):
+ params.append( decl_wrappers.python_traits.call_traits( arg.type ) % self.argument_name( index ) )
+ return ', '.join( params )
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-20 20:20:17
|
Revision: 737
http://svn.sourceforge.net/pygccxml/?rev=737&view=rev
Author: roman_yakovenko
Date: 2006-11-20 12:20:17 -0800 (Mon, 20 Nov 2006)
Log Message:
-----------
testing solution and making it work
Modified Paths:
--------------
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py
Modified: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct 2006-11-20 13:27:21 UTC (rev 736)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct 2006-11-20 20:20:17 UTC (rev 737)
@@ -1,6 +1,6 @@
#scons build script
-SharedLibrary( target=r'custom_sptr'
- , source=[ r'bindings.cpp' ]
+SharedLibrary( target=r'shared_ptr'
+ , source=[ r'solution.cpp' ]
, LIBS=[ r"boost_python" ]
, LIBPATH=[ r"/home/roman/boost_cvs/bin",r"" ]
, CPPPATH=[ r"/home/roman/boost_cvs"
Modified: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp 2006-11-20 13:27:21 UTC (rev 736)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp 2006-11-20 20:20:17 UTC (rev 737)
@@ -1,9 +1,24 @@
#include "boost/python.hpp"
-#include "boost/shared_ptr.hpp"
#include <string>
-//Your code:
+namespace boost{
+
+ template<class T>
+ inline T* get_pointer( boost::shared_ptr<const T> const& p ){
+ return const_cast< T* >( p.get() );
+ }
+}
+
+namespace boost{ namespace python{
+
+ template<class T>
+ struct pointee< boost::shared_ptr<T const> >{
+ typedef T type;
+ };
+
+} } //boost::python
+
struct info_t{
//class info_t records in what function it was created information
info_t( const std::string& n )
@@ -17,11 +32,11 @@
typedef boost::shared_ptr< const info_t > const_ptr_t;
ptr_t create_ptr(){
- return ptr_t( new fruit( "ptr" ) );
+ return ptr_t( new info_t( "ptr" ) );
}
const_ptr_t create_const_ptr(){
- return const_ptr_t( new fruit( "const ptr" ) );
+ return const_ptr_t( new info_t( "const ptr" ) );
}
std::string read_ptr( ptr_t x ){
@@ -36,27 +51,12 @@
return x->text;
}
-
-namespace boost{ namespace python{
-
- template<class T>
- inline T* get_pointer( boost::shared_ptr<const T> const& p ){
- return const_cast<T*>(p.get());
- }
-
- template<class T>
- struct pointee< boost::shared_ptr<const T> >{
- typedef T type;
- };
-
-} } //boost::python
-
namespace bpl = boost::python;
namespace utils{
template< class T >
- register_shared_ptrs_to_python(){
+ void register_shared_ptrs_to_python(){
//small helper function, which will register shared_ptr conversions
bpl::register_ptr_to_python< boost::shared_ptr< T > >();
bpl::register_ptr_to_python< boost::shared_ptr< const T > >();
@@ -66,8 +66,9 @@
}
BOOST_PYTHON_MODULE( shared_ptr ){
- bpl::class_< fruit >( "fruit", bp::init< std::string >() );
- utils::register_shared_ptrs_to_python< fruit >();
+ bpl::class_< info_t >( "info_t", bpl::init< std::string >() )
+ .add_property( "text", &info_t::text );
+ utils::register_shared_ptrs_to_python< info_t >();
bpl::def( "create_ptr", &create_ptr );
bpl::def( "create_const_ptr", &create_const_ptr );
Modified: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py 2006-11-20 13:27:21 UTC (rev 736)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py 2006-11-20 20:20:17 UTC (rev 737)
@@ -8,13 +8,14 @@
def test( self ):
ptr = shared_ptr.create_ptr()
- self.failUnless( ptr.name == "ptr" )
+ self.failUnless( ptr.text == "ptr" )
self.failUnless( shared_ptr.read_ptr( ptr ) == "ptr" )
const_ptr = shared_ptr.create_const_ptr()
- self.failUnless( const_ptr.name == "const ptr" )
+ self.failUnless( const_ptr.text == "const ptr" )
self.failUnless( shared_ptr.read_const_ptr( const_ptr ) == "const ptr" )
+ #testing conversion functionality
self.failUnless( shared_ptr.read_const_ptr( ptr ) == "ptr" )
def create_suite():
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-20 13:27:24
|
Revision: 736
http://svn.sourceforge.net/pygccxml/?rev=736&view=rev
Author: roman_yakovenko
Date: 2006-11-20 05:27:21 -0800 (Mon, 20 Nov 2006)
Log Message:
-----------
adding shared_ptr< const T> documentation
Modified Paths:
--------------
pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest
pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/www_configuration.py
Added Paths:
-----------
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/definition.rest
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/generate_code.py
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct.rest
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/shared_ptr.rest
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp.rest
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py.rest
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/www_configuration.py
Modified: pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest 2006-11-20 08:46:26 UTC (rev 735)
+++ pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest 2006-11-20 13:27:21 UTC (rev 736)
@@ -14,13 +14,18 @@
On this page you will find my collection of the solutions to some of the problems.
-`Custom smart pointer class`_
+`custom smart pointer class`_
.. include:: ./smart_ptrs/definition.rest
-.. _`Custom smart pointer class` : ./smart_ptrs/smart_ptrs.html
+.. _`custom smart pointer class` : ./smart_ptrs/smart_ptrs.html
+`boost::shared_ptr< const T>`_
+ .. include:: ./shared_ptr/definition.rest
+
+.. _`boost::shared_ptr< const T>` : ./shared_ptr/shared_ptr.html
+
.. _`Py++` : ./../pyplusplus.html
.. _`pygccxml` : http://www.language-binding.net/pygccxml/pygccxml.html
.. _`SourceForge`: http://sourceforge.net/index.php
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/definition.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/definition.rest (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/definition.rest 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,3 @@
+Boost.Python works pretty well with ``boost::shared_ptr< T >`` class, but
+additional work should be done if you want to register a conversion to
+``boost::shared_ptr< const T>`` class.
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/generate_code.py
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/generate_code.py (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/generate_code.py 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,120 @@
+#The code contained in this file will show you how to instruct Py++ to generate
+#code, that uses your smart pointer class.
+#
+
+#Advise:
+#Using your favorite editor create regular C++ header file and to it next code.
+#You don't really need to generate it every time.
+#
+# template<class T>
+# inline T * get_pointer(smart_ptr_t<T> const& p){
+# return p.get();
+# }
+#
+# template <class T>
+# struct pointee< smart_ptr_t<T> >{
+# typedef T type;
+# };
+
+
+HELD_TYPE_TMPL = \
+"""
+namespace boost{ namespace python{
+
+%(class_name)s* get_pointer( %(class_ptr_name)s const& p ){
+ return p.get();
+}
+
+template <>
+struct pointee< %(class_ptr_name)s >{
+ typedef %(class_name)s type;
+};
+
+}}// namespace boost::python
+"""
+
+REGISTER_PTR_TO_PYTHON_TMPL = \
+"""
+boost::python::register_ptr_to_python< %(sp_inst_class_name)s >();
+"""
+
+IMPLICITLY_CONVERTIBLE_TMPL = \
+"""
+boost::python::implicitly_convertible< %(derived)s, %(base)s >();
+"""
+
+
+def get_pointee( sp_instantiation ):
+ #sp_instantiation - reference to smart_ptr_t<XXX>
+ #returns reference to XXX type/declaration
+ #I will find m_managed member variable and will find out its type
+ no_ptr = declarations.remove_pointer( sp_instantiation.variable ('m_managed').type )
+ no_alias = declarations.remove_alias( no_ptr )
+ return declarations.remove_declarated( no_alias )
+
+def expose_single( sp_instantiation ):
+ #This function instructs Py++ how to expose pointee class functionality
+ #related to your smart pointer
+ #sp_instantiation - reference to smart_ptr_t<XXX>
+
+ # You don't need to expose smart_ptr_t< X > class
+ sp_instantiation.exclude()
+
+ pointee = get_pointee( sp_instantiation )
+
+ #Our example defines derived_ptr_t class:
+ #struct derived_ptr_t : public smart_ptr_t< derived_t >
+ #{...};
+ #Next if checks that smart_ptr_t< XXX > class has a derived class
+ #and "exposes" it.
+ if sp_instantiation.derived:
+ assert 1 == len( sp_instantiation.derived )
+ sp_derived = sp_instantiation.derived[0].related_class
+ #You don't want to expose it
+ sp_derived.exclude()
+
+ #Adding your custom code to pointee class.
+ #You don't have to warry about order or place of generated code,
+ #Py++ does it right.
+
+ #Telling Boost.Python how to work with your smart pointer
+ pointee.add_declaration_code(
+ HELD_TYPE_TMPL % { 'class_name': pointee.decl_string
+ , 'class_ptr_name': sp_derived.decl_string } )
+
+ #Telling Boost.Python about relationship between classes
+ pointee.add_registration_code(
+ IMPLICITLY_CONVERTIBLE_TMPL % { 'derived' : sp_derived.decl_string
+ , 'base' : sp_instantiation.decl_string }
+ , works_on_instance=False )
+
+ pointee.add_registration_code(
+ REGISTER_PTR_TO_PYTHON_TMPL % { 'sp_inst_class_name' : sp_derived.decl_string }
+ , works_on_instance=False )
+
+ #Setting class held type
+ pointee.held_type = 'smart_ptr_t< %s >' % pointee.wrapper_alias
+
+ #Registering relationships between classes
+ pointee.add_registration_code(
+ IMPLICITLY_CONVERTIBLE_TMPL % { 'derived' : pointee.held_type
+ , 'base' : sp_instantiation.decl_string }
+ , works_on_instance=False )
+
+ pointee.add_registration_code(
+ REGISTER_PTR_TO_PYTHON_TMPL % { 'sp_inst_class_name' : sp_instantiation.decl_string }
+ , works_on_instance=False )
+
+ #Registering relationships between classes
+ base_classes = filter( lambda hierarchy_info: hierarchy_info.access_type == 'public', pointee.bases )
+ for base in base_classes:
+ pointee.add_registration_code(
+ IMPLICITLY_CONVERTIBLE_TMPL % { 'derived' : sp_instantiation.decl_string
+ , 'base' : 'smart_ptr_t< %s >' % base.related_class.decl_string }
+ , works_on_instance=False)
+
+def expose(mb):
+ sp_instantiations = mb.classes( lambda decl: decl.name.startswith( 'smart_ptr_t' ) )
+ map( lambda sp: expose_single( sp ), sp_instantiations )
+
+
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,10 @@
+#scons build script
+SharedLibrary( target=r'custom_sptr'
+ , source=[ r'bindings.cpp' ]
+ , LIBS=[ r"boost_python" ]
+ , LIBPATH=[ r"/home/roman/boost_cvs/bin",r"" ]
+ , CPPPATH=[ r"/home/roman/boost_cvs"
+ , r"/usr/include/python2.4" ]
+ , SHLIBPREFIX=''
+ , SHLIBSUFFIX='.so'
+)
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct.rest (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct.rest 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,3 @@
+.. code-block::
+ :language: Python
+ :source-file: ./sconstruct
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/shared_ptr.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/shared_ptr.rest (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/shared_ptr.rest 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,89 @@
+===================================================
+How to register ``shared_ptr<const T>`` conversion?
+===================================================
+
+.. contents:: Table of contents
+
+------------
+Introduction
+------------
+
+.. include:: ./definition.rest
+
+--------
+Solution
+--------
+
+The solution is pretty simple:
+
+ .. code-block:: C++
+
+ namespace boost{ namespace python{
+
+ template<class T>
+ inline T* get_pointer( boost::shared_ptr<const T> const& p ){
+ return const_cast<T*>(p.get());
+ }
+
+ template<class T>
+ struct pointee< boost::shared_ptr<const T> >{
+ typedef T type;
+ };
+
+ } } //boost::python
+
+ namespace utils{
+
+ template< class T >
+ register_shared_ptrs_to_python(){
+ namespace bpl = boost::python;
+ bpl::register_ptr_to_python< boost::shared_ptr< T > >();
+ bpl::register_ptr_to_python< boost::shared_ptr< const T > >();
+ bpl::implicitly_convertible< boost::shared_ptr< T >, boost::shared_ptr< const T > >();
+ }
+
+ }
+
+ BOOST_PYTHON_MODULE(...){
+ class_< YourClass >( "YourClass" )
+ ...;
+ utils::register_shared_ptrs_to_python< YourClass >();
+ }
+
+Files
+-----
+
+* `solution.cpp`_ file contains definition of a class and few functions, which
+ have ``shared_ptr< T >`` and ``shared_ptr< const T>`` as return type or as an
+ argument. The file also contains source code that exposes the defined
+ functionality to Python.
+
+* `sconstruct`_ file contains build instructions for scons build tool.
+
+* `test.py`_ file contains complete unit tests for the exposed classes
+
+All files contain comments, which describe what and why was done.
+
+.. _`solution.cpp` : ./solution.hpp.html
+.. _`sconstruct` : ./sconstruct.html
+.. _`test.py` : ./test.py.html
+
+--------
+Download
+--------
+
+https://sourceforge.net/project/showfiles.php?group_id=118209
+
+
+.. _`Py++` : ./../pyplusplus.html
+.. _`pygccxml` : http://www.language-binding.net/pygccxml/pygccxml.html
+.. _`SourceForge`: http://sourceforge.net/index.php
+
+..
+ Local Variables:
+ mode: indented-text
+ indent-tabs-mode: nil
+ sentence-end-double-space: t
+ fill-column: 70
+ End:
+
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,77 @@
+#include "boost/python.hpp"
+#include "boost/shared_ptr.hpp"
+#include <string>
+
+//Your code:
+
+struct info_t{
+ //class info_t records in what function it was created information
+ info_t( const std::string& n )
+ : text( n )
+ {}
+
+ std::string text;
+};
+
+typedef boost::shared_ptr< info_t > ptr_t;
+typedef boost::shared_ptr< const info_t > const_ptr_t;
+
+ptr_t create_ptr(){
+ return ptr_t( new fruit( "ptr" ) );
+}
+
+const_ptr_t create_const_ptr(){
+ return const_ptr_t( new fruit( "const ptr" ) );
+}
+
+std::string read_ptr( ptr_t x ){
+ if( !x )
+ return "";
+ return x->text;
+}
+
+std::string read_const_ptr( const_ptr_t x ){
+ if( !x )
+ return "";
+ return x->text;
+}
+
+
+namespace boost{ namespace python{
+
+ template<class T>
+ inline T* get_pointer( boost::shared_ptr<const T> const& p ){
+ return const_cast<T*>(p.get());
+ }
+
+ template<class T>
+ struct pointee< boost::shared_ptr<const T> >{
+ typedef T type;
+ };
+
+} } //boost::python
+
+namespace bpl = boost::python;
+
+namespace utils{
+
+ template< class T >
+ register_shared_ptrs_to_python(){
+ //small helper function, which will register shared_ptr conversions
+ bpl::register_ptr_to_python< boost::shared_ptr< T > >();
+ bpl::register_ptr_to_python< boost::shared_ptr< const T > >();
+ bpl::implicitly_convertible< boost::shared_ptr< T >, boost::shared_ptr< const T > >();
+ }
+
+}
+
+BOOST_PYTHON_MODULE( shared_ptr ){
+ bpl::class_< fruit >( "fruit", bp::init< std::string >() );
+ utils::register_shared_ptrs_to_python< fruit >();
+
+ bpl::def( "create_ptr", &create_ptr );
+ bpl::def( "create_const_ptr", &create_const_ptr );
+ bpl::def( "read_ptr", &read_ptr );
+ bpl::def( "read_const_ptr", &read_const_ptr );
+
+}
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp.rest (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp.rest 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,3 @@
+.. code-block::
+ :language: C++
+ :source-file: ./solution.cpp
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,29 @@
+import unittest
+import shared_ptr
+
+
+class tester_t( unittest.TestCase ):
+ def __init__( self, *args ):
+ unittest.TestCase.__init__( self, *args )
+
+ def test( self ):
+ ptr = shared_ptr.create_ptr()
+ self.failUnless( ptr.name == "ptr" )
+ self.failUnless( shared_ptr.read_ptr( ptr ) == "ptr" )
+
+ const_ptr = shared_ptr.create_const_ptr()
+ self.failUnless( const_ptr.name == "const ptr" )
+ self.failUnless( shared_ptr.read_const_ptr( const_ptr ) == "const ptr" )
+
+ self.failUnless( shared_ptr.read_const_ptr( ptr ) == "ptr" )
+
+def create_suite():
+ suite = unittest.TestSuite()
+ suite.addTest( unittest.makeSuite(tester_t))
+ return suite
+
+def run_suite():
+ unittest.TextTestRunner(verbosity=2).run( create_suite() )
+
+if __name__ == "__main__":
+ run_suite()
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py.rest (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py.rest 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,3 @@
+.. code-block::
+ :language: Python
+ :source-file: ./test.py
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/www_configuration.py
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/www_configuration.py (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/www_configuration.py 2006-11-20 13:27:21 UTC (rev 736)
@@ -0,0 +1,3 @@
+name = 'shared_ptr< const T>'
+files_to_skip = ['definition.rest']
+names = {}
Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/www_configuration.py
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/www_configuration.py 2006-11-20 08:46:26 UTC (rev 735)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/www_configuration.py 2006-11-20 13:27:21 UTC (rev 736)
@@ -1,3 +1,3 @@
-name = 'Custom smart pointer'
+name = 'custom smart pointer'
files_to_skip = ['definition.rest']
names = {}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-20 08:46:27
|
Revision: 735
http://svn.sourceforge.net/pygccxml/?rev=735&view=rev
Author: roman_yakovenko
Date: 2006-11-20 00:46:26 -0800 (Mon, 20 Nov 2006)
Log Message:
-----------
adding reference to getting started guide
Modified Paths:
--------------
pyplusplus_dev/docs/download.rest
Modified: pyplusplus_dev/docs/download.rest
===================================================================
--- pyplusplus_dev/docs/download.rest 2006-11-19 12:20:30 UTC (rev 734)
+++ pyplusplus_dev/docs/download.rest 2006-11-20 08:46:26 UTC (rev 735)
@@ -42,8 +42,11 @@
-------------------------
Users of Microsoft Windows can enjoy from simple `installer for Boost Libraries`_.
-You can find it `here`_.
+You can find it `here`_. Take a look on new `getting started guide`_ for Boost
+libraries.
+
+.. _`getting started guide` : http://boost.cvs.sourceforge.net/*checkout*/boost/boost/more/getting_started.html
.. _`here` : http://www.boost-consulting.com/download.html
.. _`installer for Boost Libraries` : http://www.boost-consulting.com/download.html
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rom...@us...> - 2006-11-19 12:20:31
|
Revision: 734
http://svn.sourceforge.net/pygccxml/?rev=734&view=rev
Author: roman_yakovenko
Date: 2006-11-19 04:20:30 -0800 (Sun, 19 Nov 2006)
Log Message:
-----------
updating documentation
Modified Paths:
--------------
pyplusplus_dev/docs/peps/dsl_challenge.rest
pyplusplus_dev/docs/quotes.rest
Modified: pyplusplus_dev/docs/peps/dsl_challenge.rest
===================================================================
--- pyplusplus_dev/docs/peps/dsl_challenge.rest 2006-11-18 19:20:05 UTC (rev 733)
+++ pyplusplus_dev/docs/peps/dsl_challenge.rest 2006-11-19 12:20:30 UTC (rev 734)
@@ -105,42 +105,42 @@
BUI does not work for template instantiated classes and functions. If we change
class ``Point`` to be template, the special syntax should be introduced:
- .. code-block:: C++
+ .. code-block:: C++
- template < class Numeric >
- struct Point{
- ...
- };
+ template < class Numeric >
+ struct Point{
+ ...
+ };
-.. code-block:: Python
+ .. code-block:: Python
- PointTmpl = mb.module.template('Point')
- Point = PointTmpl( 'int' )
+ PointTmpl = mb.module.template('Point')
+ Point = PointTmpl( 'int' )
- This is a trivial example, that is why it looks grate. Consider next class:
+ This is a trivial example, that is why it looks grate. Consider next class:
-. code-block:: C++
+ .. code-block:: C++
- template< class String, class Allocator >
- class regex{ ... }
+ template< class String, class Allocator >
+ class regex{ ... }
- The code the user will need to write is:
+ The code the user will need to write is:
- .. code-block:: Python
+ .. code-block:: Python
- regex_tmpl = mb.module.geometry.template( 'regex' )
- #white spaces and scope resolution( :: ) are important
- regex_std_string = regex_tmpl(
- '::std::basic_string<char,std::char_traits<char>,std::allocator<char> >'
- , '::std::allocator<char>' )
+ regex_tmpl = mb.module.geometry.template( 'regex' )
+ #white spaces and scope resolution( :: ) are important
+ regex_std_string = regex_tmpl(
+ '::std::basic_string<char,std::char_traits<char>,std::allocator<char> >'
+ , '::std::allocator<char>' )
- Using current `Py++`_ interface the user can get reference to the class
- instantiation in one line of code:
+ Using current `Py++`_ interface the user can get reference to the class
+ instantiation in one line of code:
-.. code-block:: Python
+ .. code-block:: Python
- regex_std_string = mb.class_(
- lambda decl: decl.name.startswith( 'regex' ) and 'wchar_t' not in decl.name )
+ regex_std_string = mb.class_(
+ lambda decl: decl.name.startswith( 'regex' ) and 'wchar_t' not in decl.name )
* overloaded functions resolution
@@ -165,9 +165,9 @@
Using BUI the user is forced to write full declaration name, otherwise he faces
next problem:
-.. code-block:: Python
+ .. code-block:: Python
- Point = mb.module.Point
+ Point = mb.module.Point
Lets analyze what the ``Point`` value:
@@ -182,7 +182,7 @@
.. code-block:: Python
- Point.add_registration_code( ... )
+ Point.add_registration_code( ... )
Constructor declaration does not define ``add_registration_code`` method.
According to Python rules: "Errors should never pass silently", exception
Modified: pyplusplus_dev/docs/quotes.rest
===================================================================
--- pyplusplus_dev/docs/quotes.rest 2006-11-18 19:20:05 UTC (rev 733)
+++ pyplusplus_dev/docs/quotes.rest 2006-11-19 12:20:30 UTC (rev 734)
@@ -45,8 +45,41 @@
.. __ : http://www.highend3d.com/maya
* Lakin Wecker, the author of `Python-OGRE`_ project, is using `Py++`_ to
- create Python bindings for `OGRE`_.
+ create Python bindings for `OGRE`_.
+
+ `OGRE`_ - is a scene-oriented, flexible 3D engine written in C++ designed to
+ make it easier and more intuitive for developers to produce applications
+ utilising hardware-accelerated 3D graphics.
+* Andy Miller, another developer of `Python-OGRE`_ project, is using `Py++`_ to
+ create Python bindings for:
+
+ * `CEGUI`_ - a free library providing windowing and widgets for graphics
+ APIs / engines where such functionality is not natively available, or
+ severely lacking.
+
+ .. _`CEGUI` : http://www.cegui.org.uk/wiki/index.php/Main_Page
+
+ * `Newton`_ - Newton Game Dynamics, a closed source (but free) physics and
+ collisions library.
+
+ .. _`Newton` : http://www.newtondynamics.com/apache2-default/
+
+ * `ODE`_ - an open source, high performance library for simulating rigid body
+ dynamics.
+
+ .. _`ODE` : http://www.ode.org/
+
+ * `OIS`_ - an object oriented input system.
+
+ .. _`OIS` : http://www.wreckedgames.com/wiki/index.php/WreckedLibs:OIS
+
+* Nicolas Tessore is using `Py++`_ to create Python bindings for `NifTools`_
+ project. You can read in his `blog`_ what he thinks about `Py++`_.
+
+ .. _`NifTools` : http://www.niftools.org/wiki/index.php/NIF_File_Format_Library_and_Tools
+ .. _`blog` : http://ni-te.de/blog/?p=10
+
* I am :-). I created Python bindings for next libraries:
* `Boost.Date_Time`_
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|