pygccxml-commit Mailing List for C++ Python language bindings (Page 39)
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...> - 2007-02-16 20:41:44
|
Revision: 908 http://svn.sourceforge.net/pygccxml/?rev=908&view=rev Author: roman_yakovenko Date: 2007-02-16 12:41:45 -0800 (Fri, 16 Feb 2007) Log Message: ----------- initial implementation of return_range call policies Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_repository/call_policies.py Modified: pyplusplus_dev/pyplusplus/code_repository/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/call_policies.py 2007-02-16 10:01:39 UTC (rev 907) +++ pyplusplus_dev/pyplusplus/code_repository/call_policies.py 2007-02-16 20:41:45 UTC (rev 908) @@ -22,6 +22,10 @@ #define call_policies_pyplusplus_hpp__ #include "boost/python.hpp" +#include "boost/mpl/int.hpp" +#include "boost/function.hpp" +#include "boost/python/suite/indexing/iterator_range.hpp" +#include "boost/python/object/class_detail.hpp" namespace pyplusplus{ namespace call_policies{ @@ -132,7 +136,89 @@ } /*arrays*/ +namespace detail{ +struct return_raw_data_ref{ + + template <class T> + struct apply{ + + BOOST_STATIC_ASSERT( boost::is_pointer<T>::value ); + + struct type{ + static bool convertible() + { return true; } + + PyObject* + operator()( T return_value) const{ + if( !return_value ){ + return bpl::detail::none(); + } + else{ + typedef typename boost::remove_pointer< T >::type value_type; + typedef typename boost::remove_const< value_type >::type non_const_value_type; + non_const_value_type* data = const_cast<non_const_value_type*>( return_value ); + return PyCObject_FromVoidPtr( data, NULL ); + } + } + }; + + }; + +}; + +} //detail + +template < typename ValueType, typename SizeGetter, typename GetItemCallPolicies=bpl::default_call_policies > +struct return_range : bpl::default_call_policies +{ + typedef return_range< ValueType, SizeGetter, GetItemCallPolicies > this_type; +public: + //result converter generator should return PyCObject instance + //postcall will destruct it + typedef typename detail::return_raw_data_ref result_converter; + typedef GetItemCallPolicies get_item_call_policies; + typedef ValueType value_type; + typedef bpl::indexing::iterator_range<value_type*> range_type; + + static void register_range_class_on_demand(){ + + // Check the registry. If one is already registered, return it. + bpl::handle<> class_obj( + bpl::objects::registered_class_object(bpl::type_id<range_type>())); + + if (class_obj.get() == 0){ + bpl::class_<range_type>( "_range_iterator_", bpl::init<value_type*, value_type*>() ) + .def(bpl::indexing::container_suite<range_type>() ); + } + } + + template <class ArgumentPackage> + static PyObject* postcall(ArgumentPackage const& args, PyObject* result) + { + if( result == bpl::detail::none() ){ + return result; + } + if( !PyCObject_Check( result ) ){ + throw std::runtime_error( "Internal error: expected to get PyCObject" ); + } + value_type* raw_data = reinterpret_cast<value_type*>( PyCObject_AsVoidPtr( result ) ); + Py_DECREF(result);//we don't need result anymore + + PyObject* self_impl = bpl::detail::get(boost::mpl::int_<0>(),args); + bpl::object self( bpl::handle<>( bpl::borrowed( self_impl ) ) ); + + register_range_class_on_demand(); + + SizeGetter get_size; + ssize_t size = get_size( self ); + range_type the_range( raw_data, raw_data+size ); + bpl::object range_obj( the_range ); + + return bpl::incref( range_obj.ptr() ); + } +}; + } /*pyplusplus*/ } /*call_policies*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-16 10:01:38
|
Revision: 907 http://svn.sourceforge.net/pygccxml/?rev=907&view=rev Author: roman_yakovenko Date: 2007-02-16 02:01:39 -0800 (Fri, 16 Feb 2007) Log Message: ----------- fixing bug in is_convertible functionality: there is no implicit conversion between integral types and void* Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/type_traits.py pygccxml_dev/unittests/data/type_traits.hpp pygccxml_dev/unittests/type_traits_tester.py Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2007-02-16 09:36:27 UTC (rev 906) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2007-02-16 10:01:39 UTC (rev 907) @@ -555,7 +555,10 @@ if is_reference( target ) and is_const( target.base ) and is_same( source, target.base.base ): return True #X => const X& if is_same( target, cpptypes.pointer_t( cpptypes.void_t() ) ): - return True #X => void* + if is_integral( source ) or is_enum( source ): + return False + else: + return True #X => void* if is_pointer( source ) and is_pointer( target ): if is_const( target.base ) and is_same( source.base, target.base.base ): return True#X* => const X* @@ -763,31 +766,31 @@ and not is_void( target ): return True # enum could be converted to any integral type - assert isinstance( source.declaration, class_declaration.class_t ) - source_inst = source.declaration - #class instance could be convertible to something else if it has operator - casting_operators = algorithm.find_all_declarations( source_inst.declarations - , type=calldef.casting_operator_t - , recursive=False ) - if casting_operators: - for operator in casting_operators: - if is_convertible( operator.return_type, target ): - return True + if isinstance( source.declaration, class_declaration.class_t ): + source_inst = source.declaration + #class instance could be convertible to something else if it has operator + casting_operators = algorithm.find_all_declarations( source_inst.declarations + , type=calldef.casting_operator_t + , recursive=False ) + if casting_operators: + for operator in casting_operators: + if is_convertible( operator.return_type, target ): + return True #may be target is class too, so in this case we should check whether is #has constructor from source if isinstance( target, cpptypes.declarated_t ): - assert isinstance( target.declaration, class_declaration.class_t ) - constructors = algorithm.find_all_declarations( target.declaration.declarations - , type=calldef.constructor_t - , recursive=False ) - if constructors: - for constructor in constructors: - if 1 != len( constructor.arguments ): - continue - #TODO: add test to check explicitness - if is_convertible( source, constructor.arguments[0].type ): - return True + if isinstance( target.declaration, class_declaration.class_t ): + constructors = algorithm.find_all_declarations( target.declaration.declarations + , type=calldef.constructor_t + , recursive=False ) + if constructors: + for constructor in constructors: + if 1 != len( constructor.arguments ): + continue + #TODO: add test to check explicitness + if is_convertible( source, constructor.arguments[0].type ): + return True return False Modified: pygccxml_dev/unittests/data/type_traits.hpp =================================================================== --- pygccxml_dev/unittests/data/type_traits.hpp 2007-02-16 09:36:27 UTC (rev 906) +++ pygccxml_dev/unittests/data/type_traits.hpp 2007-02-16 10:01:39 UTC (rev 907) @@ -592,8 +592,8 @@ struct x70 : public tester_t< float, int&, false >{}; struct x71 : public tester_t< float, const int&, true >{}; struct x72 : public tester_t< other, void*, true >{}; -struct x73 : public tester_t< int, void*, true >{}; -struct x74 : public tester_t< fruit, void*, true >{}; +struct x73 : public tester_t< int, void*, false >{}; +struct x74 : public tester_t< fruit, void*, false >{}; struct x75 : public tester_t< other, int*, false >{}; struct x76 : public tester_t< other*, int*, false >{}; struct x77 : public tester_t< fruit, int, true >{}; Modified: pygccxml_dev/unittests/type_traits_tester.py =================================================================== --- pygccxml_dev/unittests/type_traits_tester.py 2007-02-16 09:36:27 UTC (rev 906) +++ pygccxml_dev/unittests/type_traits_tester.py 2007-02-16 10:01:39 UTC (rev 907) @@ -203,8 +203,6 @@ self.failUnless( declarations.is_binary_operator( operator_pe ), 'operator+= should be idenitified as binray operator' ) def __is_convertible_impl( self, decl ): - if decl.name == 'x81': - i = 0 defs = decl.bases[0].related_class.declarations source_type = declarations.find_declaration( defs, name='source_type' ) target_type = declarations.find_declaration( defs, name='target_type' ) @@ -212,8 +210,8 @@ , name='expected' , type=declarations.enumeration_t ) expected_value = bool( expected_type.get_name2value_dict()['value'] ) - if expected_value != declarations.is_convertible( source_type, target_type ): - print decl.name + self.failUnless( expected_value == declarations.is_convertible( source_type, target_type ) + , 'Check conversion failed for ' + decl.name ) def test_is_convertible( self ): ns_is_convertible = declarations.find_declaration( self.declarations This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-16 09:36:26
|
Revision: 906 http://svn.sourceforge.net/pygccxml/?rev=906&view=rev Author: roman_yakovenko Date: 2007-02-16 01:36:27 -0800 (Fri, 16 Feb 2007) Log Message: ----------- adding convinience function Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2007-02-16 08:05:54 UTC (rev 905) +++ pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2007-02-16 09:36:27 UTC (rev 906) @@ -24,6 +24,9 @@ def __init__(self): object.__init__(self) + def create_type(self): + return self.create( None, CREATION_POLICY.AS_TEMPLATE_ARGUMENT ) + def create(self, function_creator, creation_policy=CREATION_POLICY.AS_INSTANCE): """Creates code from the call policies class instance. @param function_creator: parent code creator This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-16 08:05:54
|
Revision: 905 http://svn.sourceforge.net/pygccxml/?rev=905&view=rev Author: roman_yakovenko Date: 2007-02-16 00:05:54 -0800 (Fri, 16 Feb 2007) Log Message: ----------- moving "class_var_name" functionality to decl_wrappers Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/class_declaration.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/function_transformers/transformers.py Modified: pyplusplus_dev/pyplusplus/code_creators/class_declaration.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/class_declaration.py 2007-02-16 06:14:14 UTC (rev 904) +++ pyplusplus_dev/pyplusplus/code_creators/class_declaration.py 2007-02-16 08:05:54 UTC (rev 905) @@ -36,9 +36,9 @@ result.append( ';' ) return ''.join( result ) - def _get_class_var_name(self): - return self.alias + '_exposer' - class_var_name = property( _get_class_var_name ) + @property + def class_var_name(self): + return self.declaration.class_var_name def is_exposed_using_scope(self): if self.declaration.always_expose_using_scope: @@ -246,11 +246,11 @@ result.append( ';' ) return ''.join( result ) - def _get_class_var_name(self): - return self.alias + '_exposer' - class_var_name = property( _get_class_var_name ) - @property + def class_var_name(self): + return self.declaration.class_var_name + + @property def typedef_name( self ): return self.class_var_name + '_t' Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2007-02-16 06:14:14 UTC (rev 904) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2007-02-16 08:05:54 UTC (rev 905) @@ -160,6 +160,10 @@ return False except: return False + + @property + def class_var_name(self): + return self.alias + '_exposer' #this will only be exported if indexing suite is not None and only when needed class class_declaration_t( class_common_details_t Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-02-16 06:14:14 UTC (rev 904) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-02-16 08:05:54 UTC (rev 905) @@ -129,7 +129,10 @@ def __configure_sealed( self, controller ): w_arg = controller.find_wrapper_arg( self.arg.name ) w_arg.type = self.modifier( self.arg.type ) - + if not declarations.is_convertible( w_arg.type, self.arg.type ): + casting_code = 'reinterpret_cast< %s >( %s )' % ( self.arg.type, w_arg.name ) + controller.modify_arg_expression(self.arg_index, casting_code) + def __configure_v_mem_fun_default( self, controller ): self.__configure_sealed( controller ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-16 06:14:22
|
Revision: 904 http://svn.sourceforge.net/pygccxml/?rev=904&view=rev Author: roman_yakovenko Date: 2007-02-15 22:14:14 -0800 (Thu, 15 Feb 2007) Log Message: ----------- adding google analytics Modified Paths: -------------- website/templates/online/page_template.html Modified: website/templates/online/page_template.html =================================================================== --- website/templates/online/page_template.html 2007-02-11 21:00:32 UTC (rev 903) +++ website/templates/online/page_template.html 2007-02-16 06:14:14 UTC (rev 904) @@ -99,5 +99,12 @@ </a> </div> </div> + <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> + <!-- xml kid bug --> + </script> + <script type="text/javascript"> + _uacct = "UA-355561-1"; + urchinTracker(); + </script> </body> </html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-11 21:00:33
|
Revision: 903 http://svn.sourceforge.net/pygccxml/?rev=903&view=rev Author: roman_yakovenko Date: 2007-02-11 13:00:32 -0800 (Sun, 11 Feb 2007) Log Message: ----------- adding caveats to the documentation Modified Paths: -------------- pyplusplus_dev/docs/documentation/best_practices.rest Modified: pyplusplus_dev/docs/documentation/best_practices.rest =================================================================== --- pyplusplus_dev/docs/documentation/best_practices.rest 2007-02-11 20:59:49 UTC (rev 902) +++ pyplusplus_dev/docs/documentation/best_practices.rest 2007-02-11 21:00:32 UTC (rev 903) @@ -84,7 +84,30 @@ my_big_class = mb.class_( my_big_class ) mb.split_module( ..., huge_classes=[my_big_class], ... ) + * **Caveats** + + Consider next file layout: + :: + boost/ + date_time/ + ptime.hpp + time_duration.hpp + date_time.hpp //main header, which include all other header files + + Py++ currently does not handle relative paths as input very well, so it is + recommended that you use "os.path.abspath()" to transform the header file to + be processed into an absolute path: + + .. code-block:: Python + + #Next code will expose nothing + mb = module_builder( [ 'date_time/date_time.hpp' ], ... ) + + #while this one will work as expected + import os + mb = module_builder( [ os.path.abspath('date_time/date_time.hpp') ], ... ) + .. _`this error` : http://boost.org/libs/python/doc/v2/faq.html#c1204 .. __ : ./../../pygccxml/design.html This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-11 20:59:49
|
Revision: 902 http://svn.sourceforge.net/pygccxml/?rev=902&view=rev Author: roman_yakovenko Date: 2007-02-11 12:59:49 -0800 (Sun, 11 Feb 2007) Log Message: ----------- porting indexing suite recent changes to linux Modified Paths: -------------- pyplusplus_dev/indexing_suite_v2/indexing/map.hpp pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp pyplusplus_dev/unittests/indexing_suites2_tester.py Modified: pyplusplus_dev/indexing_suite_v2/indexing/map.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/map.hpp 2007-02-11 13:45:41 UTC (rev 901) +++ pyplusplus_dev/indexing_suite_v2/indexing/map.hpp 2007-02-11 20:59:49 UTC (rev 902) @@ -111,7 +111,7 @@ typedef BOOST_DEDUCED_TYPENAME most_derived::container::value_type value_type; mapping::register_value_type< PythonClass, value_type, Policy >( pyClass ); //now we can expose iterators functionality - pyClass.def( "__iter__", python::iterator< most_derived::container >() ); + pyClass.def( "__iter__", python::iterator< BOOST_DEDUCED_TYPENAME most_derived::container >() ); } }; Modified: pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2007-02-11 13:45:41 UTC (rev 901) +++ pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2007-02-11 20:59:49 UTC (rev 902) @@ -108,7 +108,7 @@ typedef BOOST_DEDUCED_TYPENAME most_derived::container::value_type value_type; mapping::register_value_type< PythonClass, value_type, Policy >( pyClass ); //now we can expose iterators functionality - pyClass.def( "__iter__", python::iterator< most_derived::container >() ); + pyClass.def( "__iter__", python::iterator< BOOST_DEDUCED_TYPENAME most_derived::container >() ); } @@ -148,7 +148,8 @@ boost::python::list _keys; //For some reason code with set could not be compiled //std::set< key_param > unique_keys; - for( iterator index = most_derived::begin(c); index != most_derived::end(c); ++index ){ + typedef BOOST_DEDUCED_TYPENAME container::iterator iter_type; + for( iter_type index = most_derived::begin(c); index != most_derived::end(c); ++index ){ //if( unique_keys.end() == unique_keys.find( index->first ) ){ // unique_keys.insert( index->first ); if( !_keys.count( index->first ) ){ Modified: pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp 2007-02-11 13:45:41 UTC (rev 901) +++ pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp 2007-02-11 20:59:49 UTC (rev 902) @@ -81,4 +81,8 @@ } +namespace pyplusplus{ namespace aliases{ + typedef std::vector<indexing_suites2::item_t*> items_ptr_t; +}} + #endif//__indexing_suites2_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/indexing_suites2_tester.py =================================================================== --- pyplusplus_dev/unittests/indexing_suites2_tester.py 2007-02-11 13:45:41 UTC (rev 901) +++ pyplusplus_dev/unittests/indexing_suites2_tester.py 2007-02-11 20:59:49 UTC (rev 902) @@ -30,7 +30,7 @@ fvector.indexing_suite.disable_method( 'extend' ) fvector.indexing_suite.disable_methods_group( 'reorder' ) #fvector.indexing_suite.call_policies = module_builder.call_policies.default_call_policies() - items_ptr = generator.global_ns.typedef( 'items_ptr_t' ) + items_ptr = generator.global_ns.typedefs( 'items_ptr_t' )[0] items_ptr = declarations.remove_declarated( items_ptr.type ) self.failUnless( items_ptr.indexing_suite.call_policies.__class__ is module_builder.call_policies.return_internal_reference().__class__ ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-11 13:45:40
|
Revision: 901 http://svn.sourceforge.net/pygccxml/?rev=901&view=rev Author: roman_yakovenko Date: 2007-02-11 05:45:41 -0800 (Sun, 11 Feb 2007) Log Message: ----------- expose mapping containers value type Modified Paths: -------------- pyplusplus_dev/unittests/indexing_suites2_tester.py Modified: pyplusplus_dev/unittests/indexing_suites2_tester.py =================================================================== --- pyplusplus_dev/unittests/indexing_suites2_tester.py 2007-02-11 13:28:38 UTC (rev 900) +++ pyplusplus_dev/unittests/indexing_suites2_tester.py 2007-02-11 13:45:41 UTC (rev 901) @@ -50,6 +50,11 @@ name2value = module.name2value_t() name2value[ "x" ] = "y" self.failUnless( "x" == module.get_first_name( name2value ) ) + for kv in name2value: + self.failUnless( kv.key == "x" and kv.value == "y" ) + for k, v in name2value: + self.failUnless( k == "x" and v == "y" ) + items_ptr = module.items_ptr_t() items_ptr.append( item ) self.failUnless( items_ptr[0].value == 1977 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-11 13:28:41
|
Revision: 900 http://svn.sourceforge.net/pygccxml/?rev=900&view=rev Author: roman_yakovenko Date: 2007-02-11 05:28:38 -0800 (Sun, 11 Feb 2007) Log Message: ----------- expose mapping containers value type Modified Paths: -------------- pyplusplus_dev/indexing_suite_v2/indexing/map.hpp pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp Added Paths: ----------- pyplusplus_dev/indexing_suite_v2/indexing/pair.hpp Modified: pyplusplus_dev/indexing_suite_v2/indexing/map.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/map.hpp 2007-02-10 21:40:21 UTC (rev 899) +++ pyplusplus_dev/indexing_suite_v2/indexing/map.hpp 2007-02-11 13:28:38 UTC (rev 900) @@ -23,6 +23,7 @@ #include <boost/python/suite/indexing/algorithms.hpp> #include <boost/detail/workaround.hpp> #include <map> +#include <boost/python/suite/indexing/pair.hpp> namespace boost { namespace python { namespace indexing { ///////////////////////////////////////////////////////////////////////// @@ -105,7 +106,12 @@ static void visit_container_class( PythonClass &pyClass, Policy const &policy) { ContainerTraits::visit_container_class (pyClass, policy); - pyClass.def( "keys", &self_type::keys ); + pyClass.def( "keys", &self_type::keys ); + + typedef BOOST_DEDUCED_TYPENAME most_derived::container::value_type value_type; + mapping::register_value_type< PythonClass, value_type, Policy >( pyClass ); + //now we can expose iterators functionality + pyClass.def( "__iter__", python::iterator< most_derived::container >() ); } }; Modified: pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2007-02-10 21:40:21 UTC (rev 899) +++ pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2007-02-11 13:28:38 UTC (rev 900) @@ -20,6 +20,7 @@ #include <boost/detail/workaround.hpp> #include <functional> #include <map> +#include <boost/python/suite/indexing/pair.hpp> namespace boost { namespace python { namespace indexing { ///////////////////////////////////////////////////////////////////////// @@ -103,6 +104,12 @@ { ContainerTraits::visit_container_class (pyClass, policy); pyClass.def( "keys", &self_type::keys ); + + typedef BOOST_DEDUCED_TYPENAME most_derived::container::value_type value_type; + mapping::register_value_type< PythonClass, value_type, Policy >( pyClass ); + //now we can expose iterators functionality + pyClass.def( "__iter__", python::iterator< most_derived::container >() ); + } }; @@ -141,8 +148,7 @@ boost::python::list _keys; //For some reason code with set could not be compiled //std::set< key_param > unique_keys; - typedef BOOST_DEDUCED_TYPENAME container::iterator iter_type; - for( iter_type index = most_derived::begin(c); index != most_derived::end(c); ++index ){ + for( iterator index = most_derived::begin(c); index != most_derived::end(c); ++index ){ //if( unique_keys.end() == unique_keys.find( index->first ) ){ // unique_keys.insert( index->first ); if( !_keys.count( index->first ) ){ Added: pyplusplus_dev/indexing_suite_v2/indexing/pair.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/pair.hpp (rev 0) +++ pyplusplus_dev/indexing_suite_v2/indexing/pair.hpp 2007-02-11 13:28:38 UTC (rev 900) @@ -0,0 +1,98 @@ +// Header file pair.hpp +// +// Exposes std::pair< key, value > class +// +// Copyright (c) 2007 Roman Yakovenko +// +// Use, modification and distribution is subject to 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) +// +// History +// ======= +// 2007/2/11 rmg File creation +// + +#ifndef BOOST_PYTHON_STD_PAIR_KEY_VALUE_11_02_2007_HPP +#define BOOST_PYTHON_STD_PAIR_KEY_VALUE_11_02_2007_HPP + +#include <boost/config.hpp> +#include <boost/python/suite/indexing/container_traits.hpp> +#include <boost/python/suite/indexing/container_suite.hpp> +#include <boost/python/suite/indexing/algorithms.hpp> +#include <boost/detail/workaround.hpp> + +namespace boost { namespace python { namespace indexing { namespace mapping{ + +namespace details{ + +template< typename TValueType, typename TValueCallPolicies > +struct pair_exposer_t{ + + typedef TValueType pair_type; + typedef BOOST_DEDUCED_TYPENAME pair_type::first_type key_type; + typedef BOOST_DEDUCED_TYPENAME pair_type::second_type mapped_type; + typedef pair_exposer_t< TValueType, TValueCallPolicies > exposer_type; + + pair_exposer_t(const std::string& name){ + class_< pair_type >( name.c_str() ) + .def( "__len__", &exposer_type::len ) + .def( "__getitem__", &exposer_type::get_item ) + .add_property( "key", &exposer_type::get_key ) + .add_property( "value", &exposer_type::get_mapped ); + } + +private: + + static size_t len( const pair_type& ){ + return 2; + } + + static object get_item( pair_type& p, size_t index ){ + switch( index ){ + case 0:{ + return get_key( p ); + } + case 1:{ + return get_mapped( p ); + } + case 2:{ + objects::stop_iteration_error(); + return object(); //will not reach this line + } + default:{ + PyErr_SetString( PyExc_IndexError, "the only valid index numbers are: 0 and 1"); + throw_error_already_set(); + return object(); //will not reach this line + } + } + } + + static object get_key( const pair_type& p ){ + return object( p.first ); + } + + static object get_mapped( pair_type& p ){ + typedef BOOST_DEDUCED_TYPENAME TValueCallPolicies::result_converter rc_type; + typedef BOOST_DEDUCED_TYPENAME rc_type:: template apply< mapped_type >::type converter_type; + converter_type converter; + return object( handle<>( converter( p.second ) ) ); + } + +}; +} //details + +template< typename TPythonClass, typename TValueType, typename TValueCallPolicies > +inline void register_value_type(TPythonClass &pyClass){ + typedef details::pair_exposer_t< TValueType, TValueCallPolicies > exposer_type; + + object class_name(pyClass.attr("__name__")); + extract<std::string> class_name_extractor(class_name); + std::string pair_name = class_name_extractor() + "_entry"; + + exposer_type expose( pair_name ); +} + +} } } } + +#endif // BOOST_PYTHON_STD_PAIR_KEY_VALUE_11_02_2007_HPP This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-10 21:40:22
|
Revision: 899 http://svn.sourceforge.net/pygccxml/?rev=899&view=rev Author: roman_yakovenko Date: 2007-02-10 13:40:21 -0800 (Sat, 10 Feb 2007) Log Message: ----------- if PyObject doesn't have len attribute don't try to make conversion Modified Paths: -------------- pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/tuples.hpp Modified: pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/tuples.hpp =================================================================== --- pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/tuples.hpp 2007-02-09 10:24:13 UTC (rev 898) +++ pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/tuples.hpp 2007-02-10 21:40:21 UTC (rev 899) @@ -152,7 +152,12 @@ return 0; } + if( !PyObject_HasAttrString( py_obj, "__len__" ) ){ + return 0; + } + python::object py_sequence( handle<>( borrowed( py_obj ) ) ); + if( tuples::length< TTuple >::value != len( py_sequence ) ){ return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-09 10:24:13
|
Revision: 898 http://svn.sourceforge.net/pygccxml/?rev=898&view=rev Author: roman_yakovenko Date: 2007-02-09 02:24:13 -0800 (Fri, 09 Feb 2007) Log Message: ----------- fixing compilation in generated code for VC 6.0 Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/calldef.py Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2007-02-04 08:51:09 UTC (rev 897) +++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2007-02-09 10:24:13 UTC (rev 898) @@ -363,7 +363,7 @@ template.append( 'if( %(override)s func_%(alias)s = this->get_override( "%(alias)s" ) )' ) template.append( self.indent('%(return_)sfunc_%(alias)s( %(args)s );') ) template.append( 'else' ) - template.append( self.indent('%(return_)s%(wrapped_class)s::%(name)s( %(args)s );') ) + template.append( self.indent('%(return_)sthis->%(wrapped_class)s::%(name)s( %(args)s );') ) template = os.linesep.join( template ) return_ = '' @@ -593,7 +593,7 @@ template.append( 'if( %(override)s func_%(alias)s = this->get_override( "%(alias)s" ) )' ) template.append( self.indent('%(return_)sfunc_%(alias)s( %(args)s );') ) template.append( 'else' ) - template.append( self.indent('%(return_)s%(wrapped_class)s::%(name)s( %(args)s );') ) + template.append( self.indent('%(return_)sthis->%(wrapped_class)s::%(name)s( %(args)s );') ) template = os.linesep.join( template ) return_ = '' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-04 08:51:09
|
Revision: 897 http://svn.sourceforge.net/pygccxml/?rev=897&view=rev Author: roman_yakovenko Date: 2007-02-04 00:51:09 -0800 (Sun, 04 Feb 2007) Log Message: ----------- incrementing versions Modified Paths: -------------- pygccxml_dev/pygccxml/__init__.py pygccxml_dev/setup.py pyplusplus_dev/pyplusplus/__init__.py pyplusplus_dev/setup.py Modified: pygccxml_dev/pygccxml/__init__.py =================================================================== --- pygccxml_dev/pygccxml/__init__.py 2007-02-02 18:46:02 UTC (rev 896) +++ pygccxml_dev/pygccxml/__init__.py 2007-02-04 08:51:09 UTC (rev 897) @@ -35,4 +35,6 @@ #TODO: # 1. Write documentation for filtering functionality. -# 2. Add "explicit" property for constructors \ No newline at end of file +# 2. Add "explicit" property for constructors + +__version__ = '0.8.6' Modified: pygccxml_dev/setup.py =================================================================== --- pygccxml_dev/setup.py 2007-02-02 18:46:02 UTC (rev 896) +++ pygccxml_dev/setup.py 2007-02-04 08:51:09 UTC (rev 897) @@ -52,7 +52,7 @@ setup( name = "pygccxml", - version = "0.8.5", + version = "0.8.6", description = "GCC-XML generated file reader", author = "Roman Yakovenko", author_email = "rom...@gm...", Modified: pyplusplus_dev/pyplusplus/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/__init__.py 2007-02-02 18:46:02 UTC (rev 896) +++ pyplusplus_dev/pyplusplus/__init__.py 2007-02-04 08:51:09 UTC (rev 897) @@ -34,7 +34,7 @@ from _logging_ import multi_line_formatter_t -__version__ = '0.8.3' +__version__ = '0.8.6' #Known issues: #3. Modified: pyplusplus_dev/setup.py =================================================================== --- pyplusplus_dev/setup.py 2007-02-02 18:46:02 UTC (rev 896) +++ pyplusplus_dev/setup.py 2007-02-04 08:51:09 UTC (rev 897) @@ -90,7 +90,7 @@ setup( name = "Py++", - version = "0.8.5", + version = "0.8.6", description="Py++ is a framework of components for creating C++ code generator for Boost.Python library", author="Roman Yakovenko", author_email="rom...@gm...", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-02 18:46:05
|
Revision: 896 http://svn.sourceforge.net/pygccxml/?rev=896&view=rev Author: roman_yakovenko Date: 2007-02-02 10:46:02 -0800 (Fri, 02 Feb 2007) Log Message: ----------- removing breaking changes Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/module.py pyplusplus_dev/pyplusplus/module_creator/creator.py Modified: pyplusplus_dev/pyplusplus/code_creators/module.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/module.py 2007-02-01 12:15:05 UTC (rev 895) +++ pyplusplus_dev/pyplusplus/code_creators/module.py 2007-02-02 18:46:02 UTC (rev 896) @@ -133,7 +133,7 @@ if creator.header in self.__system_headers: if not leave_system_headers: self.remove_creator( creator ) - if creator.is_user_defined: + elif creator.is_user_defined: pass else: self.remove_creator( creator ) @@ -171,8 +171,8 @@ code = self.unindent(code) return os.linesep.join( includes ) + 2 * os.linesep + code + os.linesep - def add_include( self, header, user_defined ): - self.adopt_include( include.include_t( header=header, user_defined=user_defined ) ) + def add_include( self, header ): + self.adopt_include( include.include_t( header=header, user_defined=True ) ) def add_namespace_usage( self, namespace_name ): self.adopt_creator( namespace.namespace_using_t( namespace_name ) @@ -202,4 +202,4 @@ - \ No newline at end of file + Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-02-01 12:15:05 UTC (rev 895) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-02-02 18:46:02 UTC (rev 896) @@ -429,7 +429,8 @@ included = filter( lambda cc: isinstance(cc, code_creators.include_t) and cc.header==header , self.__extmodule.creators) if not included: - self.__extmodule.add_include( header, user_defined=True ) + self.__extmodule.adopt_include( + code_creators.include_t( header=header, user_defined=True ) ) # Check if it is a header from the code repository if header in code_repository.headers: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-01 12:15:10
|
Revision: 895 http://svn.sourceforge.net/pygccxml/?rev=895&view=rev Author: roman_yakovenko Date: 2007-02-01 04:15:05 -0800 (Thu, 01 Feb 2007) Log Message: ----------- adding new link to comparison Modified Paths: -------------- pyplusplus_dev/docs/comparisons/compare_to.rest Modified: pyplusplus_dev/docs/comparisons/compare_to.rest =================================================================== --- pyplusplus_dev/docs/comparisons/compare_to.rest 2007-02-01 07:52:10 UTC (rev 894) +++ pyplusplus_dev/docs/comparisons/compare_to.rest 2007-02-01 12:15:05 UTC (rev 895) @@ -40,7 +40,9 @@ .. _`Integrating Python, C and C++` : http://www.suttoncourtenay.org.uk/duncan/accu/integratingpython.html +* `Python Wrapper Tools: A Performance Study`_ + .. _`Python Wrapper Tools: A Performance Study` : http://people.web.psi.ch/geus/talks/europython2004_geus.pdf .. _`Py++` : ./../pyplusplus.html .. _`Pyste`: http://www.boost.org/libs/python/doc/index.html This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-01 07:52:09
|
Revision: 894 http://svn.sourceforge.net/pygccxml/?rev=894&view=rev Author: roman_yakovenko Date: 2007-01-31 23:52:10 -0800 (Wed, 31 Jan 2007) Log Message: ----------- small dos update Modified Paths: -------------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2007-02-01 06:54:04 UTC (rev 893) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2007-02-01 07:52:10 UTC (rev 894) @@ -22,6 +22,8 @@ * ``output_static_array`` +* ``input_c_buffer`` + The set doesn't cover all common use cases, but it will grow with every new version of `Py++`_. If you created your own transformer consider to contribute it to the project. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-01 06:54:08
|
Revision: 893 http://svn.sourceforge.net/pygccxml/?rev=893&view=rev Author: roman_yakovenko Date: 2007-01-31 22:54:04 -0800 (Wed, 31 Jan 2007) Log Message: ----------- improving "input_c_buffer" memory allocation adding documentation Modified Paths: -------------- pyplusplus_dev/docs/history/history.rest pyplusplus_dev/pyplusplus/function_transformers/transformers.py Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_c_buffer.rest Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_c_buffer.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_c_buffer.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_c_buffer.rest 2007-02-01 06:54:04 UTC (rev 893) @@ -0,0 +1,82 @@ +================================== +``input_c_buffer`` transformer +================================== + +.. contents:: Table of contents + +---------- +Definition +---------- + +"input_c_buffer" transformer works on C buffers. It handles the translation +between a `Python`_ sequence object and the buffer. + +"input_c_buffer" transformer takes as first argument name or index of the +"buffer" argument. The argument should have "array" or "pointer" type. +The second argument should be name or index of another original function argument, +which represents array size. + +------- +Example +------- + +.. code-block:: C++ + + struct file_t{ + void write( char* buffer, int size ) const; + }; + +In order to expose ``write`` member function we need to create small wrapper: +Next `Py++`_ code does it for you: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + f = mb.class_( 'file_t' ) + f.mem_fun( 'write' ).add_transformation( FT.input_c_buffer( 'buffer', 'size' ) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: C++ + + #include "__convenience.pypp.hpp" //Py++ header file, which contains few convenience function + + #include <vector> + + #include <iterator> + + namespace bp = boost::python; + + static void write_8883fea8925bad9911e6c5a4015ed106( ::file_t const & inst, boost::python::object buffer ){ + int size2 = boost::python::len(buffer); + std::vector< char > native_buffer; + native_buffer.reserve( size2 ); + pyplus_conv::ensure_uniform_sequence< char >( buffer ); + pyplus_conv::copy_sequence( buffer, std::back_inserter( native_buffer), boost::type< char >() ); + inst.write(&native_buffer[0], size2); + } + + BOOST_PYTHON_MODULE(...){ + ... + bp::class_< file_t >( "file_t" ) + .def( + "write" + , (void (*)( ::file_t const &,boost::python::object ))( &write_8883fea8925bad9911e6c5a4015ed106 ) + , ( bp::arg("inst"), bp::arg("buffer") ) ); + } + +.. _`Py++` : ./../pyplusplus.html +.. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html +.. _`Python`: http://www.python.org +.. _`GCC-XML`: http://www.gccxml.org + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + End: Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2007-02-01 05:50:00 UTC (rev 892) +++ pyplusplus_dev/docs/history/history.rest 2007-02-01 06:54:04 UTC (rev 893) @@ -43,16 +43,28 @@ * Declaration of virtual functions that have an exception specification with an empty throw was fixed. Now the exception specification is generated properly. Many thanks to Martin Preisler for reporting the bug. - + +.. line-separator + 2. Added exposing of copy constructors and "operator=". "operator=" is exposed under "assign" name. - + +.. line-separator + 3. Added new call policy - `as_tuple`_ -.. _`as_tuple` : ../documentation/functions/call_policies.html +.. _`as_tuple` : ../documentation/functions/call_policies.html#as-tuple 4. Added initial support for multi-module development. +.. line-separator + +5. `input_c_buffer`_ - new functions transformation, which allows to pass a Python + sequence to function, instead of pair of arguments: pointer to buffer and size. + +.. _`input_c_buffer` : ../documentation/functions/transformation/built_in/input_c_buffer.html + + ------------- Version 0.8.5 ------------- Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-02-01 05:50:00 UTC (rev 892) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-02-01 06:54:04 UTC (rev 893) @@ -455,7 +455,9 @@ buffer_var = controller.declare_variable( declarations.dummy_type_t( "std::vector< %s >" % self.buffer_item_type.decl_string ) , "native_" + self.buffer_arg.name ) - + + controller.add_pre_call_code( '%s.reserve( %s );' % ( buffer_var, size_var ) ) + copy_pylist2arr = _seq2vector.substitute( type=self.buffer_item_type , pylist=w_buffer_arg.name , native_array=buffer_var ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-02-01 05:50:02
|
Revision: 892 http://svn.sourceforge.net/pygccxml/?rev=892&view=rev Author: roman_yakovenko Date: 2007-01-31 21:50:00 -0800 (Wed, 31 Jan 2007) Log Message: ----------- fixing input_c_buffer transformer Modified Paths: -------------- pyplusplus_dev/docs/history/history.rest pyplusplus_dev/pyplusplus/code_creators/calldef_utils.py pyplusplus_dev/pyplusplus/function_transformers/transformers.py pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp pyplusplus_dev/unittests/function_transformations_tester.py Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2007-01-31 22:12:43 UTC (rev 891) +++ pyplusplus_dev/docs/history/history.rest 2007-02-01 05:50:00 UTC (rev 892) @@ -43,7 +43,16 @@ * Declaration of virtual functions that have an exception specification with an empty throw was fixed. Now the exception specification is generated properly. Many thanks to Martin Preisler for reporting the bug. + +2. Added exposing of copy constructors and "operator=". "operator=" is exposed + under "assign" name. + +3. Added new call policy - `as_tuple`_ +.. _`as_tuple` : ../documentation/functions/call_policies.html + +4. Added initial support for multi-module development. + ------------- Version 0.8.5 ------------- Modified: pyplusplus_dev/pyplusplus/code_creators/calldef_utils.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef_utils.py 2007-01-31 22:12:43 UTC (rev 891) +++ pyplusplus_dev/pyplusplus/code_creators/calldef_utils.py 2007-02-01 05:50:00 UTC (rev 892) @@ -113,6 +113,8 @@ and ( self.__function.call_policies.is_default() \ or False == bool( self.__controller.return_variables ) ): self.__pre_return_code = '' + elif self.__function.call_policies.is_default(): + self.__pre_return_code = '' else: c_p_typedef = 'typedef %s %s;' \ % ( self.__function.call_policies.create_template_arg( self.__creator ) Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-01-31 22:12:43 UTC (rev 891) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-02-01 05:50:00 UTC (rev 892) @@ -454,8 +454,7 @@ # Declare a variable that will hold the C array... buffer_var = controller.declare_variable( declarations.dummy_type_t( "std::vector< %s >" % self.buffer_item_type.decl_string ) - , "native_" + self.buffer_arg.name - , '(%s)' % size_var ) + , "native_" + self.buffer_arg.name ) copy_pylist2arr = _seq2vector.substitute( type=self.buffer_item_type , pylist=w_buffer_arg.name Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2007-01-31 22:12:43 UTC (rev 891) +++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2007-02-01 05:50:00 UTC (rev 892) @@ -222,7 +222,6 @@ struct input_c_buffer_tester_t{ std::string write( char* buffer, int dummy, int size ) const { - std::cout << "wwwwwwwwwww> " << std::string( buffer, size ); return std::string( buffer, size ); } Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2007-01-31 22:12:43 UTC (rev 891) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2007-02-01 05:50:00 UTC (rev 892) @@ -236,7 +236,6 @@ tmp = module.input_c_buffer_tester_t() hw = 'hello world' dummy = 11 - print 'xxxxxxxxxxx> ', tmp.write( list( hw ), dummy ) self.failUnless( 'hello world' == tmp.write( list( hw ), dummy ) ) self.failUnless( 'hello world' == tmp.write_s( dummy, tuple( list( hw ) ) ) ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-01-31 22:12:43
|
Revision: 891 http://svn.sourceforge.net/pygccxml/?rev=891&view=rev Author: roman_yakovenko Date: 2007-01-31 14:12:43 -0800 (Wed, 31 Jan 2007) Log Message: ----------- adding initial support for input_c_buffer transformer Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/include.py pyplusplus_dev/pyplusplus/code_creators/module.py pyplusplus_dev/pyplusplus/code_repository/convenience.py pyplusplus_dev/pyplusplus/function_transformers/__init__.py pyplusplus_dev/pyplusplus/function_transformers/transformers.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp pyplusplus_dev/unittests/function_transformations_tester.py Modified: pyplusplus_dev/pyplusplus/code_creators/include.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/include.py 2007-01-31 18:53:51 UTC (rev 890) +++ pyplusplus_dev/pyplusplus/code_creators/include.py 2007-01-31 22:12:43 UTC (rev 891) @@ -12,10 +12,15 @@ """ Creates C++ code for include directive """ - def __init__( self, header ): + def __init__( self, header, user_defined=False ): code_creator.code_creator_t.__init__(self) self._header = include_directories.include_directories_t.normalize( header ) self._include_dirs_optimization = None #This parameter will be set from module_t.create function + self._user_defined = user_defined + + @property + def is_user_defined(self): + return self._user_defined def _get_header(self): return self._header @@ -30,6 +35,10 @@ include_dirs_optimization = property( _get_include_dirs_optimization, _set_include_dirs_optimization ) def _create_impl(self): + header = self.header.strip() + if header.startswith( '"' ) or header.startswith( '<' ): + return '#include %s' % self.header + if not self.include_dirs_optimization: return '#include "%s"' % self.header else: Modified: pyplusplus_dev/pyplusplus/code_creators/module.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/module.py 2007-01-31 18:53:51 UTC (rev 890) +++ pyplusplus_dev/pyplusplus/code_creators/module.py 2007-01-31 22:12:43 UTC (rev 891) @@ -133,6 +133,8 @@ if creator.header in self.__system_headers: if not leave_system_headers: self.remove_creator( creator ) + if creator.is_user_defined: + pass else: self.remove_creator( creator ) map( lambda header: self.adopt_include( include.include_t( header=header ) ) @@ -169,8 +171,8 @@ code = self.unindent(code) return os.linesep.join( includes ) + 2 * os.linesep + code + os.linesep - def add_include( self, header ): - self.adopt_include( include.include_t( header=header ) ) + def add_include( self, header, user_defined ): + self.adopt_include( include.include_t( header=header, user_defined=user_defined ) ) def add_namespace_usage( self, namespace_name ): self.adopt_creator( namespace.namespace_using_t( namespace_name ) Modified: pyplusplus_dev/pyplusplus/code_repository/convenience.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/convenience.py 2007-01-31 18:53:51 UTC (rev 890) +++ pyplusplus_dev/pyplusplus/code_repository/convenience.py 2007-01-31 22:12:43 UTC (rev 891) @@ -88,10 +88,19 @@ void copy_sequence( boost::python::object const& seq, Inserter inserter ){ index_type length = boost::python::len( seq ); for( index_type index = 0; index < length; ++index ){ - inserter( seq[index] ); + inserter = seq[index]; } } +template< class Inserter, class TItemType > +void copy_sequence( boost::python::object const& seq, Inserter inserter, boost::type< TItemType > ){ + index_type length = boost::python::len( seq ); + for( index_type index = 0; index < length; ++index ){ + boost::python::object item = seq[index]; + inserter = boost::python::extract< TItemType >( item ); + } +} + struct list_inserter{ list_inserter( boost::python::list& py_list ) : m_py_list( py_list ) @@ -112,17 +121,23 @@ , m_curr_pos( 0 ) , m_size( size ) {} - - void operator()( boost::python::object const & item ){ + + void insert( const T& item ){ if( m_size <= m_curr_pos ){ std::stringstream err; err << "Index out of range. Array size is" << m_size << ", " << "current position is" << m_curr_pos << "."; raise_error( PyExc_ValueError, err.str().c_str() ); } - m_array[ m_curr_pos ] = boost::python::extract< T >( item ); + m_array[ m_curr_pos ] = item; m_curr_pos += 1; } + + array_inserter_t<T>& + operator=( boost::python::object const & item ){ + insert( boost::python::extract< T >( item ) ); + return *this; + } private: T* m_array; Modified: pyplusplus_dev/pyplusplus/function_transformers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2007-01-31 18:53:51 UTC (rev 890) +++ pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2007-01-31 22:12:43 UTC (rev 891) @@ -49,3 +49,8 @@ def creator( function ): return transformers.type_modifier_t( function, *args, **keywd ) return creator + +def input_c_buffer( *args, **keywd ): + def creator( function ): + return transformers.input_c_buffer_t( function, *args, **keywd ) + return creator Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-01-31 18:53:51 UTC (rev 890) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-01-31 22:12:43 UTC (rev 891) @@ -224,9 +224,13 @@ _seq2arr = string.Template( os.linesep.join([ - 'pyplus_conv::ensure_uniform_sequence< $type >( $pylist, $array_size );' + 'pyplus_conv::ensure_uniform_sequence< $type >( $pylist, $array_size );' , 'pyplus_conv::copy_sequence( $pylist, pyplus_conv::array_inserter( $native_array, $array_size ) );'])) +_seq2vector = string.Template( os.linesep.join([ + 'pyplus_conv::ensure_uniform_sequence< $type >( $pylist );' + , 'pyplus_conv::copy_sequence( $pylist, std::back_inserter( $native_array), boost::type< $type >() );'])) + _arr2seq = string.Template( 'pyplus_conv::copy_container( $native_array, $native_array + $array_size, pyplus_conv::list_inserter( $pylist ) );' ) @@ -395,3 +399,95 @@ def configure_virtual_mem_fun( self, controller ): self.__configure_v_mem_fun_override( controller.override_controller ) self.__configure_v_mem_fun_default( controller.default_controller ) + + +class input_c_buffer_t(transformer.transformer_t): + """Handles an input of C buffere: + + void write( byte *buffer, int size ) -> void write( python sequence ) + """ + + def __init__(self, function, buffer_arg_ref, size_arg_ref): + """Constructor. + + @param buffer_arg_ref: "reference" to the buffer argument + @param buffer_arg_ref: "reference" to argument, which holds buffer size + """ + transformer.transformer_t.__init__( self, function ) + + self.buffer_arg = self.get_argument( buffer_arg_ref ) + self.buffer_arg_index = self.function.arguments.index( self.buffer_arg ) + + self.size_arg = self.get_argument( size_arg_ref ) + self.size_arg_index = self.function.arguments.index( self.size_arg ) + + if not is_ptr_or_array( self.buffer_arg.type ): + raise ValueError( '%s\nin order to use "input_c_buffer" transformation, "buffer" argument %s type must be a array or a pointer (got %s).' ) \ + % ( function, self.buffer_arg.name, self.buffer_arg.type) + + if not declarations.is_integral( self.size_arg.type ): + raise ValueError( '%s\nin order to use "input_c_buffer" transformation, "size" argument %s type must be an integral type (got %s).' ) \ + % ( function, self.size_arg.name, self.size_arg.type) + + self.buffer_item_type = declarations.array_item_type( self.buffer_arg.type ) + + def __str__(self): + return "input_c_buffer(buffer arg=%s, size arg=%s)" \ + % ( self.buffer_arg.name, self.size_arg.name) + + def required_headers( self ): + """Returns list of header files that transformer generated code depends on.""" + return [ code_repository.convenience.file_name, '<vector>', '<iterator>' ] + + def __configure_sealed(self, controller): + global _seq2arr + w_buffer_arg = controller.find_wrapper_arg( self.buffer_arg.name ) + w_buffer_arg.type = declarations.dummy_type_t( "boost::python::object" ) + + controller.remove_wrapper_arg( self.size_arg.name ) + + size_var = controller.declare_variable( + declarations.remove_const( self.size_arg.type ) + , self.size_arg.name + , ' = boost::python::len(%s)' % w_buffer_arg.name ) + + # Declare a variable that will hold the C array... + buffer_var = controller.declare_variable( + declarations.dummy_type_t( "std::vector< %s >" % self.buffer_item_type.decl_string ) + , "native_" + self.buffer_arg.name + , '(%s)' % size_var ) + + copy_pylist2arr = _seq2vector.substitute( type=self.buffer_item_type + , pylist=w_buffer_arg.name + , native_array=buffer_var ) + + controller.add_pre_call_code( copy_pylist2arr ) + + controller.modify_arg_expression( self.buffer_arg_index, '&%s[0]' % buffer_var ) + controller.modify_arg_expression( self.size_arg_index, '%s' % size_var ) + + def __configure_v_mem_fun_default( self, controller ): + self.__configure_sealed( controller ) + + def __configure_v_mem_fun_override( self, controller ): + raise NotImplementedError() + #global _arr2seq + #pylist = controller.declare_py_variable( declarations.dummy_type_t( 'boost::python::list' ) + #, 'py_' + self.arg.name ) + + #copy_arr2pylist = _arr2seq.substitute( native_array=self.arg.name + #, array_size=self.array_size + #, pylist=pylist ) + + #controller.add_py_pre_call_code( copy_arr2pylist ) + + def configure_mem_fun( self, controller ): + self.__configure_sealed( controller ) + + def configure_free_fun(self, controller ): + self.__configure_sealed( controller ) + + def configure_virtual_mem_fun( self, controller ): + self.__configure_v_mem_fun_override( controller.override_controller ) + self.__configure_v_mem_fun_default( controller.default_controller ) + Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-01-31 18:53:51 UTC (rev 890) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-01-31 22:12:43 UTC (rev 891) @@ -429,7 +429,7 @@ included = filter( lambda cc: isinstance(cc, code_creators.include_t) and cc.header==header , self.__extmodule.creators) if not included: - self.__extmodule.add_include( header ) + self.__extmodule.add_include( header, user_defined=True ) # Check if it is a header from the code repository if header in code_repository.headers: Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2007-01-31 18:53:51 UTC (rev 890) +++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2007-01-31 22:12:43 UTC (rev 891) @@ -8,6 +8,7 @@ #include <cmath> #include <string> +#include <iostream> namespace ft2{ @@ -219,6 +220,18 @@ }; +struct input_c_buffer_tester_t{ + std::string write( char* buffer, int dummy, int size ) const { + std::cout << "wwwwwwwwwww> " << std::string( buffer, size ); + return std::string( buffer, size ); + } + + static std::string write_s( int dummy, char* buffer, int size ){ + return std::string( buffer, size ); + } + +}; + } #endif//__function_transformations_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2007-01-31 18:53:51 UTC (rev 890) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2007-01-31 22:12:43 UTC (rev 891) @@ -79,6 +79,12 @@ clone.call_policies = call_policies.return_value_policy( call_policies.manage_new_object ) clone.add_transformation( ft.modify_type(0, declarations.remove_reference ) ) + cls = mb.class_( 'input_c_buffer_tester_t') + write_mf = cls.mem_fun( 'write' ) + write_mf.add_transformation( ft.input_c_buffer( 'buffer', 'size' ) ) + write_s = cls.mem_fun( 'write_s' ) + write_s.add_transformation( ft.input_c_buffer( 'buffer', 'size' ) ) + def run_tests(self, module): """Run the actual unit tests. """ @@ -226,6 +232,13 @@ tmp = module.modify_type_tester_t() self.failUnless( 123 == tmp.do_nothing(123) ) self.failUnless( tmp != tmp.clone(123) ) + + tmp = module.input_c_buffer_tester_t() + hw = 'hello world' + dummy = 11 + print 'xxxxxxxxxxx> ', tmp.write( list( hw ), dummy ) + self.failUnless( 'hello world' == tmp.write( list( hw ), dummy ) ) + self.failUnless( 'hello world' == tmp.write_s( dummy, tuple( list( hw ) ) ) ) def create_suite(): suite = unittest.TestSuite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-01-31 18:53:59
|
Revision: 890 http://svn.sourceforge.net/pygccxml/?rev=890&view=rev Author: roman_yakovenko Date: 2007-01-31 10:53:51 -0800 (Wed, 31 Jan 2007) Log Message: ----------- removing named_tuple.py Removed Paths: ------------- pyplusplus_dev/unittests/temp/named_tuple.py Deleted: pyplusplus_dev/unittests/temp/named_tuple.py =================================================================== --- pyplusplus_dev/unittests/temp/named_tuple.py 2007-01-31 08:41:50 UTC (rev 889) +++ pyplusplus_dev/unittests/temp/named_tuple.py 2007-01-31 18:53:51 UTC (rev 890) @@ -1,46 +0,0 @@ -# This file has been generated by Py++. - -# 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) - -class named_tuple(tuple): - """Creates tuple, which allows access to stored values by name and\or by index. - - Construction example: named_tuple( ('a',0), ('b',1) ) - 'a' and 'b' are names, while 0 and 1 are values - """ - - def __new__(cls, *args): - return tuple.__new__( cls, [ val for name, val in args] ) - - def __init__(self, *args): - tuple.__init__( self ) - self.__dict__[ '__name2value' ] = dict( args ) - - def __getattr__(self, name): - try: - return self.__dict__['__name2value'][ name ] - except KeyError: - raise AttributeError( "named_tuple has no attribute '%s'" % name ) - - def __setattr__(self, name, value): - raise AttributeError( "named_tuple has no attribute '%s'" % name ) - - def __getitem__( self, key ): - #TODO: it could be nice to support slicing. So the __getitem__ in case of - #slicing will return new named_tuple. - if isinstance( key, basestring ): - return self.__dict__['__name2value'][ key ] - else: - return super( named_tuple, self ).__getitem__( key ) - -if __name__ == '__main__': - nt = named_tuple( ('a',0), ('b',1) ) - assert nt.a == 0 and nt.b == 1 - a,b = nt - assert a == 0 and b == 1 - assert nt[ "a" ] == 0 and nt[ "b" ] == 1 - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-01-31 08:41:50
|
Revision: 889 http://svn.sourceforge.net/pygccxml/?rev=889&view=rev Author: roman_yakovenko Date: 2007-01-31 00:41:50 -0800 (Wed, 31 Jan 2007) Log Message: ----------- adding exposing of copy constructors Modified Paths: -------------- pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/vector3_tester.py Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-01-30 18:03:43 UTC (rev 888) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-01-31 08:41:50 UTC (rev 889) @@ -449,8 +449,6 @@ self.curr_code_creator.adopt_creator( static_method ) def visit_constructor( self ): - if self.curr_decl.is_copy_constructor: - return self.__types_db.update( self.curr_decl ) self.__dependencies_manager.add_exported( self.curr_decl ) if self.curr_decl.allow_implicit_conversion: Modified: pyplusplus_dev/unittests/vector3_tester.py =================================================================== --- pyplusplus_dev/unittests/vector3_tester.py 2007-01-30 18:03:43 UTC (rev 888) +++ pyplusplus_dev/unittests/vector3_tester.py 2007-01-31 08:41:50 UTC (rev 889) @@ -31,6 +31,8 @@ def run_tests( self, module): v3 = module.Vector3() self.failUnless( v3.ZERO == v3.do_smth() ) + #test copy constructor + self.failUnless( module.Vector3(v3.ZERO) == v3.do_smth() ) def create_suite(): suite = unittest.TestSuite() @@ -41,4 +43,4 @@ unittest.TextTestRunner(verbosity=2).run( create_suite() ) if __name__ == "__main__": - run_suite() \ No newline at end of file + run_suite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-01-30 18:03:44
|
Revision: 888 http://svn.sourceforge.net/pygccxml/?rev=888&view=rev Author: roman_yakovenko Date: 2007-01-30 10:03:43 -0800 (Tue, 30 Jan 2007) Log Message: ----------- adding new extension to be removed Modified Paths: -------------- developer_scripts/clean_source_dir.py Modified: developer_scripts/clean_source_dir.py =================================================================== --- developer_scripts/clean_source_dir.py 2007-01-30 12:08:48 UTC (rev 887) +++ developer_scripts/clean_source_dir.py 2007-01-30 18:03:43 UTC (rev 888) @@ -14,6 +14,7 @@ , '*.cpp~' , '*.hpp~' , '*.dll' + , '*.rest~' , '*.obj' , '*.a' , '*.def' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-01-30 12:08:53
|
Revision: 887 http://svn.sourceforge.net/pygccxml/?rev=887&view=rev Author: roman_yakovenko Date: 2007-01-30 04:08:48 -0800 (Tue, 30 Jan 2007) Log Message: ----------- expose operator= as "assign" function, with call policy "return_self" Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/data/operators_to_be_exported.hpp pyplusplus_dev/unittests/operators_tester.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2007-01-30 12:08:48 UTC (rev 887) @@ -316,7 +316,7 @@ @staticmethod def exportable( oper ): """returns True if Boost.Python or Py++ know how to export the operator""" - if isinstance( oper, declarations.member_operator_t ) and oper.symbol in ( '()', '[]' ): + if isinstance( oper, declarations.member_operator_t ) and oper.symbol in ( '()', '[]', '=' ): return '' if not operators_helper.is_supported( oper ): return messages.W1014 % oper.name @@ -335,6 +335,8 @@ alias = '__call__' elif self.symbol == '[]': alias = '__getitem__' + elif self.symbol == '=': + alias = 'assign' else: pass return alias Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2007-01-30 12:08:48 UTC (rev 887) @@ -18,6 +18,14 @@ ACCESS_TYPES = declarations.ACCESS_TYPES VIRTUALITY_TYPES = declarations.VIRTUALITY_TYPES +class impl_details: + class GAEUS_VALUES: #guess always expose using scope values + TRUE = 'true' + FALSE = 'false' + ALWAYS_TRUE = 'always true' + all = [ TRUE, FALSE, ALWAYS_TRUE ] + + always_expose_using_scope_documentation = \ """boolean, configures how Py++ should generate code for class. Py can generate code using IDL like syntax: @@ -49,7 +57,7 @@ """ def __init__(self): object.__init__( self ) - self._always_expose_using_scope = False + self._always_expose_using_scope = None self._indexing_suite = None self._equality_comparable = None self._less_than_comparable = None @@ -80,12 +88,24 @@ , doc="reference to indexing suite configuration class. " \ +"If the class is not STD container, returns None") - def _get_always_expose_using_scope( self ): - #I am almost sure this logic should be moved to code_creators + def guess_always_expose_using_scope_value( self ): if isinstance( self.indexing_suite, isuite2.indexing_suite2_t ) \ and ( self.indexing_suite.disable_methods or self.indexing_suite.disabled_methods_groups ): + return impl_details.GAEUS_VALUES.ALWAYS_TRUE + else: + return impl_details.GAEUS_VALUES.FALSE + + def _get_always_expose_using_scope( self ): + tmp = self.guess_always_expose_using_scope_value() + if tmp == impl_details.GAEUS_VALUES.ALWAYS_TRUE: return True + if None is self._always_expose_using_scope: + if impl_details.GAEUS_VALUES.TRUE == tmp: + self._always_expose_using_scope = True + else: + self._always_expose_using_scope = False return self._always_expose_using_scope + def _set_always_expose_using_scope( self, value ): self._always_expose_using_scope = value always_expose_using_scope = property( _get_always_expose_using_scope, _set_always_expose_using_scope @@ -328,17 +348,21 @@ vfunction_selector = lambda member: isinstance( member, declarations.member_function_t ) \ and member.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL members.extend( filter( vfunction_selector, self.private_members ) ) - #now lets filter out none public operators: Py++ does not support them right now - members = filter( lambda decl: not isinstance( decl, declarations.member_operator_t ) - or decl.access_type == declarations.ACCESS_TYPES.PUBLIC - , members ) + + def is_exportable( decl ): + #filter out non-public member operators - Py++ does not support them right now + if isinstance( decl, declarations.member_operator_t ) \ + and decl.access_type != declarations.ACCESS_TYPES.PUBLIC: + return False + #remove artificial constructors + if isinstance( decl, declarations.constructor_t ) and decl.is_artificial: + return False + if decl.ignore == True or decl.exportable == False: + return False + return True #-#if declarations.has_destructor( self ) \ #-# and not declarations.has_public_destructor( self ): - #remove artificial constructors - members = filter( lambda decl: not isinstance( decl, declarations.constructor_t ) - or not decl.is_artificial - , members ) - members = filter( lambda member: member.ignore == False and member.exportable, members ) + members = filter( is_exportable, members ) sorted_members = members if sort: sorted_members = sort( members ) @@ -484,3 +508,17 @@ def _readme_impl( self ): return self.is_wrapper_needed() + + def guess_always_expose_using_scope_value( self ): + def is_assign( oper ): + if oper.symbol != '=': + return False + if oper.is_artificial: + return False + if oper.access_type != ACCESS_TYPES.PUBLIC: + return False + return True + #MSVC 7.1 has problem with taking reference to operator= + if self.member_operators( is_assign, allow_empty=True, recursive=False ): + return impl_details.GAEUS_VALUES.ALWAYS_TRUE + return super(class_t, self).guess_always_expose_using_scope_value() Modified: pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2007-01-30 12:08:48 UTC (rev 887) @@ -115,6 +115,19 @@ else: return decl_wrappers.return_internal_reference() +class return_self_resolver_t( resolver_t ): + def __init__( self ): + resolver_t.__init__( self ) + + def __call__(self, calldef, hint=None): + if not isinstance( calldef, declarations.member_operator_t ): + return None + + if calldef.symbol != '=': + return None + + return decl_wrappers.return_self() + class variable_accessors_resolver_t( resolver_t ): def __init__( self ): resolver_t.__init__( self ) @@ -170,6 +183,7 @@ self.__resolvers.append( void_pointer_resolver_t() ) self.__resolvers.append( return_internal_reference_resolver_t() ) self.__resolvers.append( variable_accessors_resolver_t() ) + self.__resolvers.append( return_self_resolver_t() ) def __call__( self, calldef, hint=None ): for resolver in self.__resolvers: Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-01-30 12:08:48 UTC (rev 887) @@ -472,7 +472,7 @@ pass def visit_member_operator( self ): - if self.curr_decl.symbol in ( '()', '[]' ): + if self.curr_decl.symbol in ( '()', '[]', '=' ): self.visit_member_function() else: self.__types_db.update( self.curr_decl ) Modified: pyplusplus_dev/unittests/data/operators_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/operators_to_be_exported.hpp 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/unittests/data/operators_to_be_exported.hpp 2007-01-30 12:08:48 UTC (rev 887) @@ -1,29 +1,32 @@ -// 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) - -#ifndef __operators_to_be_exported_hpp__ -#define __operators_to_be_exported_hpp__ - -#include "boost/rational.hpp" +// 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) + +#ifndef __operators_to_be_exported_hpp__ +#define __operators_to_be_exported_hpp__ + +#include "boost/rational.hpp" #include <iostream> - -namespace pyplusplus{ namespace rational{ - -typedef boost::rational< long int > pyrational; - -struct helper{ - - void instantiate(){ - sizeof( pyrational ); - boost::gcd<long int>( 1, 1); + +namespace pyplusplus{ namespace rational{ + +typedef boost::rational< long int > pyrational; + +struct helper{ + + void instantiate(){ + sizeof( pyrational ); + boost::gcd<long int>( 1, 1); boost::lcm<long int>( 1, 1); - std::cout << pyrational( 1,1); - } -}; - -} } - - -#endif//__operators_to_be_exported_hpp__ + std::cout << pyrational( 1,1); + pyrational x(1,1); + x = pyrational( 2, 3 ); + + } +}; + +} } + + +#endif//__operators_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/operators_tester.py =================================================================== --- pyplusplus_dev/unittests/operators_tester.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/unittests/operators_tester.py 2007-01-30 12:08:48 UTC (rev 887) @@ -76,6 +76,9 @@ self.failUnless( 0 < r1 ) + r1 = pyrational( 5, 7 ) + self.failUnless( r1.assign( 17 ) == pyrational( 17, 1 ) ) + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) @@ -85,4 +88,4 @@ unittest.TextTestRunner(verbosity=2).run( create_suite() ) if __name__ == "__main__": - run_suite() \ No newline at end of file + run_suite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-01-29 07:26:31
|
Revision: 886 http://svn.sourceforge.net/pygccxml/?rev=886&view=rev Author: roman_yakovenko Date: 2007-01-28 23:26:32 -0800 (Sun, 28 Jan 2007) Log Message: ----------- improving handling of "already_exposed" declarations - warnings for them will not be shown Modified Paths: -------------- pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py Modified: pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py 2007-01-28 21:26:50 UTC (rev 885) +++ pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py 2007-01-29 07:26:32 UTC (rev 886) @@ -71,7 +71,8 @@ if self.__is_std_decl( decl ): #TODO add element_type to the list of dependencies return [] #std declarations should be exported by Py++! - + if decl.already_exposed: + return [] dependencies = decl.i_depend_on_them(recursive=False) if isinstance( decl, declarations.class_t ): dependencies = filter( lambda d: d.access_type != declarations.ACCESS_TYPES.PRIVATE This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-01-28 21:26:49
|
Revision: 885 http://svn.sourceforge.net/pygccxml/?rev=885&view=rev Author: roman_yakovenko Date: 2007-01-28 13:26:50 -0800 (Sun, 28 Jan 2007) Log Message: ----------- changing title Modified Paths: -------------- pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/automatic_conversion.rest Modified: pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/automatic_conversion.rest =================================================================== --- pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/automatic_conversion.rest 2007-01-28 20:54:19 UTC (rev 884) +++ pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/automatic_conversion.rest 2007-01-28 21:26:50 UTC (rev 885) @@ -1,6 +1,6 @@ -=================================================== -How to register ``shared_ptr<const T>`` conversion? -=================================================== +================================================= +Automatic conversion between C++ and Python types +================================================= .. contents:: Table of contents @@ -14,27 +14,27 @@ Content ------- -This example actually consist from 2 small, well documented examples. +This example actually consist from 2 small, well documented examples. The first one shows how to handle conversion between tuples: `boost::tuples::tuple`_ and Python tuple. .. _`boost::tuples::tuple` : http://boost.org/libs/tuple/doc/tuple_users_guide.html -The second one shows how to add an automatic conversion from Python tuple to -some registered class. The class registration allows you to use its functionality +The second one shows how to add an automatic conversion from Python tuple to +some registered class. The class registration allows you to use its functionality and enjoy from automatic conversion. Files ----- -* `tuples.hpp`_ file contains Boost.Tuple to\\from Python tuple conversion +* `tuples.hpp`_ file contains Boost.Tuple to\\from Python tuple conversion implementation - -* `tuples_tester.cpp`_ file contains few functions, which test the tuples + +* `tuples_tester.cpp`_ file contains few functions, which test the tuples conversion functionality -* `custom_rvalue.cpp`_ file contains example of registration custom r-value +* `custom_rvalue.cpp`_ file contains example of registration custom r-value converter * `sconstruct`_ file contains build instructions for scons build tool. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2007-01-28 20:54:21
|
Revision: 884 http://svn.sourceforge.net/pygccxml/?rev=884&view=rev Author: roman_yakovenko Date: 2007-01-28 12:54:19 -0800 (Sun, 28 Jan 2007) Log Message: ----------- adding as_tuple docs Modified Paths: -------------- pyplusplus_dev/docs/documentation/functions/call_policies.rest Modified: pyplusplus_dev/docs/documentation/functions/call_policies.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/call_policies.rest 2007-01-28 19:20:20 UTC (rev 883) +++ pyplusplus_dev/docs/documentation/functions/call_policies.rest 2007-01-28 20:54:19 UTC (rev 884) @@ -231,6 +231,77 @@ assert 0.5 == my_module.get_value() assert None is my_module.get_null_value() +as_tuple +-------- + +Class ``as_tuple`` is a model of `ResultConverterGenerator`_ which +can be used to wrap C++ functions returning a pointer to arrays with fixed size. +The policy will construct a Python tuple from the array and treat the array memory. + +Example +~~~~~~~ + +.. code-block:: C++ + + struct vector3{ + ... + + float* clone_row_data() const{ + float* values = new float[3]; + //copy values + return values; + } + + const flow* get_row_data() const{ + return m_values; + } + + private: + float m_values[3]; + }; + + namespace bpl = boost::python; + namespace pypp_cp = pyplusplus::call_policies; + BOOST_PYTHON_MODULE(my_module){ + bpl::class_< vector3 >( "vector3" ) + .def( "clone_row_data" + , &::vector3::clone_row_data + , bpl::return_value_policy< pypp_cp::arrays::as_tuple< 3, pypp_cp::memory_managers::delete_ > >() ) + .def( "get_row_data" + , &::vector3::get_row_data + , bpl::return_value_policy< pypp_cp::arrays::as_tuple< 3, pypp_cp::memory_managers::none > >() ) ); + } + +``as_tuple`` class +~~~~~~~~~~~~~~~~~~ +``as_tuple`` is a template class that takes few arguments: + +1. the size of the array - compile time constant + +2. memory management policy - a class, which will manage the return value. + There are two built-in memory managers: + + * delete\_ - the array will be deleted after it was copied to tuple, using + ``operator delete[]`` + + * none - do nothing + + +The `Py++`_ code is slightly different from the C++ one, but it is definitely shorter: + +.. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus.module_builder import call_policies + + mb = module_builder.module_builder_t( ... ) + mb.member_function( 'clone_row_data' ).call_policies \ + = call_policies.convert_array_to_tuple( 3, call_policies.memory_managers.delete_ ) + mb.member_function( 'get_row_data' ).call_policies \ + = call_policies.convert_array_to_tuple( 3, call_policies.memory_managers.none ) + + + .. _`ResultConverterGenerator` : http://boost.org/libs/python/doc/v2/ResultConverter.html#ResultConverterGenerator-concept .. _`Py++` : ./../pyplusplus.html This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |