pygccxml-commit Mailing List for C++ Python language bindings (Page 47)
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-13 19:03:40
|
Revision: 724 http://svn.sourceforge.net/pygccxml/?rev=724&view=rev Author: roman_yakovenko Date: 2006-11-13 11:00:19 -0800 (Mon, 13 Nov 2006) Log Message: ----------- integrating return_pointee_value call policies Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_repository/__init__.py pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py pyplusplus_dev/pyplusplus/module_builder/call_policies.py pyplusplus_dev/pyplusplus/module_creator/creator.py Modified: pyplusplus_dev/pyplusplus/code_repository/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/__init__.py 2006-11-13 15:43:25 UTC (rev 723) +++ pyplusplus_dev/pyplusplus/code_repository/__init__.py 2006-11-13 19:00:19 UTC (rev 724) @@ -16,8 +16,9 @@ import array_1 import gil_guard import convenience +import call_policies -all = [ array_1, gil_guard, convenience ] +all = [ array_1, gil_guard, convenience, call_policies ] headers = map( lambda f: f.file_name, all ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-11-13 15:43:25 UTC (rev 723) +++ pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-11-13 19:00:19 UTC (rev 724) @@ -80,7 +80,9 @@ from call_policies import return_by_value from call_policies import return_opaque_pointer from call_policies import return_value_policy +from call_policies import return_pointee_value from call_policies import is_return_opaque_pointer_policy +from call_policies import is_return_pointee_value_policy from decl_wrapper_printer import decl_wrapper_printer_t from decl_wrapper_printer import print_declarations Modified: pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2006-11-13 15:43:25 UTC (rev 723) +++ pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2006-11-13 19:00:19 UTC (rev 724) @@ -213,12 +213,18 @@ reference_existing_object = '::boost::python::reference_existing_object' return_by_value = '::boost::python::return_by_value' return_opaque_pointer = '::boost::python::return_opaque_pointer' +return_pointee_value = '::pyplusplus::call_policies::return_pointee_value' def return_value_policy( result_converter_generator, base=None): return return_value_policy_t( result_converter_generator, base ) - def is_return_opaque_pointer_policy( policy ): """returns True is policy represents return_value_policy<return_opaque_pointer>, False otherwise""" return isinstance( policy, return_value_policy_t ) \ and policy.result_converter_generator == return_opaque_pointer + +def is_return_pointee_value_policy( policy ): + """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/pyplusplus/module_builder/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/call_policies.py 2006-11-13 15:43:25 UTC (rev 723) +++ pyplusplus_dev/pyplusplus/module_builder/call_policies.py 2006-11-13 19:00:19 UTC (rev 724) @@ -17,3 +17,4 @@ from pyplusplus.decl_wrappers import return_by_value from pyplusplus.decl_wrappers import return_opaque_pointer from pyplusplus.decl_wrappers import return_value_policy +from pyplusplus.decl_wrappers import return_pointee_value \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-11-13 15:43:25 UTC (rev 723) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-11-13 19:00:19 UTC (rev 724) @@ -139,6 +139,7 @@ self.__free_operators = [] self.__exposed_free_fun_overloads = set() self.__opaque_types_manager = opaque_types_manager.manager_t( self.__extmodule ) + self.__return_pointee_value_exists = False def _prepare_decls( self, decls, doc_extractor ): global DO_NOT_REPORT_MSGS @@ -350,6 +351,14 @@ creators.reverse() self.__module_body.adopt_creators( creators, 0 ) + def __on_demand_include_call_policies( self, call_policy ): + if not self.__return_pointee_value_exists \ + and decl_wrappers.is_return_pointee_value_policy( call_policy ): + self.__return_pointee_value_exists = True + self.__extmodule.add_include( code_repository.call_policies.file_name ) + self.__extmodule.add_system_header( code_repository.call_policies.file_name ) + + def create(self, decl_headers=None): """Create and return the module for the extension. @@ -388,7 +397,8 @@ self.__types_db.update( self.curr_decl ) if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) - + self.__on_demand_include_call_policies( self.curr_decl.call_policies ) + maker_cls, fwrapper_cls = creators_wizard.find_out_mem_fun_creator_classes( self.curr_decl ) maker = None @@ -453,6 +463,7 @@ maker = code_creators.constructor_t( constructor=self.curr_decl, wrapper=cwrapper ) if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) + self.__on_demand_include_call_policies( self.curr_decl.call_policies ) self.curr_code_creator.adopt_creator( maker ) def visit_destructor( self ): @@ -469,7 +480,8 @@ def visit_casting_operator( self ): if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) - + self.__on_demand_include_call_policies( self.curr_decl.call_policies ) + self.__types_db.update( self.curr_decl ) if not self.curr_decl.parent.is_abstract and not declarations.is_reference( self.curr_decl.return_type ): maker = code_creators.casting_operator_t( operator=self.curr_decl ) @@ -499,6 +511,7 @@ self.__types_db.update( f ) if None is f.call_policies: f.call_policies = self.__call_policies_resolver( f ) + self.__on_demand_include_call_policies( f.call_policies ) overloads_cls_creator = code_creators.free_fun_overloads_class_t( overloads ) self.__extmodule.adopt_declaration_creator( overloads_cls_creator ) @@ -518,6 +531,8 @@ self.__types_db.update( self.curr_decl ) if None is self.curr_decl.call_policies: 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 ) self.curr_code_creator.adopt_creator( maker ) self.__opaque_types_manager.register_opaque( maker, self.curr_decl ) @@ -552,6 +567,7 @@ self.__types_db.update( f ) if None is f.call_policies: f.call_policies = self.__call_policies_resolver( f ) + self.__on_demand_include_call_policies( f.call_policies ) overloads_cls_creator = code_creators.mem_fun_overloads_class_t( overloads ) self.__extmodule.adopt_declaration_creator( overloads_cls_creator ) @@ -695,8 +711,10 @@ elif declarations.is_reference( self.curr_decl.type ): if None is self.curr_decl.getter_call_policies: self.curr_decl.getter_call_policies = self.__call_policies_resolver( self.curr_decl, 'get' ) + self.__on_demand_include_call_policies( self.curr_decl.getter_call_policies ) if None is self.curr_decl.setter_call_policies: self.curr_decl.setter_call_policies = self.__call_policies_resolver( self.curr_decl, 'set' ) + self.__on_demand_include_call_policies( self.curr_decl.setter_call_policies ) wrapper = code_creators.mem_var_ref_wrapper_t( variable=self.curr_decl ) maker = code_creators.mem_var_ref_t( variable=self.curr_decl, wrapper=wrapper ) self.__opaque_types_manager.register_opaque( maker, self.curr_decl ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-11-07 18:16:20
|
Revision: 696 http://svn.sourceforge.net/pygccxml/?rev=696&view=rev Author: roman_yakovenko Date: 2006-11-07 10:16:09 -0800 (Tue, 07 Nov 2006) Log Message: ----------- adding 2 small convenience functions Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/calldef.py Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2006-11-05 07:38:29 UTC (rev 695) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2006-11-07 18:16:09 UTC (rev 696) @@ -135,6 +135,22 @@ , doc="""The argument list. @type: list of L{argument_t}""") + @property + def required_args(self): + """list of all required arguments""" + r_args = [] + for arg in self.arguments: + if not arg.default_value: + r_args.append( arg ) + else: + break + return r_args + + @property + def optional_args(self): + """list of all optional arguments, the arguments that have default value""" + return self.arguments[ len( self.required_args ) : ] + def _get_exceptions(self): return self._exceptions def _set_exceptions(self, exceptions): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-11-05 07:38:35
|
Revision: 695 http://svn.sourceforge.net/pygccxml/?rev=695&view=rev Author: roman_yakovenko Date: 2006-11-04 23:38:29 -0800 (Sat, 04 Nov 2006) Log Message: ----------- adding small todo for global variables Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/global_variable.py Modified: pyplusplus_dev/pyplusplus/code_creators/global_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/global_variable.py 2006-11-02 08:47:11 UTC (rev 694) +++ pyplusplus_dev/pyplusplus/code_creators/global_variable.py 2006-11-05 07:38:29 UTC (rev 695) @@ -12,6 +12,9 @@ from pygccxml import declarations from pyplusplus import code_repository +#TODO: mutable global variable +#scope.attr( "x" ) = object( ptr( &x ) ) + #TODO: if variable is not const, then export it using boost::python::ptr class global_variable_base_t( registration_based.registration_based_t , declaration_based.declaration_based_t ): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-11-02 08:47:28
|
Revision: 694 http://svn.sourceforge.net/pygccxml/?rev=694&view=rev Author: roman_yakovenko Date: 2006-11-02 00:47:11 -0800 (Thu, 02 Nov 2006) Log Message: ----------- fixing few bugs in indexing suite v2 Modified Paths: -------------- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp pyplusplus_dev/indexing_suite_v2/indexing/map.hpp pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp pyplusplus_dev/indexing_suite_v2/indexing/set.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/algorithms.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -151,25 +151,11 @@ static size_type count (container &, key_param); static bool contains (container &, key_param); - static boost::python::list keys( container & ); - // Default visit_container_class template<typename PythonClass, typename Policy> static void visit_container_class( PythonClass &pyClass, Policy const &policy) { ContainerTraits::visit_container_class (pyClass, policy); - pyClass.def( "keys", &self_type::keys ); - - //~ object class_name(cl.attr("__name__")); - //~ extract<std::string> class_name_extractor(class_name); - //~ std::string = class_name_extractor() + "_entry"; - - //~ class_<value_type>(elem_name.c_str()) - //~ .def("data", &DerivedPolicies::get_data, get_data_return_policy()) - //~ .def("key", &DerivedPolicies::get_key) - //~ ; - - } @@ -529,25 +515,6 @@ return c.count (key); } - template<typename ContainerTraits, typename Ovr> - boost::python::list - assoc_algorithms<ContainerTraits, Ovr>::keys( container &c ) - { - 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 ){ - //if( unique_keys.end() == unique_keys.find( index->first ) ){ - // unique_keys.insert( index->first ); - if( !_keys.count( index->first ) ){ - _keys.append( index->first ); - } - //} - } - - return _keys; - } - ///////////////////////////////////////////////////////////////////////// // Some meta-information to select algorithms for const and // non-const qualified containers. All algorithms_selector specializations Modified: pyplusplus_dev/indexing_suite_v2/indexing/map.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/map.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/indexing_suite_v2/indexing/map.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -96,8 +96,18 @@ static reference get (container &, index_param); // Version to return only the mapped type + static boost::python::list keys( container & ); + static void assign (container &, index_param, value_param); static void insert (container &, index_param, value_param); + + template<typename PythonClass, typename Policy> + static void visit_container_class( PythonClass &pyClass, Policy const &policy) + { + ContainerTraits::visit_container_class (pyClass, policy); + pyClass.def( "keys", &self_type::keys ); + } + }; #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) @@ -159,6 +169,26 @@ return most_derived::find_or_throw (c, ix)->second; } + + template<typename ContainerTraits, typename Ovr> + boost::python::list + map_algorithms<ContainerTraits, Ovr>::keys( container &c ) + { + 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 ){ + //if( unique_keys.end() == unique_keys.find( index->first ) ){ + // unique_keys.insert( index->first ); + if( !_keys.count( index->first ) ){ + _keys.append( index->first ); + } + //} + } + + return _keys; + } + ///////////////////////////////////////////////////////////////////////// // Assign a value at a particular index (map version) ///////////////////////////////////////////////////////////////////////// Modified: pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -93,8 +93,18 @@ static boost::python::list get (container &, index_param); // Version to return only the mapped type + static boost::python::list keys( container & ); + static void assign (container &, index_param, value_param); static void insert (container &, index_param, value_param); + + template<typename PythonClass, typename Policy> + static void visit_container_class( PythonClass &pyClass, Policy const &policy) + { + ContainerTraits::visit_container_class (pyClass, policy); + pyClass.def( "keys", &self_type::keys ); + } + }; template< @@ -124,6 +134,26 @@ return l; } + template<typename ContainerTraits, typename Ovr> + boost::python::list + multimap_algorithms<ContainerTraits, Ovr>::keys( container &c ) + { + 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 ){ + //if( unique_keys.end() == unique_keys.find( index->first ) ){ + // unique_keys.insert( index->first ); + if( !_keys.count( index->first ) ){ + _keys.append( index->first ); + } + //} + } + + return _keys; + } + + ///////////////////////////////////////////////////////////////////////// // Assign a value at a particular index (map version) ///////////////////////////////////////////////////////////////////////// Modified: pyplusplus_dev/indexing_suite_v2/indexing/set.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/set.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/indexing_suite_v2/indexing/set.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -85,6 +85,14 @@ typedef typename Parent::index_param index_param; static void insert (container &, index_param); + + template<typename PythonClass, typename Policy> + static void visit_container_class( PythonClass &pyClass, Policy const &policy) + { + ContainerTraits::visit_container_class (pyClass, policy); + pyClass.def( "add", &self_type::insert ); + } + }; #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) @@ -144,13 +152,15 @@ set_algorithms<ContainerTraits, Ovr>::insert( container &c, index_param ix) { - if (!c.insert (ix).second) - { - PyErr_SetString( - PyExc_ValueError, "Set already holds value for insertion"); + c.insert (ix); + //~ Python set does not raise exception in this situation + //~ if (!c.insert (ix).second) + //~ { + //~ PyErr_SetString( + //~ PyExc_ValueError, "Set already holds value for insertion"); - boost::python::throw_error_already_set (); - } + //~ boost::python::throw_error_already_set (); + //~ } } } } } Modified: pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -9,6 +9,7 @@ #include <vector> #include <string> #include <map> +#include <set> namespace indexing_suites2 { @@ -66,6 +67,11 @@ return multimap_ints_t(); } +typedef std::set< std::string > set_strings_t; +inline set_strings_t create_set_strings(){ + return set_strings_t(); } -#endif//__indexing_suites2_to_be_exported_hpp__ \ No newline at end of file +} + +#endif//__indexing_suites2_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/indexing_suites2_tester.py =================================================================== --- pyplusplus_dev/unittests/indexing_suites2_tester.py 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/unittests/indexing_suites2_tester.py 2006-11-02 08:47:11 UTC (rev 694) @@ -53,7 +53,12 @@ items_ptr = module.items_ptr_t() items_ptr.append( item ) self.failUnless( items_ptr[0].value == 1977 ) - print 'xx' + + set_of_strings = module.create_set_strings() + set_of_strings.add("s") + set_of_strings.add("s1") + set_of_strings.add("s") + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) @@ -63,4 +68,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: <mb...@us...> - 2006-10-30 16:44:11
|
Revision: 693 http://svn.sourceforge.net/pygccxml/?rev=693&view=rev Author: mbaas Date: 2006-10-30 08:43:55 -0800 (Mon, 30 Oct 2006) Log Message: ----------- Added a section about how to keep the declaration tree small (using the -fxml-start option of gccxml). Modified Paths: -------------- pyplusplus_dev/docs/documentation/best_practices.rest Modified: pyplusplus_dev/docs/documentation/best_practices.rest =================================================================== --- pyplusplus_dev/docs/documentation/best_practices.rest 2006-10-28 12:38:46 UTC (rev 692) +++ pyplusplus_dev/docs/documentation/best_practices.rest 2006-10-30 16:43:55 UTC (rev 693) @@ -88,8 +88,37 @@ .. _`this error` : http://boost.org/libs/python/doc/v2/faq.html#c1204 .. __ : ./../../pygccxml/design.html +* Keep the declaration tree small. + When parsing the header files to build the declaration tree, there will also + be the occasional "junk" declaration inside the tree that is not relevant to + the bindings you want to generate. These extra declarations come from header + files that were included somewhere in the header files that you were actually + parsing (e.g. if that library uses the STL or OpenGL or other system headers + then the final declaration tree will contain those declarations, too). + It can happen that the majority of declarations in your declaration tree are + such "junk" declarations that are not required for generating your bindings + and that just slow down the generation process (reading the declaration cache + and doing queries will take longer). + To speed up your generation process you might want to consider making the + declaration tree as small as possible and only store those declarations that + somehow have an influence on the bindings. Ideally, this is done as early + as possible and luckily gccxml provides an option that allows you to reduce + the number of declarations that it will store in the output XML file. You can + specify one or more declarations using the ``-fxml-start`` option and only + those sub-tree starting at the specified declarations will be written. For + example, if you specify the name of a particular class, only this class + and all its members will get written. Or if your project already uses + a dedicated namespace you can simply use this namespace as a starting point + and all declarations stemming from system headers will be ignored (except + for those declarations that are actually used within your library). + + In the ``pygccxml`` package you can set the value for the ``-fxml-start`` + option using the ``start_with_declarations`` attribute of the + ``pygccxml.parser.config_t`` object that you are passing to the parser. + + .. _`Py++` : ./../pyplusplus.html .. _`pygccxml` : ./../../pygccxml/pygccxml.html .. _`Boost.Python`: 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...> - 2006-10-28 12:38:56
|
Revision: 692 http://svn.sourceforge.net/pygccxml/?rev=692&view=rev Author: roman_yakovenko Date: 2006-10-28 05:38:46 -0700 (Sat, 28 Oct 2006) Log Message: ----------- introducing call_traits( http://boost.org/libs/utility/call_traits.htm ) and making small refactoring to use it Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/calldef.py pyplusplus_dev/pyplusplus/decl_wrappers/python_traits.py pyplusplus_dev/pyplusplus/function_transformers/code_manager.py pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-10-27 23:03:19 UTC (rev 691) +++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-10-28 12:38:46 UTC (rev 692) @@ -198,24 +198,8 @@ def function_call_args( self ): params = [] - for index in range( len( self.declaration.arguments ) ): - arg_type = declarations.remove_alias( self.declaration.arguments[index].type ) - if decl_wrappers.python_traits.is_immutable( arg_type ): - params.append( self.argument_name( index ) ) - elif declarations.is_reference( arg_type ): - no_ref = declarations.remove_reference( arg_type ) - if decl_wrappers.python_traits.is_immutable( no_ref ): - #pass by value - params.append( self.argument_name( index ) ) - else: - #pass by ref - params.append( 'boost::ref(%s)' % self.argument_name( index ) ) - elif declarations.is_pointer( arg_type ) \ - and not declarations.is_pointer( arg_type.base ) \ - and not decl_wrappers.python_traits.is_immutable( arg_type.base ): - params.append( 'boost::python::ptr(%s)' % self.argument_name( index ) ) - else: - params.append( self.argument_name( index ) ) + 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 ) def wrapped_class_identifier( self ): Modified: pyplusplus_dev/pyplusplus/decl_wrappers/python_traits.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/python_traits.py 2006-10-27 23:03:19 UTC (rev 691) +++ pyplusplus_dev/pyplusplus/decl_wrappers/python_traits.py 2006-10-28 12:38:46 UTC (rev 692) @@ -16,4 +16,20 @@ or declarations.smart_pointer_traits.is_smart_pointer( type_ ) #todo is_complex, ... - +def call_traits( type_ ): + """http://boost.org/libs/utility/call_traits.htm""" + type_ = declarations.remove_alias( type_ ) + if is_immutable( type_ ): + return "%s" #pass by value + elif declarations.is_reference( type_ ): + no_ref = declarations.remove_reference( type_ ) + if is_immutable( no_ref ): + return "%s" #pass by value + else: + return "boost::ref(%s)" #pass by ref + elif declarations.is_pointer( type_ ) \ + and not is_immutable( type_.base ) \ + and not declarations.is_pointer( type_.base ): + return "boost::python::ptr(%s)" #pass by ptr + else: + return "%s" #pass by value Modified: pyplusplus_dev/pyplusplus/function_transformers/code_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-10-27 23:03:19 UTC (rev 691) +++ pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-10-28 12:38:46 UTC (rev 692) @@ -358,4 +358,3 @@ # Invoke the inherited method that sets the actual variables code_manager_t.init_variables(self) - Modified: pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-10-27 23:03:19 UTC (rev 691) +++ pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-10-28 12:38:46 UTC (rev 692) @@ -176,7 +176,8 @@ @param transformers: Function transformer objects @type transformers: list of transformer_t """ - + #prevent recursive import + from pyplusplus import decl_wrappers # Code manager for the virtual function self.virtual_func = code_manager_t() # Code manager for the wrapper function @@ -202,7 +203,9 @@ self.virtual_func.class_name = wrapper_class self.virtual_func.FUNC_NAME = decl.name self.virtual_func.CALL_FUNC_NAME = decl.name - self.virtual_func.input_params = map(lambda a: self._function_call_arg(a), decl.arguments) + self.virtual_func.input_params \ + = map( lambda arg: decl_wrappers.python_traits.call_traits( arg.type ) % arg.name + , decl.arguments ) self.wrapper_func.arg_list = decl.arguments[:] self.wrapper_func.class_name = wrapper_class @@ -488,42 +491,7 @@ decl = parent return None - # _function_call_arg - def _function_call_arg(self, arg): - """Return the C++ expression that represents arg in the actual function call. - This helper method returns a string that contains a C++ expression - that references the argument arg. This expression is supposed to - be used in the function invocation of which this is one input - parameter. The return value is one of three variants: - - - <name> - - boost::ref(<name>) - - boost::python::ptr(<name>) - - @rtype: str - """ - arg_type = declarations.remove_alias( arg.type ) - #prevent recursive import - from pyplusplus import decl_wrappers - if decl_wrappers.python_traits.is_immutable( arg_type ): - return arg.name - elif declarations.is_reference( arg_type ): - no_ref = declarations.remove_reference( arg_type ) - if decl_wrappers.python_traits.is_immutable( no_ref ): - #pass by value - return arg.name - else: - #pass by ref - return 'boost::ref(%s)' % arg.name - elif declarations.is_pointer( arg_type ) \ - and not declarations.is_pointer( arg_type.base ) \ - and not decl_wrappers.python_traits.is_immutable( arg_type.base ): - return 'boost::python::ptr(%s)' % arg.name - else: - return arg.name - - # return_virtual_result_t class return_virtual_result_t(transformer_t): """Extract and return the result value of the virtual function. @@ -609,4 +577,4 @@ print wm.subst_wrapper(template) print wm.get_includes() print wm.get_includes("virtual") - print wm.get_includes("wrapper") + print wm.get_includes("wrapper") \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-27 23:03:25
|
Revision: 691 http://svn.sourceforge.net/pygccxml/?rev=691&view=rev Author: roman_yakovenko Date: 2006-10-27 16:03:19 -0700 (Fri, 27 Oct 2006) Log Message: ----------- updating indexing suite v2 unit test Modified Paths: -------------- pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp pyplusplus_dev/unittests/indexing_suites2_tester.py Modified: pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp 2006-10-27 23:02:12 UTC (rev 690) +++ pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp 2006-10-27 23:03:19 UTC (rev 691) @@ -60,6 +60,12 @@ } } + +typedef std::multimap< int, int > multimap_ints_t; +inline multimap_ints_t create_multimap_ints(){ + return multimap_ints_t(); } +} + #endif//__indexing_suites2_to_be_exported_hpp__ \ No newline at end of file Modified: pyplusplus_dev/unittests/indexing_suites2_tester.py =================================================================== --- pyplusplus_dev/unittests/indexing_suites2_tester.py 2006-10-27 23:02:12 UTC (rev 690) +++ pyplusplus_dev/unittests/indexing_suites2_tester.py 2006-10-27 23:03:19 UTC (rev 691) @@ -22,6 +22,9 @@ , *args) def customize(self, generator): + items = generator.global_ns.typedef( 'items_t' ) + items = declarations.remove_declarated( items.type ) + items.alias = "items_t" fvector = generator.global_ns.typedef( 'fvector' ) fvector = declarations.remove_declarated( fvector.type ) fvector.indexing_suite.disable_method( 'extend' ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-27 23:02:23
|
Revision: 690 http://svn.sourceforge.net/pygccxml/?rev=690&view=rev Author: roman_yakovenko Date: 2006-10-27 16:02:12 -0700 (Fri, 27 Oct 2006) Log Message: ----------- adding support for multimap adding few message why function\variable is not exported Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite2.py pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py pyplusplus_dev/pyplusplus/module_creator/creator.py Modified: pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-10-27 22:58:40 UTC (rev 689) +++ pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-10-27 23:02:12 UTC (rev 690) @@ -91,7 +91,11 @@ answer.append( '%s.def( ' % self.parent.class_var_name) else: answer.append( 'def( ' ) - answer.append( algorithm.create_identifier(self, "::boost::python::indexing::container_suite" ) ) + bpi = algorithm.create_identifier(self, "::boost::python::indexing" ) + if self.declaration.indexing_suite.use_container_suite: + answer.append( bpi + '::container_suite' ) + else: + answer.append( bpi + '::' + self.declaration.name.split( '<' )[0] + '_suite' ) answer.append( '< ' ) answer.append( self.decl_identifier ) if self.does_user_disable_methods(): Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-10-27 22:58:40 UTC (rev 689) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-10-27 23:02:12 UTC (rev 690) @@ -197,7 +197,11 @@ , doc="boolean, if True, will use BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS macro to expose declarations" \ +"Default value is False.") - + def _exportable_impl_derived(self): + if self.access_type == declarations.ACCESS_TYPES.PRIVATE \ + and self.virtuality == declarations.VIRTUALITY_TYPES.NOT_VIRTUAL: + return "Py++ doesn't export private not virtual functions." + return '' class constructor_t( declarations.constructor_t, calldef_t ): """defines a set of properties, that will instruct Py++ how to expose the constructor""" def __init__(self, *arguments, **keywords): @@ -216,6 +220,8 @@ def _exportable_impl_derived( self ): if self.is_artificial: return 'Py++ does not exports compiler generated constructors' + if self.access_type == declarations.ACCESS_TYPES.PRIVATE: + return "Py++ doesn't export private constructor." return '' def does_define_implicit_conversion( self ): @@ -304,6 +310,9 @@ , doc="Gives right alias for operator()( __call__ ) and operator[]( __getitem__ )" ) def _exportable_impl_derived( self ): + if self.access_type == declarations.ACCESS_TYPES.PRIVATE \ + and self.virtuality == declarations.VIRTUALITY_TYPES.NOT_VIRTUAL: + return "Py++ doesn't export private operators." return operators_helper.exportable( self ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite2.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite2.py 2006-10-27 22:58:40 UTC (rev 689) +++ pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite2.py 2006-10-27 23:02:12 UTC (rev 690) @@ -62,7 +62,14 @@ self._disabled_methods = set() self._disabled_groups = set() self._default_applied = False + self._use_container_suite = False + def get_use_container_suite( self ): + return self._use_container_suite + def set_use_container_suite( self, value ): + self._use_container_suite = value + use_container_suite = property( get_use_container_suite, set_use_container_suite ) + def _get_container_class( self ): return self.__container_class container_class = property( _get_container_class Modified: pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-10-27 22:58:40 UTC (rev 689) +++ pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-10-27 23:02:12 UTC (rev 690) @@ -65,4 +65,7 @@ cls = declarations.class_traits.get_declaration( type_ ) if not cls.name: return "Py++ can not expose variables of with unnamed type." + if isinstance( self.parent, declarations.class_t ): + if self.access_type != declarations.ACCESS_TYPES.PUBLIC: + return "Py++ doesn't expose private or protected member variables." return '' Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-10-27 22:58:40 UTC (rev 689) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-10-27 23:02:12 UTC (rev 690) @@ -37,6 +37,7 @@ , 'deque<' : "boost/python/suite/indexing/deque.hpp" , 'list<' : "boost/python/suite/indexing/list.hpp" , 'map<' : "boost/python/suite/indexing/map.hpp" + , 'multimap<' : "boost/python/suite/indexing/multimap.hpp" , 'hash_map<' : "boost/python/suite/indexing/map.hpp" , 'set<' : "boost/python/suite/indexing/set.hpp" , 'hash_set<' : "boost/python/suite/indexing/set.hpp" @@ -52,6 +53,10 @@ , 'Py++, by default, does not expose compiler generated declarations.' , 'Py++ can not expose private class.' , 'Py++ will generate class wrapper - class contains definition of virtual or pure virtual member function' + , "Py++ doesn't expose private or protected member variables." + , "Py++ doesn't export private not virtual functions." + , "Py++ doesn't export private constructor." + , "Py++ doesn't export private operators." ] class creator_t( declarations.decl_visitor_t ): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-27 22:58:47
|
Revision: 689 http://svn.sourceforge.net/pygccxml/?rev=689&view=rev Author: roman_yakovenko Date: 2006-10-27 15:58:40 -0700 (Fri, 27 Oct 2006) Log Message: ----------- small bug fixes Modified Paths: -------------- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp Modified: pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-10-27 22:38:20 UTC (rev 688) +++ pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-10-27 22:58:40 UTC (rev 689) @@ -32,7 +32,7 @@ #include <functional> #include <stdexcept> #include <string> -#inllude <set> +#include <set> namespace boost { namespace python { namespace indexing { template<typename ContainerTraits, typename Ovr = detail::no_override> @@ -534,12 +534,15 @@ assoc_algorithms<ContainerTraits, Ovr>::keys( container &c ) { boost::python::list _keys; - std::set< key_param > unique_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 ){ - if( unique_keys.end() == unique_keys.find( index->first ) ){ - unique_keys.insert( unique_keys ); + //if( unique_keys.end() == unique_keys.find( index->first ) ){ + // unique_keys.insert( index->first ); + if( !_keys.count( index->first ) ){ _keys.append( index->first ); } + //} } return _keys; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-27 22:38:29
|
Revision: 688 http://svn.sourceforge.net/pygccxml/?rev=688&view=rev Author: roman_yakovenko Date: 2006-10-27 15:38:20 -0700 (Fri, 27 Oct 2006) Log Message: ----------- adding mutlimap container support + new method "keys" for map and multimap containers Modified Paths: -------------- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp Added Paths: ----------- pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp Modified: pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-10-25 08:35:41 UTC (rev 687) +++ pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-10-27 22:38:20 UTC (rev 688) @@ -12,6 +12,7 @@ // ======= // 2003/ 9/11 rmg File creation from suite_utils.hpp // 2003/10/28 rmg Split container-specific versions into separate headers +// 2006/10/25 Roman Adding keys function to assoc_algorithms class // // $Id: algorithms.hpp,v 1.1.2.15 2004/02/08 18:57:42 raoulgough Exp $ // @@ -31,6 +32,7 @@ #include <functional> #include <stdexcept> #include <string> +#inllude <set> namespace boost { namespace python { namespace indexing { template<typename ContainerTraits, typename Ovr = detail::no_override> @@ -149,6 +151,28 @@ static size_type count (container &, key_param); static bool contains (container &, key_param); + static boost::python::list keys( container & ); + + // Default visit_container_class + template<typename PythonClass, typename Policy> + static void visit_container_class( PythonClass &pyClass, Policy const &policy) + { + ContainerTraits::visit_container_class (pyClass, policy); + pyClass.def( "keys", &self_type::keys ); + + //~ object class_name(cl.attr("__name__")); + //~ extract<std::string> class_name_extractor(class_name); + //~ std::string = class_name_extractor() + "_entry"; + + //~ class_<value_type>(elem_name.c_str()) + //~ .def("data", &DerivedPolicies::get_data, get_data_return_policy()) + //~ .def("key", &DerivedPolicies::get_key) + //~ ; + + + } + + protected: static iterator find_or_throw (container &, index_param); }; @@ -505,6 +529,22 @@ return c.count (key); } + template<typename ContainerTraits, typename Ovr> + boost::python::list + assoc_algorithms<ContainerTraits, Ovr>::keys( container &c ) + { + boost::python::list _keys; + std::set< key_param > unique_keys; + 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( unique_keys ); + _keys.append( index->first ); + } + } + + return _keys; + } + ///////////////////////////////////////////////////////////////////////// // Some meta-information to select algorithms for const and // non-const qualified containers. All algorithms_selector specializations Added: pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp (rev 0) +++ pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2006-10-27 22:38:20 UTC (rev 688) @@ -0,0 +1,165 @@ +// 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) +// +// Header file multimap.hpp +// +// Indexing algorithms support for std::multimap instances +// +// History +// ======= +// 2006/10/27 Roman File creation from map.hpp +// + +#ifndef BOOST_PYTHON_INDEXING_MULTIMAP_HPP +#define BOOST_PYTHON_INDEXING_MULTIMAP_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> +#include <functional> +#include <map> + +namespace boost { namespace python { namespace indexing { + ///////////////////////////////////////////////////////////////////////// + // ContainerTraits implementation for std::map instances + ///////////////////////////////////////////////////////////////////////// + + template<typename Container> + class multimap_traits : public base_container_traits<Container> + { + typedef base_container_traits<Container> base_class; + + public: +# if BOOST_WORKAROUND (BOOST_MSVC, <= 1200) + // MSVC6 has a nonstandard name for mapped_type in std::multimap + typedef typename Container::referent_type value_type; +# else + typedef typename Container::mapped_type value_type; +# endif + typedef value_type & reference; + typedef typename Container::key_type index_type; // operator[] + typedef typename Container::key_type key_type; // find, count, ... + + typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <value_type>::param_type + value_param; + typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <key_type>::param_type + key_param; + typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <index_type>::param_type + index_param; + + BOOST_STATIC_CONSTANT( + method_set_type, + supported_methods = ( + method_iter + + | method_getitem + | method_contains + | method_count + | method_has_key + + | detail::method_set_if< + base_class::is_mutable, + method_setitem + | method_delitem + | method_insert + >::value + )); + }; + + ///////////////////////////////////////////////////////////////////////// + // Algorithms implementation for std::multimap instances + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr = detail::no_override> + class multimap_algorithms + : public assoc_algorithms + <ContainerTraits, + typename detail::maybe_override + <multimap_algorithms<ContainerTraits, Ovr>, Ovr> + ::type> + { + typedef multimap_algorithms<ContainerTraits, Ovr> self_type; + typedef typename detail::maybe_override<self_type, Ovr>::type most_derived; + typedef assoc_algorithms<ContainerTraits, most_derived> Parent; + + public: + typedef typename Parent::container container; + typedef typename Parent::reference reference; + typedef typename Parent::index_param index_param; + typedef typename Parent::value_param value_param; + + static boost::python::list get (container &, index_param); + // Version to return only the mapped type + + static void assign (container &, index_param, value_param); + static void insert (container &, index_param, value_param); + }; + + template< + class Container, + method_set_type MethodMask = all_methods, + class Traits = multimap_traits<Container> + > + struct multimap_suite + : container_suite<Container, MethodMask, multimap_algorithms<Traits> > + { + }; + + ///////////////////////////////////////////////////////////////////////// + // Index into a container (multimap version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + boost::python::list + multimap_algorithms<ContainerTraits, Ovr>::get (container &c, index_param ix) + { + boost::python::list l; + typedef BOOST_DEDUCED_TYPENAME container::iterator iter_type; + for( iter_type index = c.lower_bound( ix ); index != c.upper_bound( ix ); ++index ){ + boost::python::object v( index->second ); + l.append( v ); + } + return l; + } + + ///////////////////////////////////////////////////////////////////////// + // Assign a value at a particular index (map version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void + multimap_algorithms<ContainerTraits, Ovr>::assign( + container &c, index_param ix, value_param val) + { + typedef std::pair< + BOOST_DEDUCED_TYPENAME self_type::container_traits::index_type + , BOOST_DEDUCED_TYPENAME self_type::container_traits::value_type> + pair_type; + + // Can't use std::make_pair, because param types may be references + c.insert (pair_type (ix, val)); + } + + + ///////////////////////////////////////////////////////////////////////// + // Insert a new key, value pair into a map + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void + multimap_algorithms<ContainerTraits, Ovr>::insert( + container &c, index_param ix, value_param val) + { + typedef std::pair + <BOOST_DEDUCED_TYPENAME self_type::container_traits::index_type, + BOOST_DEDUCED_TYPENAME self_type::container_traits::value_type> + pair_type; + + // Can't use std::make_pair, because param types may be references + c.insert (pair_type (ix, val) ); + } +} } } + +#endif // BOOST_PYTHON_INDEXING_MULTIMAP_HPP This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-25 08:35:49
|
Revision: 687 http://svn.sourceforge.net/pygccxml/?rev=687&view=rev Author: roman_yakovenko Date: 2006-10-25 01:35:41 -0700 (Wed, 25 Oct 2006) Log Message: ----------- adding missing function_transformation.py file small cosmetic change in sm Modified Paths: -------------- pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py Added Paths: ----------- pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py Added: pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py (rev 0) +++ pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py 2006-10-25 08:35:41 UTC (rev 687) @@ -0,0 +1,19 @@ +# Copyright 2006 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) + + +"""This module contains the class L{function_transformation_t}. +""" + + +class function_transformation_t: + def __init__(self, transformers): + """Constructor. + """ + self.__transformers = list(transformers) + + @property + def transformers( self ): + return self.__transformers Modified: pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-10-24 21:13:48 UTC (rev 686) +++ pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-10-25 08:35:41 UTC (rev 687) @@ -8,6 +8,7 @@ """This module contains the L{substitution_manager_t} class. """ +import os from pygccxml import declarations from code_manager import code_manager_t, wrapper_code_manager_t from transformer import transformer_t @@ -290,48 +291,31 @@ self._funcs_initialized = True - # The default method which is used when a particular method from - # the code_base_t interface is not implemented - defmeth = lambda x: None + block_sep = os.linesep * 2 # Create the wrapper function pre-call block... - src = map(lambda cb: getattr(cb, "wrapper_pre_call", defmeth)(self), transformers) - src = filter(lambda x: x!=None, src) - precall = "\n\n".join(src) - self.wrapper_func.PRE_CALL = precall + tmp = filter(None, map(lambda cb: cb.wrapper_pre_call(self), transformers) ) + self.wrapper_func.PRE_CALL = block_sep.join( tmp ) # Create the wrapper function post-call block... - src = map(lambda cb: getattr(cb, "wrapper_post_call", defmeth)(self), transformers) - src = filter(lambda x: x!=None, src) - src.reverse() - postcall = "\n\n".join(src) - self.wrapper_func.POST_CALL = postcall + tmp = filter(None, map(lambda cb: cb.wrapper_post_call(self), transformers) ) + self.wrapper_func.POST_CALL = block_sep.join( tmp ) # Create the wrapper function cleanup block... - src = map(lambda cb: getattr(cb, "wrapper_cleanup", defmeth)(self), transformers) - src = filter(lambda x: x!=None, src) - cleanup = "\n\n".join(src) - self.wrapper_func.CLEANUP = cleanup + tmp = filter(None, map(lambda cb: cb.wrapper_cleanup(self), transformers) ) + self.wrapper_func.CLEANUP = block_sep.join( tmp ) # Create the virtual function pre-call block... - src = map(lambda cb: getattr(cb, "virtual_pre_call", defmeth)(self), transformers) - src = filter(lambda x: x!=None, src) - precall = "\n\n".join(src) - self.virtual_func.PRE_CALL = precall + tmp = filter(None, map(lambda cb: cb.virtual_pre_call(self), transformers) ) + self.virtual_func.PRE_CALL = block_sep.join( tmp ) # Create the virtual function post-call block... - src = map(lambda cb: getattr(cb, "virtual_post_call", defmeth)(self), transformers) - src = filter(lambda x: x!=None, src) - src.reverse() - postcall = "\n\n".join(src) - self.virtual_func.POST_CALL = postcall - + tmp = filter(None, map(lambda cb: cb.virtual_post_call(self), transformers) ) + self.virtual_func.POST_CALL = block_sep.join( tmp ) + # Create the virtual function cleanup block... - src = map(lambda cb: getattr(cb, "virtual_cleanup", defmeth)(self), transformers) - src = filter(lambda x: x!=None, src) - cleanup = "\n\n".join(src) - self.virtual_func.CLEANUP = cleanup + tmp = filter(None, map(lambda cb: cb.virtual_cleanup(self), transformers) ) + self.virtual_func.CLEANUP = block_sep.join( tmp ) - # remove_arg def remove_arg(self, idx): """Remove an argument from the wrapper function. @@ -625,4 +609,4 @@ print wm.subst_wrapper(template) print wm.get_includes() print wm.get_includes("virtual") - print wm.get_includes("wrapper") \ No newline at end of file + print wm.get_includes("wrapper") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-24 21:13:55
|
Revision: 686 http://svn.sourceforge.net/pygccxml/?rev=686&view=rev Author: roman_yakovenko Date: 2006-10-24 14:13:48 -0700 (Tue, 24 Oct 2006) Log Message: ----------- changing the interface of FT feature Modified Paths: -------------- pyplusplus_dev/unittests/function_transformations_tester.py Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2006-10-24 21:02:08 UTC (rev 685) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2006-10-24 21:13:48 UTC (rev 686) @@ -7,9 +7,8 @@ import sys import unittest import fundamental_tester_base -from pyplusplus.function_transformers.transformers import * -from pyplusplus.decl_wrappers import * - +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' @@ -21,20 +20,21 @@ def customize( self, mb ): image = mb.class_( "image_t" ) - image.member_function( "get_size" ).function_transformers.extend([output_t(1), output_t(2)]) - image.member_function( "get_one_value" ).function_transformers.extend([output_t(1)]) - image.member_function( "get_size2" ).function_transformers.extend([output_t(1), output_t(2)]) - image.member_function( "input_arg" ).function_transformers.extend([input_t(1)]) - image.member_function( "fixed_input_array" ).function_transformers.extend([input_array_t(1,3)]) - image.member_function( "fixed_output_array" ).function_transformers.extend([output_array_t(1,3)]) - mb.free_function("get_cpp_instance").call_policies = return_value_policy(reference_existing_object) + image.member_function( "get_size" ).add_transformation( ft.output(1), ft.output(2) ) + image.member_function( "get_one_value" ).add_transformation( ft.output(1) ) + image.member_function( "get_size2" ).add_transformation( ft.output(1), ft.output(2) ) + image.member_function( "input_arg" ).add_transformation( ft.input(1) ) + image.member_function( "fixed_input_array" ).add_transformation( ft.input_array(1,3) ) + image.member_function( "fixed_output_array" ).add_transformation( ft.output_array(1,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").function_transformers.append(output_t(1)) + cls.member_function("member").add_transformation( ft.output(1) ) cls = mb.class_("ft_private_destructor_t") - cls.member_function("get_value").function_transformers.append(output_t(1)) + cls.member_function("get_value").add_transformation( ft.output(1) ) mb.decls(lambda decl: decl.name[0]=="_").exclude() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-24 21:02:21
|
Revision: 685 http://svn.sourceforge.net/pygccxml/?rev=685&view=rev Author: roman_yakovenko Date: 2006-10-24 14:02:08 -0700 (Tue, 24 Oct 2006) Log Message: ----------- changing the interface of FT feature Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/function_transformers/__init__.py pyplusplus_dev/pyplusplus/function_transformers/code_manager.py pyplusplus_dev/pyplusplus/function_transformers/subst.py pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py pyplusplus_dev/pyplusplus/module_creator/creators_wizard.py Modified: pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-10-24 19:18:07 UTC (rev 684) +++ pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-10-24 21:02:08 UTC (rev 685) @@ -66,7 +66,8 @@ calldef_wrapper_t.__init__( self, function=function ) # Create the substitution manager - sm = function_transformers.substitution_manager_t(function, transformers=function.function_transformers) + sm = function_transformers.substitution_manager_t( function + , transformers=function.transformations[0].transformers) sm.init_funcs() self._subst_manager = sm @@ -251,7 +252,9 @@ calldef_wrapper_t.__init__( self, function=function ) # Create the substitution manager - sm = function_transformers.substitution_manager_t(function, transformers=function.function_transformers) + sm = function_transformers.substitution_manager_t(function + , transformers=function.transformations[0].transformers ) + sm.init_funcs() self._subst_manager = sm @@ -530,4 +533,4 @@ # argument list) self.declaration.arguments = self._subst_manager.wrapper_func.arg_list - return answer + return answer \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-10-24 19:18:07 UTC (rev 684) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-10-24 21:02:08 UTC (rev 685) @@ -8,6 +8,7 @@ import user_text import decl_wrapper from pygccxml import declarations +from pyplusplus import function_transformers as ft class calldef_t(decl_wrapper.decl_wrapper_t): """base class for all decl_wrappers callable objects classes.""" @@ -28,7 +29,7 @@ self._use_default_arguments = True self._create_with_signature = False self._overridable = None - self._function_transformers = None + self._transformations = None def get_call_policies(self): return self._call_policies @@ -78,16 +79,6 @@ else: return False - #def _finalize_impl( self, error_behavior ): - #if not isinstance( self, declarations.member_calldef_t ): - #pass - #elif self.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL: - #raise RuntimeError( "In order to expose pure virtual function, you should allow to Py++ to create wrapper." ) - #elif self.access_type == declarations.ACCESS_TYPES.PROTECTED: - #self.ignore = True - #else: - #pass - def get_overridable( self ): """Check if the method can be overridden.""" if None is self._overridable: @@ -115,28 +106,25 @@ overridable = property( get_overridable, set_overridable , doc = get_overridable.__doc__ ) - - def _get_function_transformers(self): + @property + def transformations(self): """Get method for property 'function_transformers'. Returns a reference to the internal list (which may be modified). """ - if None is self._function_transformers: + if None is self._transformations: #TODO: for trivial cases get_size( int&, int& ) Py++ should guess #function transformers - self._function_transformers = [] - return self._function_transformers + self._transformations = [] + return self._transformations - def _set_function_transformers(self, function_transformers): - """Set method for property 'function_transformers'.""" - self._function_transformers = function_transformers + def add_transformation(self, *args): + """Set method for property 'function_transformers'. - function_transformers = property( _get_function_transformers, _set_function_transformers, - doc = """A list of function transformer objects that should be applied to the generated C++ code (default: []). - The returned list is the internal list (not a copy) which may be modified. - @type: list""") + args is a list of transformers + """ + self.transformations.append( ft.function_transformation_t( args ) ) - def _exportable_impl_derived( self ): return '' Modified: pyplusplus_dev/pyplusplus/function_transformers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2006-10-24 19:18:07 UTC (rev 684) +++ pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2006-10-24 21:02:08 UTC (rev 685) @@ -18,4 +18,20 @@ from substitution_manager import substitution_manager_t from transformer import transformer_t -import transformers \ No newline at end of file +import transformers +from function_transformation import function_transformation_t + +def output( *args, **keywd ): + return transformers.output_t( *args, **keywd ) + +def input( *args, **keywd ): + return transformers.input_t( *args, **keywd ) + +def inout( *args, **keywd ): + return transformers.inout_t( *args, **keywd ) + +def input_array( *args, **keywd ): + return transformers.input_array_t( *args, **keywd ) + +def output_array( *args, **keywd ): + return transformers.output_array_t( *args, **keywd ) Modified: pyplusplus_dev/pyplusplus/function_transformers/code_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-10-24 19:18:07 UTC (rev 684) +++ pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-10-24 21:02:08 UTC (rev 685) @@ -359,4 +359,3 @@ # Invoke the inherited method that sets the actual variables code_manager_t.init_variables(self) - Modified: pyplusplus_dev/pyplusplus/function_transformers/subst.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/subst.py 2006-10-24 19:18:07 UTC (rev 684) +++ pyplusplus_dev/pyplusplus/function_transformers/subst.py 2006-10-24 21:02:08 UTC (rev 685) @@ -140,4 +140,3 @@ return "" return "\n".join(map(lambda s: ((n*" ")+s).rstrip(), code.split("\n"))) - Modified: pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-10-24 19:18:07 UTC (rev 684) +++ pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-10-24 21:02:08 UTC (rev 685) @@ -11,7 +11,6 @@ from pygccxml import declarations from code_manager import code_manager_t, wrapper_code_manager_t from transformer import transformer_t -from pyplusplus import decl_wrappers # substitution_manager_t class substitution_manager_t: @@ -521,6 +520,8 @@ @rtype: str """ arg_type = declarations.remove_alias( arg.type ) + #prevent recursive import + from pyplusplus import decl_wrappers if decl_wrappers.python_traits.is_immutable( arg_type ): return arg.name elif declarations.is_reference( arg_type ): Modified: pyplusplus_dev/pyplusplus/module_creator/creators_wizard.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creators_wizard.py 2006-10-24 19:18:07 UTC (rev 684) +++ pyplusplus_dev/pyplusplus/module_creator/creators_wizard.py 2006-10-24 21:02:08 UTC (rev 685) @@ -20,9 +20,11 @@ maker_cls = None fwrapper_cls = None access_level = decl.parent.find_out_member_access_type( decl ) + if len( decl.transformations ) not in ( 0, 1 ): + raise RuntimeError( "Right now Py++ does not support multiple transformation applied on a single function." ) if access_level == ACCESS_TYPES.PUBLIC: if decl.virtuality == VIRTUALITY_TYPES.NOT_VIRTUAL: - if decl.function_transformers: + if decl.transformations: maker_cls = code_creators.mem_fun_transformed_t fwrapper_cls = code_creators.mem_fun_transformed_wrapper_t else: @@ -31,7 +33,7 @@ fwrapper_cls = code_creators.mem_fun_pv_wrapper_t maker_cls = code_creators.mem_fun_pv_t else: - if decl.function_transformers: + if decl.transformations: fwrapper_cls = code_creators.mem_fun_v_transformed_wrapper_t maker_cls = code_creators.mem_fun_v_transformed_t else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-24 19:18:17
|
Revision: 684 http://svn.sourceforge.net/pygccxml/?rev=684&view=rev Author: roman_yakovenko Date: 2006-10-24 12:18:07 -0700 (Tue, 24 Oct 2006) Log Message: ----------- adding base class for all transformers Modified Paths: -------------- pyplusplus_dev/pyplusplus/function_transformers/transformers.py Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-10-24 19:10:52 UTC (rev 683) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-10-24 19:18:07 UTC (rev 684) @@ -16,11 +16,12 @@ - L{output_array_t} """ import os +import transformer from pygccxml import declarations from pyplusplus import code_repository # output_t -class output_t: +class output_t( transformer.transformer_t ): """Handles a single output variable. The specified variable is removed from the argument list and is turned @@ -30,6 +31,7 @@ """ def __init__(self, idx): + transformer.transformer_t.__init__( self ) """Constructor. The specified argument must be a reference or a pointer. @@ -78,7 +80,7 @@ # input_t -class input_t: +class input_t(transformer.transformer_t): """Handles a single input variable. The reference on the specified variable is removed. @@ -94,6 +96,7 @@ @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 ) self.idx = idx def __str__(self): @@ -115,7 +118,7 @@ sm.insert_arg(self.idx, noref_arg, arg.name) # inout_t -class inout_t: +class inout_t(transformer.transformer_t): """Handles a single input/output variable. void foo(int& v) -> v = foo(v) @@ -129,6 +132,7 @@ @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 ) self.idx = idx self.local_var = "<not initialized>" @@ -175,7 +179,7 @@ # input_array_t -class input_array_t: +class input_array_t(transformer.transformer_t): """Handles an input array with fixed size. void setVec3(double* v) -> setVec3(object v) @@ -194,6 +198,7 @@ @param size: The fixed size of the input array @type size: int """ + transformer.transformer_t.__init__( self ) self.idx = idx self.size = size @@ -267,7 +272,7 @@ # output_array_t -class output_array_t: +class output_array_t(transformer.transformer_t): """Handles an output array of a fixed size. void getVec3(double* v) -> v = getVec3() @@ -285,7 +290,7 @@ @param size: The fixed size of the output array @type size: int """ - + transformer.transformer_t.__init__( self ) self.idx = idx self.size = size @@ -355,3 +360,4 @@ , 'ivar' : self.virtual_ivar , 'array_name' : self.argname } + \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-24 19:11:20
|
Revision: 683 http://svn.sourceforge.net/pygccxml/?rev=683&view=rev Author: roman_yakovenko Date: 2006-10-24 12:10:52 -0700 (Tue, 24 Oct 2006) Log Message: ----------- renaming function_transformation.py => transformer.py function_transformer_t => transformer_t arg_policies.py => transformers.py Modified Paths: -------------- pyplusplus_dev/contrib/pypp_api/pypp_api/__init__.py pyplusplus_dev/pyplusplus/function_transformers/__init__.py pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py pyplusplus_dev/unittests/function_transformations_tester.py Added Paths: ----------- pyplusplus_dev/pyplusplus/function_transformers/transformer.py pyplusplus_dev/pyplusplus/function_transformers/transformers.py Removed Paths: ------------- pyplusplus_dev/pyplusplus/function_transformers/arg_policies.py pyplusplus_dev/pyplusplus/function_transformers/function_transformer.py Modified: pyplusplus_dev/contrib/pypp_api/pypp_api/__init__.py =================================================================== --- pyplusplus_dev/contrib/pypp_api/pypp_api/__init__.py 2006-10-24 12:10:40 UTC (rev 682) +++ pyplusplus_dev/contrib/pypp_api/pypp_api/__init__.py 2006-10-24 19:10:52 UTC (rev 683) @@ -69,11 +69,11 @@ from decltypes import * #from argpolicy import * -from pyplusplus.function_transformers.arg_policies import output_t as Output -from pyplusplus.function_transformers.arg_policies import input_t as Input -from pyplusplus.function_transformers.arg_policies import inout_t as InOut -from pyplusplus.function_transformers.arg_policies import input_array_t as InputArray -from pyplusplus.function_transformers.arg_policies import output_array_t as OutputArray +from pyplusplus.function_transformers.transformers import output_t as Output +from pyplusplus.function_transformers.transformers import input_t as Input +from pyplusplus.function_transformers.transformers import inout_t as InOut +from pyplusplus.function_transformers.transformers import input_array_t as InputArray +from pyplusplus.function_transformers.transformers import output_array_t as OutputArray from modulebuilder import ModuleBuilder Modified: pyplusplus_dev/pyplusplus/function_transformers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2006-10-24 12:10:40 UTC (rev 682) +++ pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2006-10-24 19:10:52 UTC (rev 683) @@ -17,6 +17,5 @@ """ from substitution_manager import substitution_manager_t -from function_transformer import function_transformer_t - -import arg_policies +from transformer import transformer_t +import transformers \ No newline at end of file Deleted: pyplusplus_dev/pyplusplus/function_transformers/arg_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/arg_policies.py 2006-10-24 12:10:40 UTC (rev 682) +++ pyplusplus_dev/pyplusplus/function_transformers/arg_policies.py 2006-10-24 19:10:52 UTC (rev 683) @@ -1,357 +0,0 @@ -# Copyright 2006 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) -# -# Initial author: Matthias Baas - -"""This module contains the standard argument policy objects. - -The following policies are available: - - - L{output_t} - - L{input_t} - - L{inout_t} - - L{input_array_t} - - L{output_array_t} -""" -import os -from pygccxml import declarations -from pyplusplus import code_repository - -# output_t -class output_t: - """Handles a single output variable. - - The specified variable is removed from the argument list and is turned - into a return value. - - void getValue(int& v) -> v = getValue() - """ - - def __init__(self, idx): - """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 - """ - self.idx = idx - self.local_var = "<not initialized>" - - def __str__(self): - return "Output(%d)"%(self.idx) - - def init_funcs(self, sm): - # Remove the specified output argument from the wrapper function - arg = sm.remove_arg(self.idx) - - # Do some sanity checking (whether the argument can actually be - # an output argument, i.e. it has to be a reference or a pointer) - reftype = arg.type - if not (isinstance(reftype, declarations.reference_t) or - isinstance(reftype, declarations.pointer_t)): - raise ValueError, '%s\nOutput variable %d ("%s") must be a reference or a pointer (got %s)'%(sm.decl, self.idx, arg.name, arg.type) - - # Declare a local variable that will receive the output value - self.local_var = sm.wrapper_func.declare_local(arg.name, str(reftype.base)) - # Append the output to the result tuple - sm.wrapper_func.result_exprs.append(self.local_var) - - # Replace the expression in the C++ function call - if isinstance(reftype, declarations.pointer_t): - sm.wrapper_func.input_params[self.idx-1] = "&%s"%self.local_var - else: - sm.wrapper_func.input_params[self.idx-1] = self.local_var - - - def virtual_post_call(self, sm): - """Extract the C++ value after the call to the Python function. - """ - arg = sm.virtual_func.arg_list[self.idx-1] - res = "// Extract the C++ value for output argument '%s' (index: %d)\n"%(arg.name, self.idx) - if isinstance(arg.type, declarations.pointer_t): - res += "*" - res += "%s = boost::python::extract<%s>(%s);"%(arg.name, arg.type.base, sm.py_result_expr(self.local_var)) - return res - - -# input_t -class input_t: - """Handles a single input variable. - - The reference on the specified variable is removed. - - void setValue(int& v) -> setValue(v) - """ - - def __init__(self, idx): - """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 - """ - self.idx = idx - - def __str__(self): - return "Input(%d)"%(self.idx) - - def init_funcs(self, sm): - # Remove the specified input argument from the wrapper function - arg = sm.remove_arg(self.idx) - - # Do some checks (the arg has to be a reference or a pointer) - reftype = arg.type - if not (isinstance(reftype, declarations.reference_t) or - isinstance(reftype, declarations.pointer_t)): - raise ValueError, '%s\nInput variable %d ("%s") must be a reference or a pointer (got %s)'%(sm.decl, self.idx, arg.name, arg.type) - - # Create an equivalent argument that is not a reference type - noref_arg = declarations.argument_t(name=arg.name, type=arg.type.base, default_value=arg.default_value) - # Insert the noref argument - sm.insert_arg(self.idx, noref_arg, arg.name) - -# inout_t -class inout_t: - """Handles a single input/output variable. - - void foo(int& v) -> v = foo(v) - """ - - def __init__(self, idx): - """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 - """ - self.idx = idx - self.local_var = "<not initialized>" - - def __str__(self): - return "InOut(%d)"%(self.idx) - - def init_funcs(self, sm): - # Remove the specified input argument from the wrapper function - arg = sm.remove_arg(self.idx) - - # Do some checks (the arg has to be a reference or a pointer) - reftype = arg.type - if not (isinstance(reftype, declarations.reference_t) or - isinstance(reftype, declarations.pointer_t)): - raise ValueError, '%s\nInOut variable %d ("%s") must be a reference or a pointer (got %s)'%(sm.decl, self.idx, arg.name, arg.type) - - # Create an equivalent argument that is not a reference type - noref_arg = declarations.argument_t(name=arg.name, type=arg.type.base, default_value=arg.default_value) - # Insert the noref argument - sm.insert_arg(self.idx, 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 - if isinstance(reftype, declarations.pointer_t): - sm.wrapper_func.input_params[self.idx-1] = "&%s"%self.local_var - else: - sm.wrapper_func.input_params[self.idx-1] = self.local_var - - - def virtual_post_call(self, sm): - """Extract the C++ value after the call to the Python function. - """ - arg = sm.virtual_func.arg_list[self.idx-1] - res = "// Extract the C++ value for in/out argument '%s' (index: %d)\n"%(arg.name, self.idx) - if isinstance(arg.type, declarations.pointer_t): - res += "*" - res += "%s = boost::python::extract<%s>(%s);"%(arg.name, arg.type.base, sm.py_result_expr(self.local_var)) - return res - - - -# input_array_t -class input_array_t: - """Handles an input array with fixed size. - - void setVec3(double* v) -> setVec3(object v) - # v must be a sequence of 3 floats - - - TODO: Error handling (in the wrapper function)! - - """ - - def __init__(self, idx, size): - """Constructor. - - @param idx: Index of the argument that is an input array (the first arg has index 1). - @type idx: int - @param size: The fixed size of the input array - @type size: int - """ - self.idx = idx - self.size = size - - self.argname = None - self.basetype = None - self.carray = None - self.wrapper_ivar = None - self.virtual_ivar = None - self.pylist = None - - def __str__(self): - return "InputArray(%d,%d)"%(self.idx, self.size) - - def init_funcs(self, sm): - - # Remove the original argument... - arg = sm.remove_arg(self.idx) - - if not (isinstance(arg.type, declarations.pointer_t) or - isinstance(arg.type, declarations.array_t)): - raise ValueError, "%s\nArgument %d (%s) must be a pointer."%(sm.decl, self.idx, arg.name) - - # 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_local("py_"+arg.name, "boost::python::list") - - # Replace the removed argument with a Python object. - newarg = declarations.argument_t(arg.name, declarations.dummy_type_t("boost::python::object")) - sm.insert_arg(self.idx, newarg, self.pylist) - - self.argname = arg.name - self.basetype = str(arg.type.base).replace("const", "").strip() - - # Declare a variable that will hold the C array... - self.carray = sm.wrapper_func.declare_local("c_"+arg.name, self.basetype, size=self.size) - # and an int which is used for the loop - self.wrapper_ivar = sm.wrapper_func.declare_local("i", "int", default=0) - # and another one in the virtual function - self.virtual_ivar = sm.virtual_func.declare_local("i", "int", default=0) - - # Replace the input parameter with the C array - sm.wrapper_func.input_params[self.idx-1] = self.carray - - # Request the convenience header - sm.wrapper_func.require_header(code_repository.convenience.file_name) - - def wrapper_pre_call(self, sm): - """Wrapper function code. - """ - tmpl = [] - tmpl.append( 'pyplusplus::convenience::ensure_uniform_sequence< %(type)s >( %(argname)s, %(size)d );' ) - tmpl.append( 'for(%(ivar)s=0; %(ivar)s<%(size)d; ++%(ivar)s){' ) - tmpl.append( ' %(array_name)s[ %(ivar)s ] = boost::python::extract< %(type)s >( %(argname)s[%(ivar)s] );' ) - tmpl.append( '}' ) - return os.linesep.join( tmpl ) % { - 'type' : self.basetype - , 'argname' : self.argname - , 'size' : self.size - , 'ivar' : self.wrapper_ivar - , 'array_name' : self.carray - } - - def virtual_pre_call(self, sm): - """Virtual function code. - """ - res = "" - res += "// Copy the array '%s' into list '%s'...\n"%(self.argname, self.pylist) - res += "for(%s=0; %s<%d; %s++)\n"%(self.virtual_ivar, self.virtual_ivar, self.size, self.virtual_ivar) - res += " %s.append(%s[%s]);"%(self.pylist, self.argname, self.virtual_ivar) - return res - - -# output_array_t -class output_array_t: - """Handles an output array of a fixed size. - - void getVec3(double* v) -> v = getVec3() - # v will be a list with 3 floats - - TODO: Error handling (in the virtual function)! - - """ - - def __init__(self, idx, 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 - """ - - self.idx = idx - self.size = size - - self.argname = None - self.basetype = None - self.pyval = None - self.cval = None - self.ivar = None - - def __str__(self): - return "OutputArray(%d,%d)"%(self.idx, self.size) - - def init_funcs(self, sm): - # Remove the original argument... - arg = sm.remove_arg(self.idx) - - if not (isinstance(arg.type, declarations.pointer_t) or - isinstance(arg.type, declarations.array_t)): - raise ValueError, "%s\nArgument %d (%s) must be a pointer."%(sm.decl, self.idx, arg.name) - - self.argname = arg.name - self.basetype = str(arg.type.base).replace("const", "").strip() - - # Wrapper: - - # Declare a variable that will hold the C array... - self.wrapper_cval = sm.wrapper_func.declare_local("c_"+self.argname, self.basetype, size=self.size) - # Declare a Python list which will receive the output... - self.wrapper_pyval = sm.wrapper_func.declare_local(self.argname, "boost::python::list") - # ...and add it to the result - sm.wrapper_func.result_exprs.append(arg.name) - - # Declare an int which is used for the loop - self.wrapper_ivar = sm.wrapper_func.declare_local("i", "int", default=0) - - sm.wrapper_func.input_params[self.idx-1] = self.wrapper_cval - - # Virtual: - - # Declare a variable that will receive the Python list - self.virtual_pyval = sm.virtual_func.declare_local("py_"+self.argname, "boost::python::object") - - # Declare an int which is used for the loop - self.virtual_ivar = sm.virtual_func.declare_local("i", "int", default=0) - - # Request the convenience header - sm.virtual_func.require_header(code_repository.convenience.file_name) - - - def wrapper_post_call(self, sm): - res = "" - res += "// Copy the sequence '%s' into '%s'...\n"%(self.wrapper_cval, self.wrapper_pyval) - res += "for(%s=0; %s<%d; %s++)\n"%(self.wrapper_ivar, self.wrapper_ivar, self.size, self.wrapper_ivar) - res += " %s.append(%s[%s]);"%(self.wrapper_pyval, self.wrapper_cval , self.wrapper_ivar) - return res - - def virtual_post_call(self, sm): - tmpl = [] - tmpl.append( 'pyplusplus::convenience::ensure_uniform_sequence< %(type)s >( %(argname)s, %(size)d );' ) - tmpl.append( 'for(%(ivar)s=0; %(ivar)s<%(size)d; ++%(ivar)s){' ) - tmpl.append( ' %(array_name)s[ %(ivar)s ] = boost::python::extract< %(type)s >( %(argname)s[%(ivar)s] );' ) - tmpl.append( '}' ) - return os.linesep.join( tmpl ) % { - 'type' : self.basetype - , 'argname' : sm.py_result_expr(self.argname) - , 'size' : self.size - , 'ivar' : self.virtual_ivar - , 'array_name' : self.argname - } Deleted: pyplusplus_dev/pyplusplus/function_transformers/function_transformer.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/function_transformer.py 2006-10-24 12:10:40 UTC (rev 682) +++ pyplusplus_dev/pyplusplus/function_transformers/function_transformer.py 2006-10-24 19:10:52 UTC (rev 683) @@ -1,109 +0,0 @@ -# Copyright 2006 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) -# -# Initial author: Matthias Baas - -"""This module contains the class L{function_transformer_t}. -""" - -import sys, os.path, copy, re, types -from pygccxml import declarations, parser - - -# function_transformer_t -class function_transformer_t: - """Base class for a function transformer. - - This class specifies the interface that a user written transformer - has to implement. It doesn't contain any actual functionality so - a user doesn't have to derive from this class. Methods that are not - implemented are treated as if they would do nothing and return None. - - @author: Matthias Baas - """ - - def __init__(self): - """Constructor. - """ - pass - - 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 - Modified: pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-10-24 12:10:40 UTC (rev 682) +++ pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-10-24 19:10:52 UTC (rev 683) @@ -10,7 +10,7 @@ from pygccxml import declarations from code_manager import code_manager_t, wrapper_code_manager_t -from function_transformer import function_transformer_t +from transformer import transformer_t from pyplusplus import decl_wrappers # substitution_manager_t @@ -174,7 +174,7 @@ @param wrapper_class: The name of the class the generated function should belong to (or None if the generated function should be a free function) @type wrapper_class: str @param transformers: Function transformer objects - @type transformers: list of function_transformer_t + @type transformers: list of transformer_t """ # Code manager for the virtual function @@ -540,7 +540,7 @@ # return_virtual_result_t -class return_virtual_result_t(function_transformer_t): +class return_virtual_result_t(transformer_t): """Extract and return the result value of the virtual function. This is an internal code block object that is automatically appended @@ -548,7 +548,7 @@ """ def __init__(self): - function_transformer_t.__init__(self) + transformer_t.__init__(self) self.result_var = "<not initialized>" def __str__(self): @@ -591,7 +591,7 @@ if __name__=="__main__": import pyplusplus from pygccxml import parser - from arg_policies import Output + from transformers import Output cpp = """ class Spam { @@ -624,4 +624,4 @@ print wm.subst_wrapper(template) print wm.get_includes() print wm.get_includes("virtual") - print wm.get_includes("wrapper") + print wm.get_includes("wrapper") \ No newline at end of file Copied: pyplusplus_dev/pyplusplus/function_transformers/transformer.py (from rev 682, pyplusplus_dev/pyplusplus/function_transformers/function_transformer.py) =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformer.py (rev 0) +++ pyplusplus_dev/pyplusplus/function_transformers/transformer.py 2006-10-24 19:10:52 UTC (rev 683) @@ -0,0 +1,107 @@ +# Copyright 2006 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) +# +# Initial author: Matthias Baas + +"""This module contains the class L{transformer_t}. +""" + +import sys, os.path, copy, re, types +from pygccxml import declarations, parser + + +class transformer_t: + """Base class for a function transformer. + + This class specifies the interface that a user written transformer + has to implement. It doesn't contain any actual functionality so + a user doesn't have to derive from this class. Methods that are not + implemented are treated as if they would do nothing and return None. + + @author: Matthias Baas + """ + + def __init__(self): + """Constructor. + """ + pass + + 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 Copied: pyplusplus_dev/pyplusplus/function_transformers/transformers.py (from rev 682, pyplusplus_dev/pyplusplus/function_transformers/arg_policies.py) =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py (rev 0) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-10-24 19:10:52 UTC (rev 683) @@ -0,0 +1,357 @@ +# Copyright 2006 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) +# +# Initial author: Matthias Baas + +"""This module contains the standard argument policy objects. + +The following policies are available: + + - L{output_t} + - L{input_t} + - L{inout_t} + - L{input_array_t} + - L{output_array_t} +""" +import os +from pygccxml import declarations +from pyplusplus import code_repository + +# output_t +class output_t: + """Handles a single output variable. + + The specified variable is removed from the argument list and is turned + into a return value. + + void getValue(int& v) -> v = getValue() + """ + + def __init__(self, idx): + """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 + """ + self.idx = idx + self.local_var = "<not initialized>" + + def __str__(self): + return "Output(%d)"%(self.idx) + + def init_funcs(self, sm): + # Remove the specified output argument from the wrapper function + arg = sm.remove_arg(self.idx) + + # Do some sanity checking (whether the argument can actually be + # an output argument, i.e. it has to be a reference or a pointer) + reftype = arg.type + if not (isinstance(reftype, declarations.reference_t) or + isinstance(reftype, declarations.pointer_t)): + raise ValueError, '%s\nOutput variable %d ("%s") must be a reference or a pointer (got %s)'%(sm.decl, self.idx, arg.name, arg.type) + + # Declare a local variable that will receive the output value + self.local_var = sm.wrapper_func.declare_local(arg.name, str(reftype.base)) + # Append the output to the result tuple + sm.wrapper_func.result_exprs.append(self.local_var) + + # Replace the expression in the C++ function call + if isinstance(reftype, declarations.pointer_t): + sm.wrapper_func.input_params[self.idx-1] = "&%s"%self.local_var + else: + sm.wrapper_func.input_params[self.idx-1] = self.local_var + + + def virtual_post_call(self, sm): + """Extract the C++ value after the call to the Python function. + """ + arg = sm.virtual_func.arg_list[self.idx-1] + res = "// Extract the C++ value for output argument '%s' (index: %d)\n"%(arg.name, self.idx) + if isinstance(arg.type, declarations.pointer_t): + res += "*" + res += "%s = boost::python::extract<%s>(%s);"%(arg.name, arg.type.base, sm.py_result_expr(self.local_var)) + return res + + +# input_t +class input_t: + """Handles a single input variable. + + The reference on the specified variable is removed. + + void setValue(int& v) -> setValue(v) + """ + + def __init__(self, idx): + """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 + """ + self.idx = idx + + def __str__(self): + return "Input(%d)"%(self.idx) + + def init_funcs(self, sm): + # Remove the specified input argument from the wrapper function + arg = sm.remove_arg(self.idx) + + # Do some checks (the arg has to be a reference or a pointer) + reftype = arg.type + if not (isinstance(reftype, declarations.reference_t) or + isinstance(reftype, declarations.pointer_t)): + raise ValueError, '%s\nInput variable %d ("%s") must be a reference or a pointer (got %s)'%(sm.decl, self.idx, arg.name, arg.type) + + # Create an equivalent argument that is not a reference type + noref_arg = declarations.argument_t(name=arg.name, type=arg.type.base, default_value=arg.default_value) + # Insert the noref argument + sm.insert_arg(self.idx, noref_arg, arg.name) + +# inout_t +class inout_t: + """Handles a single input/output variable. + + void foo(int& v) -> v = foo(v) + """ + + def __init__(self, idx): + """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 + """ + self.idx = idx + self.local_var = "<not initialized>" + + def __str__(self): + return "InOut(%d)"%(self.idx) + + def init_funcs(self, sm): + # Remove the specified input argument from the wrapper function + arg = sm.remove_arg(self.idx) + + # Do some checks (the arg has to be a reference or a pointer) + reftype = arg.type + if not (isinstance(reftype, declarations.reference_t) or + isinstance(reftype, declarations.pointer_t)): + raise ValueError, '%s\nInOut variable %d ("%s") must be a reference or a pointer (got %s)'%(sm.decl, self.idx, arg.name, arg.type) + + # Create an equivalent argument that is not a reference type + noref_arg = declarations.argument_t(name=arg.name, type=arg.type.base, default_value=arg.default_value) + # Insert the noref argument + sm.insert_arg(self.idx, 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 + if isinstance(reftype, declarations.pointer_t): + sm.wrapper_func.input_params[self.idx-1] = "&%s"%self.local_var + else: + sm.wrapper_func.input_params[self.idx-1] = self.local_var + + + def virtual_post_call(self, sm): + """Extract the C++ value after the call to the Python function. + """ + arg = sm.virtual_func.arg_list[self.idx-1] + res = "// Extract the C++ value for in/out argument '%s' (index: %d)\n"%(arg.name, self.idx) + if isinstance(arg.type, declarations.pointer_t): + res += "*" + res += "%s = boost::python::extract<%s>(%s);"%(arg.name, arg.type.base, sm.py_result_expr(self.local_var)) + return res + + + +# input_array_t +class input_array_t: + """Handles an input array with fixed size. + + void setVec3(double* v) -> setVec3(object v) + # v must be a sequence of 3 floats + + + TODO: Error handling (in the wrapper function)! + + """ + + def __init__(self, idx, size): + """Constructor. + + @param idx: Index of the argument that is an input array (the first arg has index 1). + @type idx: int + @param size: The fixed size of the input array + @type size: int + """ + self.idx = idx + self.size = size + + self.argname = None + self.basetype = None + self.carray = None + self.wrapper_ivar = None + self.virtual_ivar = None + self.pylist = None + + def __str__(self): + return "InputArray(%d,%d)"%(self.idx, self.size) + + def init_funcs(self, sm): + + # Remove the original argument... + arg = sm.remove_arg(self.idx) + + if not (isinstance(arg.type, declarations.pointer_t) or + isinstance(arg.type, declarations.array_t)): + raise ValueError, "%s\nArgument %d (%s) must be a pointer."%(sm.decl, self.idx, arg.name) + + # 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_local("py_"+arg.name, "boost::python::list") + + # Replace the removed argument with a Python object. + newarg = declarations.argument_t(arg.name, declarations.dummy_type_t("boost::python::object")) + sm.insert_arg(self.idx, newarg, self.pylist) + + self.argname = arg.name + self.basetype = str(arg.type.base).replace("const", "").strip() + + # Declare a variable that will hold the C array... + self.carray = sm.wrapper_func.declare_local("c_"+arg.name, self.basetype, size=self.size) + # and an int which is used for the loop + self.wrapper_ivar = sm.wrapper_func.declare_local("i", "int", default=0) + # and another one in the virtual function + self.virtual_ivar = sm.virtual_func.declare_local("i", "int", default=0) + + # Replace the input parameter with the C array + sm.wrapper_func.input_params[self.idx-1] = self.carray + + # Request the convenience header + sm.wrapper_func.require_header(code_repository.convenience.file_name) + + def wrapper_pre_call(self, sm): + """Wrapper function code. + """ + tmpl = [] + tmpl.append( 'pyplusplus::convenience::ensure_uniform_sequence< %(type)s >( %(argname)s, %(size)d );' ) + tmpl.append( 'for(%(ivar)s=0; %(ivar)s<%(size)d; ++%(ivar)s){' ) + tmpl.append( ' %(array_name)s[ %(ivar)s ] = boost::python::extract< %(type)s >( %(argname)s[%(ivar)s] );' ) + tmpl.append( '}' ) + return os.linesep.join( tmpl ) % { + 'type' : self.basetype + , 'argname' : self.argname + , 'size' : self.size + , 'ivar' : self.wrapper_ivar + , 'array_name' : self.carray + } + + def virtual_pre_call(self, sm): + """Virtual function code. + """ + res = "" + res += "// Copy the array '%s' into list '%s'...\n"%(self.argname, self.pylist) + res += "for(%s=0; %s<%d; %s++)\n"%(self.virtual_ivar, self.virtual_ivar, self.size, self.virtual_ivar) + res += " %s.append(%s[%s]);"%(self.pylist, self.argname, self.virtual_ivar) + return res + + +# output_array_t +class output_array_t: + """Handles an output array of a fixed size. + + void getVec3(double* v) -> v = getVec3() + # v will be a list with 3 floats + + TODO: Error handling (in the virtual function)! + + """ + + def __init__(self, idx, 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 + """ + + self.idx = idx + self.size = size + + self.argname = None + self.basetype = None + self.pyval = None + self.cval = None + self.ivar = None + + def __str__(self): + return "OutputArray(%d,%d)"%(self.idx, self.size) + + def init_funcs(self, sm): + # Remove the original argument... + arg = sm.remove_arg(self.idx) + + if not (isinstance(arg.type, declarations.pointer_t) or + isinstance(arg.type, declarations.array_t)): + raise ValueError, "%s\nArgument %d (%s) must be a pointer."%(sm.decl, self.idx, arg.name) + + self.argname = arg.name + self.basetype = str(arg.type.base).replace("const", "").strip() + + # Wrapper: + + # Declare a variable that will hold the C array... + self.wrapper_cval = sm.wrapper_func.declare_local("c_"+self.argname, self.basetype, size=self.size) + # Declare a Python list which will receive the output... + self.wrapper_pyval = sm.wrapper_func.declare_local(self.argname, "boost::python::list") + # ...and add it to the result + sm.wrapper_func.result_exprs.append(arg.name) + + # Declare an int which is used for the loop + self.wrapper_ivar = sm.wrapper_func.declare_local("i", "int", default=0) + + sm.wrapper_func.input_params[self.idx-1] = self.wrapper_cval + + # Virtual: + + # Declare a variable that will receive the Python list + self.virtual_pyval = sm.virtual_func.declare_local("py_"+self.argname, "boost::python::object") + + # Declare an int which is used for the loop + self.virtual_ivar = sm.virtual_func.declare_local("i", "int", default=0) + + # Request the convenience header + sm.virtual_func.require_header(code_repository.convenience.file_name) + + + def wrapper_post_call(self, sm): + res = "" + res += "// Copy the sequence '%s' into '%s'...\n"%(self.wrapper_cval, self.wrapper_pyval) + res += "for(%s=0; %s<%d; %s++)\n"%(self.wrapper_ivar, self.wrapper_ivar, self.size, self.wrapper_ivar) + res += " %s.append(%s[%s]);"%(self.wrapper_pyval, self.wrapper_cval , self.wrapper_ivar) + return res + + def virtual_post_call(self, sm): + tmpl = [] + tmpl.append( 'pyplusplus::convenience::ensure_uniform_sequence< %(type)s >( %(argname)s, %(size)d );' ) + tmpl.append( 'for(%(ivar)s=0; %(ivar)s<%(size)d; ++%(ivar)s){' ) + tmpl.append( ' %(array_name)s[ %(ivar)s ] = boost::python::extract< %(type)s >( %(argname)s[%(ivar)s] );' ) + tmpl.append( '}' ) + return os.linesep.join( tmpl ) % { + 'type' : self.basetype + , 'argname' : sm.py_result_expr(self.argname) + , 'size' : self.size + , 'ivar' : self.virtual_ivar + , 'array_name' : self.argname + } Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2006-10-24 12:10:40 UTC (rev 682) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2006-10-24 19:10:52 UTC (rev 683) @@ -7,7 +7,7 @@ import sys import unittest import fundamental_tester_base -from pyplusplus.function_transformers.arg_policies import * +from pyplusplus.function_transformers.transformers import * from pyplusplus.decl_wrappers import * class tester_t(fundamental_tester_base.fundamental_tester_base_t): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mb...@us...> - 2006-10-24 12:10:43
|
Revision: 682 http://svn.sourceforge.net/pygccxml/?rev=682&view=rev Author: mbaas Date: 2006-10-24 05:10:40 -0700 (Tue, 24 Oct 2006) Log Message: ----------- Reading XML files directly now also makes use of the cache. Modified Paths: -------------- pygccxml_dev/pygccxml/parser/source_reader.py Modified: pygccxml_dev/pygccxml/parser/source_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/source_reader.py 2006-10-23 07:49:03 UTC (rev 681) +++ pygccxml_dev/pygccxml/parser/source_reader.py 2006-10-24 12:10:40 UTC (rev 682) @@ -255,9 +255,18 @@ @return: declarations tree """ + assert(self.__config!=None) + + ffname = self.__file_full_name(gccxml_created_file) self.logger.debug( "Reading xml file: [%s]" % gccxml_created_file ) + declarations = self.__dcache.cached_value( ffname, self.__config ) + if not declarations: + self.logger.debug( "File has not been found in cache, parsing..." ) + declarations, files = self.__parse_gccxml_created_file( ffname ) + self.__dcache.update( ffname, self.__config, declarations, [] ) + else: + self.logger.debug( "File has not been changed, reading declarations from cache." ) - declarations, files = self.__parse_gccxml_created_file( gccxml_created_file ) return declarations def read_string(self, content): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mb...@us...> - 2006-10-23 07:49:09
|
Revision: 681 http://svn.sourceforge.net/pygccxml/?rev=681&view=rev Author: mbaas Date: 2006-10-23 00:49:03 -0700 (Mon, 23 Oct 2006) Log Message: ----------- Committed the last couple of changes (handling pathes with blanks, eol-style, allowing the tokenizer to keep preprocessor directives). Modified Paths: -------------- pyplusplus_dev/contrib/arrayinfo/arrayinfo.py pyplusplus_dev/contrib/arrayinfo/cpptokenize.py pyplusplus_dev/contrib/arrayinfo/createarrayinfo.py Modified: pyplusplus_dev/contrib/arrayinfo/arrayinfo.py =================================================================== --- pyplusplus_dev/contrib/arrayinfo/arrayinfo.py 2006-10-23 07:38:41 UTC (rev 680) +++ pyplusplus_dev/contrib/arrayinfo/arrayinfo.py 2006-10-23 07:49:03 UTC (rev 681) @@ -1,71 +1,73 @@ -###################################################################### -# Array info -# -# Author: Matthias Baas (ba...@ir...) -###################################################################### - -# ArrayInfo -class ArrayInfo: - """Reads the information that was created by createarrayinfo.py. - - Usage: - - Create an instance of this class and either provide the file - name in the constructor or call read() manually. After the info - file has been read you can call arraySize() to retrieve the - size of a particular argument. - """ - - def __init__(self, datfile=None): - """Constructor. - - datfile is the name of the file that contains the array size - information (as created by the createarrayinfo.py utility). - If a name is provided is already read in (so there's no need - to manually call read() anymore). - """ - - # Key: (filename, firstline, funcname) - self.funcargs = {} - - if datfile!=None: - self.read(datfile) - - # read - def read(self, datfile): - """Read an info file. - """ - - n = 0 - for s in file(datfile, "rt"): - a = s.split(";") - filename, firstline, lastline, classname, funcname, args = a - firstline = int(firstline) - lastline = int(lastline) - args = eval(args) - key = (filename, lastline, funcname) - self.funcargs[key] = args - n += 1 - print n,"entries read from",datfile - - # arraySize - def arraySize(self, decl, idx): - """Return the array size of an argument. - - decl is the pygccxml calldef declaration whose argument list - should be inspected. idx is the index of the argument (0-based). - The return value is None if the argument is no array or the - array size is not known, otherwise the size of the array is - returned. - """ - filename = decl.location.file_name - line = decl.location.line - funcname = decl.name - args = self.funcargs.get((filename, line, funcname)) - if args==None: - return None - if idx>=len(args): - return None - else: - return args[idx] - +###################################################################### +# Array info +# +# Author: Matthias Baas (ba...@ir...) +###################################################################### + +import os.path + +# ArrayInfo +class ArrayInfo: + """Reads the information that was created by createarrayinfo.py. + + Usage: + + Create an instance of this class and either provide the file + name in the constructor or call read() manually. After the info + file has been read you can call arraySize() to retrieve the + size of a particular argument. + """ + + def __init__(self, datfile=None): + """Constructor. + + datfile is the name of the file that contains the array size + information (as created by the createarrayinfo.py utility). + If a name is provided is already read in (so there's no need + to manually call read() anymore). + """ + + # Key: (filename, firstline, funcname) + self.funcargs = {} + + if datfile!=None: + self.read(datfile) + + # read + def read(self, datfile): + """Read an info file. + """ + + n = 0 + for s in file(datfile, "rt"): + a = s.split(";") + filename, firstline, lastline, classname, funcname, args = a + firstline = int(firstline) + lastline = int(lastline) + args = eval(args) + key = (filename, lastline, funcname) + self.funcargs[key] = args + n += 1 + print n,"entries read from",datfile + + # arraySize + def arraySize(self, decl, idx): + """Return the array size of an argument. + + decl is the pygccxml calldef declaration whose argument list + should be inspected. idx is the index of the argument (0-based). + The return value is None if the argument is no array or the + array size is not known, otherwise the size of the array is + returned. + """ + filename = os.path.normpath(decl.location.file_name) + line = decl.location.line + funcname = decl.name + args = self.funcargs.get((filename, line, funcname)) + if args==None: + return None + if idx>=len(args): + return None + else: + return args[idx] + Modified: pyplusplus_dev/contrib/arrayinfo/cpptokenize.py =================================================================== --- pyplusplus_dev/contrib/arrayinfo/cpptokenize.py 2006-10-23 07:38:41 UTC (rev 680) +++ pyplusplus_dev/contrib/arrayinfo/cpptokenize.py 2006-10-23 07:49:03 UTC (rev 681) @@ -1,119 +1,127 @@ -########################################################################### -# C/C++ tokenizer -# Copyright (C) 2006 Matthias Baas (ba...@ir...) -########################################################################### - -"""C/C++ tokenizer module. - -This module provides the function tokenize() that just works like the -equivalent Python function with the only difference that it scans -C/C++ source code. -""" - -import re - -WHITESPACE = 0 -NAME = 1 -NUMBER = 2 -STRING = 3 -NEWLINE = 4 -OPERATOR = 5 -CHARACTER = 6 - -# tokenize -def tokenize(readline, tokeater): - """Reads a C/C++ input stream and creates tokens. - - The first parameter, readline, must be a callable object which - provides the same interface as the readline() method of built-in - file objects. Each call to the function should return one line of - input as a string. - - The second parameter, tokeneater, must also be a callable object. - It is called with six parameters: the token type, the token - string, a tuple (srow, scol) specifying the row and column where - the token begins in the source, a tuple (erow, ecol) giving the - ending position of the token, the line on which the token was - found and the filename of the current file. - - By default the filename argument is an empty string. It will only - be the actual filename if you provide a preprocessed file stream - as input (so you should first run cpp on any source code). The - tokenizer actually expects preprocessed data as it doesn't handle - comments. - """ - - regs = ( (WHITESPACE, re.compile(r"[ \t]+")), - (NAME, re.compile(r"[A-Za-z_][A-Za-z_0-9]*")), - (NUMBER, re.compile(r"[0-9]+(\.[0-9]+)?(E(\+|-)?[0-9]+)?")), - (STRING, re.compile(r"\"[^\"]*\"|'[^\']*\'")), - (OPERATOR, re.compile(r"->|::|\+\+|--|->\*|\.\*|<<|>>|<=|>=|==|!=|&&|\|\||\+=|-=|\*=|/=|%=|&=|\^=|\|=|<<=|>>=|\(|\)|\[|\]|\.|\+|-|!|~|\*|/|&|\^|%|<|>|\?|:|=")), - (NEWLINE, re.compile(r"\n")) - ) - - linenr = 0 - filename = "" - while 1: - # Read next line - line = readline() - # No more lines? then finish - if line=="": - break - - linenr+=1 - # Base for starting column... - scolbase = 0 - - # Process preprocessor lines... - if line[0]=="#": - try: - f = line.strip().split(" ") - linenr = int(f[1])-1 - filename = f[2][1:-1] - except: - pass - continue - - s = line - - # Create tokens... - while s!="": - unmatched=1 - # Check all regular expressions... - for r in regs: - m=r[1].match(s) - # Does it match? then the token is found - if m!=None: - scol = m.start() - ecol = m.end() - tok = s[scol:ecol] - s = s[ecol:] - typ = r[0] - tokeater(typ, tok, (linenr, scolbase+scol), (linenr, scolbase+ecol), line, filename) - scolbase += ecol - unmatched=0 - continue - - # No match? then report a single character... - if unmatched: - tok = s[0] - tokeater(CHARACTER, tok, (linenr, scolbase), (linenr, scolbase+1), line, filename) - s = s[1:] - scolbase += 1 - - -def _tokeater(type, s, start, end, line, filename): - """Test token eater.""" - if type==WHITESPACE or type==NEWLINE: - return - type_str = ["WHITESPACE", "NAME", "NUMBER", "STRING", "NEWLINE", "OPERATOR", "CHARACTER"] - - print "Token: %-11s %-20s %s %s %s"%(type_str[type],s, start,end,filename) - -###################################################################### - -if __name__=="__main__": - - f=open("header.h") - tokenize(f.readline, _tokeater) - \ No newline at end of file +########################################################################### +# C/C++ tokenizer +# Copyright (C) 2006 Matthias Baas (ba...@ir...) +########################################################################### + +"""C/C++ tokenizer module. + +This module provides the function tokenize() that just works like the +equivalent Python function with the only difference that it scans +C/C++ source code. +""" + +import re, os.path + +WHITESPACE = 0 +NAME = 1 +NUMBER = 2 +STRING = 3 +NEWLINE = 4 +OPERATOR = 5 +CHARACTER = 6 + +# tokenize +def tokenize(readline, tokeater, preprocessed=True): + """Reads a C/C++ input stream and creates tokens. + + The first parameter, readline, must be a callable object which + provides the same interface as the readline() method of built-in + file objects. Each call to the function should return one line of + input as a string. + + The second parameter, tokeneater, must also be a callable object. + It is called with six parameters: the token type, the token + string, a tuple (srow, scol) specifying the row and column where + the token begins in the source, a tuple (erow, ecol) giving the + ending position of the token, the line on which the token was + found and the filename of the current file. + + By default the filename argument is an empty string. It will only + be the actual filename if you provide a preprocessed file stream + as input (so you should first run cpp on any source code). The + tokenizer actually expects preprocessed data as it doesn't handle + comments. If preprocessed is False, any preprocessor directive is + also considered to be a token. + """ + + regs = ( (WHITESPACE, re.compile(r"[ \t]+")), + (NAME, re.compile(r"[A-Za-z_][A-Za-z_0-9]*")), + (NUMBER, re.compile(r"[0-9]+(\.[0-9]+)?(E(\+|-)?[0-9]+)?")), + (STRING, re.compile(r"\"[^\"]*\"|'[^\']*\'")), + (OPERATOR, re.compile(r"->|::|\+\+|--|->\*|\.\*|<<|>>|<=|>=|==|!=|&&|\|\||\+=|-=|\*=|/=|%=|&=|\^=|\|=|<<=|>>=|\(|\)|\[|\]|\.|\+|-|!|~|\*|/|&|\^|%|<|>|\?|:|=")), + (NEWLINE, re.compile(r"\n")) + ) + + refilename = re.compile(r'\"[^\"]*\"') + + linenr = 0 + filename = "" + while 1: + # Read next line + line = readline() + # No more lines? then finish + if line=="": + break + + linenr+=1 + # Base for starting column... + scolbase = 0 + + # Process preprocessor lines... + if preprocessed and line[0]=="#": + try: + line0 = line.strip() + f = line0.split(" ") + linenr = int(f[1])-1 + m = refilename.search(line0) + if m==None: + filename = os.path.normpath(f[2][1:-1]) + else: + filename = line0[m.start()+1:m.end()-1] + except: + pass + continue + + s = line + + # Create tokens... + while s!="": + unmatched=1 + # Check all regular expressions... + for r in regs: + m=r[1].match(s) + # Does it match? then the token is found + if m!=None: + scol = m.start() + ecol = m.end() + tok = s[scol:ecol] + s = s[ecol:] + typ = r[0] + tokeater(typ, tok, (linenr, scolbase+scol), (linenr, scolbase+ecol), line, filename) + scolbase += ecol + unmatched=0 + continue + + # No match? then report a single character... + if unmatched: + tok = s[0] + tokeater(CHARACTER, tok, (linenr, scolbase), (linenr, scolbase+1), line, filename) + s = s[1:] + scolbase += 1 + + +def _tokeater(type, s, start, end, line, filename): + """Test token eater.""" + if type==WHITESPACE or type==NEWLINE: + return + type_str = ["WHITESPACE", "NAME", "NUMBER", "STRING", "NEWLINE", "OPERATOR", "CHARACTER"] + + print "Token: %-11s %-20s %s %s %s"%(type_str[type],s, start,end,filename) + +###################################################################### + +if __name__=="__main__": + + f=open("header.h") + tokenize(f.readline, _tokeater) + Modified: pyplusplus_dev/contrib/arrayinfo/createarrayinfo.py =================================================================== --- pyplusplus_dev/contrib/arrayinfo/createarrayinfo.py 2006-10-23 07:38:41 UTC (rev 680) +++ pyplusplus_dev/contrib/arrayinfo/createarrayinfo.py 2006-10-23 07:49:03 UTC (rev 681) @@ -1,169 +1,169 @@ -#!/usr/bin/env python -###################################################################### -# This tool parses header files inside a directory and stores info -# about the array size of function arguments into a file for later -# retrieval. -# -# usage: createarrayinfo.py [options] <headerpath> -# -# options: -# -h, --help show this help message and exit -# -o FILENAME, --output=FILENAME -# Output file name (default: stdout) -# -a ARGSTRING, --cppargs=ARGSTRING -# Additional C preproceesor arguments -# -# Author: Matthias Baas (ba...@ir...) -###################################################################### - -import sys, os, os.path, glob, optparse -from cpptokenize import * - -# Parser -class Parser: - """Parser class. - - This class contains the token eater method that processes the tokens - generated by cpptokenize. - Whenever a function signature is parsed a line is written to the output. - """ - - def __init__(self, headerpath, output=sys.stdout): - """Constructor. - """ - - self.headerpath = os.path.normpath(headerpath) - self.output = output - - # Buffer for the last NAME token (which might be a function name) - self.lastname = None - # The current state - self.state = "Outside" - - self.classname = None - self.funcname = None - self.args = None - self.arraysize = None - self.no_arg = False - self.firstline = None - - def tokeater(self, type, s, start, end, line, filename): - """Token eater.""" - if type==WHITESPACE or type==NEWLINE: - return - - method = getattr(self, "state%s"%self.state) - method(type, s, start, end, line, filename) - - # The state methods. They are called by the token eater and must take - # the same arguments than the token eater. - - def stateOutside(self, type, s, start, end, line, filename): - if type==NAME and s=="class": - self.state = "ClassName" - if type==NAME: - self.firstline = start[0] - self.lastname = s - elif self.lastname=="operator": - self.lastname += s - elif type==OPERATOR and s=="(": - self.funcname = self.lastname - self.args = [] - self.arraysize = None - self.no_arg = True - self.state = "Args" - - def stateClassName(self, type, s, start, end, line, filename): - if s.upper()==s: - return - self.classname = s - self.state = "Outside" - - def stateArgs(self, type, s, start, end, line, filename): - if s==")": - if not self.no_arg: - self.args.append(self.arraysize) - self.state = "End" - elif s==",": - self.args.append(self.arraysize) - self.arraysize = None - elif s=="[": - self.state = "ArgsSize" - self.no_arg = False - - def stateArgsSize(self, type, s, start, end, line, filename): - if s=="]": - self.state = "Args" - else: - self.arraysize = int(s) - self.state = "Args" - - def stateEnd(self, type, s, start, end, line, filename): - if s==";": - if os.path.normpath(os.path.dirname(filename))==self.headerpath: - self.onFuncComplete(self.classname, self.funcname, self.args, self.firstline, end[0], filename) - self.state = "Outside" - - - def onFuncComplete(self, classname, funcname, args, firstline, lastline, filename): - """Callback that is called when one function is completely processed. - """ - print >>self.output, "%s;%d;%d;%s;%s;%s"%(filename, firstline, lastline, classname, funcname, args) - - -# parseHeader -def parseHeader(filename, cpp="cpp", cppargs="", output=sys.stdout): - """Parse a header file. - - filename is the header file name and cppargs is a string with - additional arguments for the invocation of the preprocessor 'cpp'. - output is the output stream. - """ - # Run the file through the preprocessor... - filename = os.path.abspath(filename) - print >>sys.stderr, "Parsing",filename - cmd = "%s %s %s >_tmp.h"%(cpp, cppargs, filename) - print >>sys.stderr, cmd - os.system(cmd) - - # Parse the preprocessed file... - parser = Parser(os.path.dirname(filename), output) - tokenize(file("_tmp.h").readline, parser.tokeater) - -###################################################################### - -# Preprocessor -cpp = "cpp" -# Preprocessor arguments -cppargs = "" -# Output stream -output = sys.stdout - -usage = "usage: %prog [options] <headerpath>" -op = optparse.OptionParser(usage) -op.add_option("-o", "--output", metavar="FILENAME", - help="Output file name") -op.add_option("-a", "--cppargs", metavar="ARGSTRING", default="", - help="Additional C preproceesor arguments") - -options, args = op.parse_args() - -if len(args)==0: - op.print_help() - sys.exit(1) - -if options.output!=None: - print >>sys.stderr, "Output file: %s"%options.output - output = file(options.output, "wt") - -headerpath = args[0] -headernames = os.path.join(headerpath, "*.h") -print >>sys.stderr, "Input files: %s"%headernames - -cppargs = options.cppargs -print >>sys.stderr, "Preprocessor args: %s"%cppargs - -headers = glob.glob(headernames) -print >>sys.stderr, "%d header files found"%len(headers) -for header in headers: - parseHeader(header, cpp, cppargs, output) \ No newline at end of file +#!/usr/bin/env python +###################################################################### +# This tool parses header files inside a directory and stores info +# about the array size of function arguments into a file for later +# retrieval. +# +# usage: createarrayinfo.py [options] <headerpath> +# +# options: +# -h, --help show this help message and exit +# -o FILENAME, --output=FILENAME +# Output file name (default: stdout) +# -a ARGSTRING, --cppargs=ARGSTRING +# Additional C preproceesor arguments +# +# Author: Matthias Baas (ba...@ir...) +###################################################################### + +import sys, os, os.path, glob, optparse +from cpptokenize import * + +# Parser +class Parser: + """Parser class. + + This class contains the token eater method that processes the tokens + generated by cpptokenize. + Whenever a function signature is parsed a line is written to the output. + """ + + def __init__(self, headerpath, output=sys.stdout): + """Constructor. + """ + + self.headerpath = os.path.normpath(headerpath) + self.output = output + + # Buffer for the last NAME token (which might be a function name) + self.lastname = None + # The current state + self.state = "Outside" + + self.classname = None + self.funcname = None + self.args = None + self.arraysize = None + self.no_arg = False + self.firstline = None + + def tokeater(self, type, s, start, end, line, filename): + """Token eater.""" + if type==WHITESPACE or type==NEWLINE: + return + + method = getattr(self, "state%s"%self.state) + method(type, s, start, end, line, filename) + + # The state methods. They are called by the token eater and must take + # the same arguments than the token eater. + + def stateOutside(self, type, s, start, end, line, filename): + if type==NAME and s=="class": + self.state = "ClassName" + if type==NAME: + self.firstline = start[0] + self.lastname = s + elif self.lastname=="operator": + self.lastname += s + elif type==OPERATOR and s=="(": + self.funcname = self.lastname + self.args = [] + self.arraysize = None + self.no_arg = True + self.state = "Args" + + def stateClassName(self, type, s, start, end, line, filename): + if s.upper()==s: + return + self.classname = s + self.state = "Outside" + + def stateArgs(self, type, s, start, end, line, filename): + if s==")": + if not self.no_arg: + self.args.append(self.arraysize) + self.state = "End" + elif s==",": + self.args.append(self.arraysize) + self.arraysize = None + elif s=="[": + self.state = "ArgsSize" + self.no_arg = False + + def stateArgsSize(self, type, s, start, end, line, filename): + if s=="]": + self.state = "Args" + else: + self.arraysize = int(s) + self.state = "Args" + + def stateEnd(self, type, s, start, end, line, filename): + if s==";": + if os.path.normpath(os.path.dirname(filename))==self.headerpath: + self.onFuncComplete(self.classname, self.funcname, self.args, self.firstline, end[0], filename) + self.state = "Outside" + + + def onFuncComplete(self, classname, funcname, args, firstline, lastline, filename): + """Callback that is called when one function is completely processed. + """ + print >>self.output, "%s;%d;%d;%s;%s;%s"%(filename, firstline, lastline, classname, funcname, args) + + +# parseHeader +def parseHeader(filename, cpp="cpp", cppargs="", output=sys.stdout): + """Parse a header file. + + filename is the header file name and cppargs is a string with + additional arguments for the invocation of the preprocessor 'cpp'. + output is the output stream. + """ + # Run the file through the preprocessor... + filename = os.path.abspath(filename) + print >>sys.stderr, "Parsing",filename + cmd = '%s %s "%s" >_tmp.h'%(cpp, cppargs, filename.replace(" ", "\\ ")) + print >>sys.stderr, cmd + os.system(cmd) + + # Parse the preprocessed file... + parser = Parser(os.path.dirname(filename), output) + tokenize(file("_tmp.h").readline, parser.tokeater) + +###################################################################### + +# Preprocessor +cpp = "cpp" +# Preprocessor arguments +cppargs = "" +# Output stream +output = sys.stdout + +usage = "usage: %prog [options] <headerpath>" +op = optparse.OptionParser(usage) +op.add_option("-o", "--output", metavar="FILENAME", + help="Output file name") +op.add_option("-a", "--cppargs", metavar="ARGSTRING", default="", + help="Additional C preproceesor arguments") + +options, args = op.parse_args() + +if len(args)==0: + op.print_help() + sys.exit(1) + +if options.output!=None: + print >>sys.stderr, "Output file: %s"%options.output + output = file(options.output, "wt") + +headerpath = args[0] +headernames = os.path.join(headerpath, "*.h") +print >>sys.stderr, "Input files: %s"%headernames + +cppargs = options.cppargs +print >>sys.stderr, "Preprocessor args: %s"%cppargs + +headers = glob.glob(headernames) +print >>sys.stderr, "%d header files found"%len(headers) +for header in headers: + parseHeader(header, cpp, cppargs, output) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-23 07:38:48
|
Revision: 680 http://svn.sourceforge.net/pygccxml/?rev=680&view=rev Author: roman_yakovenko Date: 2006-10-23 00:38:41 -0700 (Mon, 23 Oct 2006) Log Message: ----------- adding property_t to package __init__.py file Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-10-22 19:25:39 UTC (rev 679) +++ pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-10-23 07:38:41 UTC (rev 680) @@ -93,6 +93,8 @@ from doc_extractor import doc_extractor_i +from properties import property_t + import python_traits class dwfactory_t( declarations.decl_factory_t ): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mb...@us...> - 2006-10-22 19:25:43
|
Revision: 679 http://svn.sourceforge.net/pygccxml/?rev=679&view=rev Author: mbaas Date: 2006-10-22 12:25:39 -0700 (Sun, 22 Oct 2006) Log Message: ----------- Explicitly test the decl_headers argument against None instead of using it as a bool (this changes the result of the expression for empty lists). Modified Paths: -------------- pyplusplus_dev/pyplusplus/module_creator/creator.py Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-10-19 08:24:18 UTC (rev 678) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-10-22 19:25:39 UTC (rev 679) @@ -416,7 +416,7 @@ @returns: Returns the root of the code creators tree @rtype: L{module_t<code_creators.module_t>} """ - if not decl_headers: + if decl_headers is None: self._create_includes() else: for h in decl_headers: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-19 08:24:26
|
Revision: 678 http://svn.sourceforge.net/pygccxml/?rev=678&view=rev Author: roman_yakovenko Date: 2006-10-19 01:24:18 -0700 (Thu, 19 Oct 2006) Log Message: ----------- adding Py++ code, which shows how to exposes the example Added Paths: ----------- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/generate_code.py Added: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/generate_code.py =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/generate_code.py (rev 0) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/generate_code.py 2006-10-19 08:24:18 UTC (rev 678) @@ -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 ) + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-19 08:23:16
|
Revision: 677 http://svn.sourceforge.net/pygccxml/?rev=677&view=rev Author: roman_yakovenko Date: 2006-10-19 01:23:06 -0700 (Thu, 19 Oct 2006) Log Message: ----------- adding gccxml installer Python script Added Paths: ----------- pygccxml_dev/gccxml_installer/ pygccxml_dev/gccxml_installer/build_setup.py pygccxml_dev/gccxml_installer/config.py pygccxml_dev/gccxml_installer/setup.py Added: pygccxml_dev/gccxml_installer/build_setup.py =================================================================== --- pygccxml_dev/gccxml_installer/build_setup.py (rev 0) +++ pygccxml_dev/gccxml_installer/build_setup.py 2006-10-19 08:23:06 UTC (rev 677) @@ -0,0 +1,43 @@ +import os +import sys + +class settings: + gccxml_cvs_dir = "" + gccxml_bin_dir = "" + destination_dir = "" + gccxml_version = "0.7" + +#Deploy layout: +#root +# / bin +# - gccxml.exe +# - gccxml_cc1plus.exe +# - gccxml_vcupdate.bat +# / doc +# - Copyright.txt +# - gccxml.html +# - gccxml.txt +# / share +# / gccxml + version +# - gccxml_config # contains gccxml compiler +# / Borland +# * contains patches relevant for Borland compiler +# * "as is" copy of directory from cvs layout +# / Vc6 +# / Vc7 +# / Vc71 +# * contains patches relevant for Vc6 compiler +# * Patches created by running vcInstall + vcPatch programs from /VcInstall +# * directory +# /VcInstall +# * I am not sure whether this directory should be installed or not + +def makedirs( path ): + if not os.path.exists( path ): + os.makedirs( path ) + return path + +bin_dir_dest = makedirs( os.path.join( settings.destination_dir, 'bin' ) ) +bin_dir_source = settings.gccxml_bin_dir +if sys.platform + Added: pygccxml_dev/gccxml_installer/config.py =================================================================== --- pygccxml_dev/gccxml_installer/config.py (rev 0) +++ pygccxml_dev/gccxml_installer/config.py 2006-10-19 08:23:06 UTC (rev 677) @@ -0,0 +1,28 @@ +import sys + +#Directory path, in which you want to install GCC-XML. +#If directory does not exist, it will be created +destination_dir = None + +class vc6: + install_dir = None + +class vc7: + install_dir = None + +class vc71: + install_dir = None + +class borland55: + install_dir = None + +class gcc: + install_dir = None + + + +compilers = [] +if 'linux' in sys.platform: + compilers.append( gcc ) +else 'win' in sys.platform: + compilers.extend( [ vc6, vc7, vc71, borland55 ] ) Added: pygccxml_dev/gccxml_installer/setup.py =================================================================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-19 06:53:32
|
Revision: 676 http://svn.sourceforge.net/pygccxml/?rev=676&view=rev Author: roman_yakovenko Date: 2006-10-18 23:53:22 -0700 (Wed, 18 Oct 2006) Log Message: ----------- fixing few spelling errors Modified Paths: -------------- pygccxml_dev/docs/history/history.rest pyplusplus_dev/docs/history/history.rest Modified: pygccxml_dev/docs/history/history.rest =================================================================== --- pygccxml_dev/docs/history/history.rest 2006-10-19 06:52:42 UTC (rev 675) +++ pygccxml_dev/docs/history/history.rest 2006-10-19 06:53:22 UTC (rev 676) @@ -22,12 +22,12 @@ Version 0.8.2 ------------- -1. Few small bug fix and unit tests have been introduced on 64 Bit platform. +1. Few small bug fix and unit tests have been introduced on 64 Bit platforms. Many thanks to Gottfried Ganssauge! He also help me to discover and fix some important bug in ``type_traits.__remove_alias`` function, by introducing small example that reproduced the error. -2. Huge speed improvment has been achieved( x10 ). Allen Bierbaum suggested to +2. Huge speed improvement has been achieved (x10). Allen Bierbaum suggested to save and reuse results of different `pygccxml`_ algorithms: * ``declarations.remove_alias`` @@ -50,7 +50,7 @@ * ``declarations.variable_t.access_type`` property was added. -4. New type traits have been added: +4. New type traits have been added: * ``is_same_function`` Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2006-10-19 06:52:42 UTC (rev 675) +++ pyplusplus_dev/docs/history/history.rest 2006-10-19 06:53:22 UTC (rev 676) @@ -42,29 +42,29 @@ argument ``create_castinig_constructor`` was removed and deprecation warning was introduced. -2. Performance improvments. In some cases you can get x10 performance boost. - Many thanks to Allen Bierbaum! This was achieved by saving and reusing results - of different `pygccxml`_ algorithms and type traits functions. +2. Performance improvements. In some cases you can get x10 performance boost. + Many thanks to Allen Bierbaum! Saving and reusing results of different + `pygccxml`_ algorithms and type traits functions achieved this. -3. Convinience API for registering exception translator was introduced. +3. Convenience API for registering exception translator was introduced. 4. `Py++`_ can generate code that uses ``BOOST_PYTHON_FUNCTION_OVERLOADS`` and ``BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS`` macros. 5. Treatment to previously generated and no more in-use files was added. By default `Py++`_ will delete these files, but of course you can redefine this - behaviour. + behavior. 6. Generated code changes: * ``default_call_policies`` should not be generated any more. * For functions that have ``return_value_policy< return_opaque_pointer >`` - call policy, `Py++`_ will automaticly generate ``BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID`` + call policy, `Py++`_ will automatically generate ``BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID`` macro. Thank you very much for Gottfried Ganssauge for this idea. 7. Support for Boost.Python properties was introduced. `Py++`_ implements small - algorithm, that will automaticly discover properties, base on naming conventions. + algorithm, that will automatically discover properties, base on naming conventions. 8. ``decl_wrappers.class_t`` has new function: ``is_wrapper_needed``. This function explains why `Py++`_ creates class wrapper for exposed class. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-19 06:52:53
|
Revision: 675 http://svn.sourceforge.net/pygccxml/?rev=675&view=rev Author: roman_yakovenko Date: 2006-10-18 23:52:42 -0700 (Wed, 18 Oct 2006) Log Message: ----------- incrementing version numbers Modified Paths: -------------- pygccxml_dev/setup.py pyplusplus_dev/setup.py Modified: pygccxml_dev/setup.py =================================================================== --- pygccxml_dev/setup.py 2006-10-19 06:08:04 UTC (rev 674) +++ pygccxml_dev/setup.py 2006-10-19 06:52:42 UTC (rev 675) @@ -53,7 +53,7 @@ setup( name = "pygccxml", - version = "0.8.2", + version = "0.8.3", description = "GCC-XML generated file reader", author = "Roman Yakovenko", author_email = "rom...@gm...", Modified: pyplusplus_dev/setup.py =================================================================== --- pyplusplus_dev/setup.py 2006-10-19 06:08:04 UTC (rev 674) +++ pyplusplus_dev/setup.py 2006-10-19 06:52:42 UTC (rev 675) @@ -91,7 +91,7 @@ setup( name = "Py++", - version = "0.8.2", + version = "0.8.3", 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...> - 2006-10-19 06:08:11
|
Revision: 674 http://svn.sourceforge.net/pygccxml/?rev=674&view=rev Author: roman_yakovenko Date: 2006-10-18 23:08:04 -0700 (Wed, 18 Oct 2006) Log Message: ----------- porting to windows Modified Paths: -------------- developer_scripts/create_manifests.py Modified: developer_scripts/create_manifests.py =================================================================== --- developer_scripts/create_manifests.py 2006-10-18 21:54:57 UTC (rev 673) +++ developer_scripts/create_manifests.py 2006-10-19 06:08:04 UTC (rev 674) @@ -28,7 +28,7 @@ manifest.write( file_path[ len( self.root ) + 1 : ] + os.linesep ) def __call__( self ): - manifest = file( os.path.join( self.root, 'MANIFEST' ), 'w+' ) + manifest = file( os.path.join( self.root, 'MANIFEST' ), 'w+b' ) self.__proceed_files( self.root, manifest ) for dir_path in folders_iterator( self.root ): dir_name = os.path.split( dir_path )[1] @@ -82,4 +82,4 @@ print 'creating Py++ manifest' pyplusplus_creator_t()() print 'creating Py++ manifest - done' - \ No newline at end of file + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-10-18 21:55:07
|
Revision: 673 http://svn.sourceforge.net/pygccxml/?rev=673&view=rev Author: roman_yakovenko Date: 2006-10-18 14:54:57 -0700 (Wed, 18 Oct 2006) Log Message: ----------- updating documentation Modified Paths: -------------- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/sconstruct pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptrs.rest Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp 2006-10-18 21:23:08 UTC (rev 672) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp 2006-10-18 21:54:57 UTC (rev 673) @@ -82,10 +82,11 @@ .def( "get_value", bp::pure_virtual( &base_i::get_value ) ); //Register implicit conversion between smart pointers. Boost.Python library - //can not discover relationship between classes.This will allow Boost.Python - //to treat right the functions, which expect to get as argument - //smart_ptr_t< base_i > class instance, when smart_ptr_t< derived from base_i > - //class instance is passed. + //can not discover relationship between classes. You have to tell about the + //relationship to it. This will allow Boost.Python to treat right, the + //functions, which expect to get as argument smart_ptr_t< base_i > class + //instance, when smart_ptr_t< derived from base_i > class instance is passed. + // //For more information about implicitly_convertible see the documentation: //http://boost.org/libs/python/doc/v2/implicit.html . bp::implicitly_convertible< smart_ptr_t< base_wrapper_t >, smart_ptr_t< base_i > >(); Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp 2006-10-18 21:23:08 UTC (rev 672) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp 2006-10-18 21:54:57 UTC (rev 673) @@ -68,7 +68,7 @@ //Next function could be exposed, but it could not be called from Python, when -//the argument is instance of derived class. +//the argument is the instance of a derived class. // //This is the explanation David Abrahams gave: // Naturally; there is no instance of smart_ptr_t<base_i> anywhere in the Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/sconstruct =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/sconstruct 2006-10-18 21:23:08 UTC (rev 672) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/sconstruct 2006-10-18 21:54:57 UTC (rev 673) @@ -3,7 +3,8 @@ , 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" ] + , CPPPATH=[ r"/home/roman/boost_cvs" + , r"/usr/include/python2.4" ] , SHLIBPREFIX='' , SHLIBSUFFIX='.so' ) Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h 2006-10-18 21:23:08 UTC (rev 672) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h 2006-10-18 21:54:57 UTC (rev 673) @@ -3,6 +3,7 @@ #include <assert.h> + //The smart_ptr_t class has been created based on Ogre::SharedPtr class //http://www.ogre3d.org/docs/api/html/OgreSharedPtr_8h-source.html @@ -23,7 +24,7 @@ {} //Every custom smart pointer class should have copy constructor and - //assignment operator. Probably you smart pointer class already has this + //assignment operator. Probably your smart pointer class already has this //functionality. smart_ptr_t(const smart_ptr_t& r) @@ -58,7 +59,7 @@ // smart_ptr_t< base > b( smart_ptr_t<derived>() ); // //This functionality is very important for C++ Python bindings. It will allow - //us to register smart pointer conversion: + //you to register smart pointer conversion: // boost::python::implicitly_convertible< smart_ptr_t< derived >, smart_ptr_t< base > >(); template<class Y> smart_ptr_t(const smart_ptr_t<Y>& r) Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptrs.rest =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptrs.rest 2006-10-18 21:23:08 UTC (rev 672) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptrs.rest 2006-10-18 21:54:57 UTC (rev 673) @@ -10,7 +10,28 @@ .. include:: ./definition.rest +Files +----- +* `smart_ptr.h`_ file contains definition of custom smart pointer class. + +* `classes.hpp`_ file contains definition of few classes, which should be exposed + to Python. + +* `bindings.cpp`_ file contains source code that exposes the classes 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. + +.. _`smart_ptr.h` : ./smart_ptr.h.html +.. _`classes.hpp` : ./classes.hpp.html +.. _`bindings.cpp` : ./bindings.cpp.html +.. _`sconstruct` : ./sconstruct.html +.. _`test.py` : ./test.py.html + -------- Download -------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |