[pygccxml-commit] SF.net SVN: pygccxml: [951] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2007-03-07 18:54:52
|
Revision: 951
http://svn.sourceforge.net/pygccxml/?rev=951&view=rev
Author: roman_yakovenko
Date: 2007-03-07 10:54:53 -0800 (Wed, 07 Mar 2007)
Log Message:
-----------
adding work-around to boost.python def_readwrite and def_readonly bugs
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/member_variable.py
pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py
pyplusplus_dev/unittests/custom_string_tester.py
pyplusplus_dev/unittests/data/custom_string_to_be_exported.hpp
Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2007-03-07 09:55:51 UTC (rev 950)
+++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2007-03-07 18:54:53 UTC (rev 951)
@@ -108,7 +108,7 @@
return result
- def _generate_for_smart_ptr( self ):
+ def _generate_using_functions( self ):
doc = ''
add_property = ''
make_getter = algorithm.create_identifier( self, '::boost::python::make_getter')
@@ -148,8 +148,8 @@
def _create_impl( self ):
if declarations.is_pointer( self.declaration.type ):
return self._generate_for_pointer()
- elif self.declaration.apply_smart_ptr_wa:
- return self._generate_for_smart_ptr()
+ elif self.declaration.apply_smart_ptr_wa or self.declaration.use_make_functions:
+ return self._generate_using_functions()
else:
return self._generate_for_none_pointer()
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2007-03-07 09:55:51 UTC (rev 950)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2007-03-07 18:54:53 UTC (rev 951)
@@ -20,7 +20,8 @@
self._setter_call_policies = None
self._apply_smart_ptr_wa = False
self._is_read_only = None
-
+ self._use_make_functions = None
+
__call_policies_doc__ = \
"""There are usecase, when exporting member variable forces Py++ to
create accessors functions. Sometime, those functions requires call policies.
@@ -40,6 +41,10 @@
else:
value_policy = call_policies.copy_non_const_reference
self._getter_call_policies = call_policies.return_value_policy( value_policy )
+ elif self.use_make_functions:
+ self._getter_call_policies = call_policies.return_internal_reference()
+ else:
+ pass
return self._getter_call_policies
def set_getter_call_policies( self, call_policies ):
self._getter_call_policies = call_policies
@@ -48,7 +53,7 @@
def get_setter_call_policies( self ):
if None is self._getter_call_policies:
- if self.apply_smart_ptr_wa:
+ if self.apply_smart_ptr_wa or self.use_make_functions:
self._setter_call_policies = call_policies.default_call_policies()
return self._setter_call_policies
def set_setter_call_policies( self, call_policies ):
@@ -56,14 +61,35 @@
setter_call_policies = property( get_setter_call_policies, set_setter_call_policies
, doc=__call_policies_doc__ )
+ __use_make_functions_doc__ = \
+ """Generate code using make_getter and make_setter functions
+
+ Basically you don't need to use this, untill you have one of the next use-cases:
+ * member variable is smart pointer - in this case Boost.Python has small problem
+ to expose it right. Using the functions is a work around to the problem.
+ * member variable defined custom r-value converter - may be you don't know
+ but the conversion is applied only on functions arguments. So you need to
+ use make_getter/make_setter in order to allow user to enjoy from the
+ conversion.
+
+ Setting "apply_smart_ptr_wa" and/or "use_make_functions" to "True" will tell
+ Py++ to generate such code.
+ """
+
def get_apply_smart_ptr_wa( self ):
return self._apply_smart_ptr_wa
def set_apply_smart_ptr_wa( self, value):
self._apply_smart_ptr_wa = value
apply_smart_ptr_wa = property( get_apply_smart_ptr_wa, set_apply_smart_ptr_wa
- , doc="" )
+ , doc=__use_make_functions_doc__ )
-
+ def get_use_make_functions( self ):
+ return self._use_make_functions
+ def set_use_make_functions( self, value ):
+ self._use_make_functions = value
+ use_make_functions = property( get_use_make_functions, set_use_make_functions
+ , doc=__use_make_functions_doc__)
+
def __find_out_is_read_only(self):
type_ = declarations.remove_alias( self.type )
Modified: pyplusplus_dev/unittests/custom_string_tester.py
===================================================================
--- pyplusplus_dev/unittests/custom_string_tester.py 2007-03-07 09:55:51 UTC (rev 950)
+++ pyplusplus_dev/unittests/custom_string_tester.py 2007-03-07 18:54:53 UTC (rev 951)
@@ -66,11 +66,17 @@
mb.add_declaration_code( auto_convert_code )
mb.add_registration_code( register_auto_convert_code )
mb.constructors().allow_implicit_conversion = False
+ mb.variable( 'm_name' ).use_make_functions = True
+ mb.variable( 'm_123' ).use_make_functions = True
def run_tests( self, module):
self.failUnless( "1" == module.utf16_to_string( "1" ) )
self.failUnless( "22" == module.utf16_to_wstring( u"22" ) )
-
+ n = module.name_t()
+ n.m_name = '456'
+ self.failUnless( '456' == module.utf16_to_string( n.m_name ) )
+ self.failUnless( '123' == module.utf16_to_string( n.m_123 ) )
+
def create_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(tester_t))
Modified: pyplusplus_dev/unittests/data/custom_string_to_be_exported.hpp
===================================================================
--- pyplusplus_dev/unittests/data/custom_string_to_be_exported.hpp 2007-03-07 09:55:51 UTC (rev 950)
+++ pyplusplus_dev/unittests/data/custom_string_to_be_exported.hpp 2007-03-07 18:54:53 UTC (rev 951)
@@ -15,7 +15,16 @@
utf16_t() {}
explicit utf16_t(std::string const& value) : m_value_a(value) {}
explicit utf16_t(std::wstring const& value) : m_value_w(value) {}
-
+
+ utf16_t( const utf16_t& other )
+ : m_value_a( other.m_value_a ), m_value_w( other.m_value_w )
+ {}
+
+ utf16_t& operator=( const utf16_t& other ){
+ m_value_a = other.m_value_a;
+ m_value_w = other.m_value_w;
+ }
+
std::string const& value_a() const { return m_value_a; }
std::wstring const& value_w() const { return m_value_w; }
@@ -24,6 +33,13 @@
std::string m_value_a;
};
+struct name_t{
+ name_t() : m_123( "123" ){}
+
+ utf16_t m_name;
+ const utf16_t m_123;
+};
+
inline std::string utf16_to_string( const utf16_t& x ){
return x.value_a();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|