[pygccxml-commit] SF.net SVN: pygccxml:[1450] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-11-22 22:55:26
|
Revision: 1450 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1450&view=rev Author: roman_yakovenko Date: 2008-11-22 21:36:02 +0000 (Sat, 22 Nov 2008) Log Message: ----------- small refactoring, which moves "free operators" target class logic out of creator_t class Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/data/operators_to_be_exported.hpp pyplusplus_dev/unittests/indexing_suites2_tester.py pyplusplus_dev/unittests/operators_tester.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2008-11-01 19:04:11 UTC (rev 1449) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2008-11-22 21:36:02 UTC (rev 1450) @@ -400,9 +400,35 @@ included = filter( lambda decl: decl.ignore == False, oper.class_types ) if not included: return messages.W1052 % str(oper) - return '' + @staticmethod + def target_class( oper ): + """this functions returns reference to class/class declaration + in scope of which, the operator should be exposed.""" + if isinstance( oper.parent, declarations.class_t ): + return oper.parent + #now we deal with free operators + def find_class( type_ ): + type_ = declarations.remove_reference( type_ ) + if declarations.is_class( type_ ): + return declarations.class_traits.get_declaration( type_ ) + elif declarations.is_class_declaration( type_ ): + return declarations.class_declaration_traits.get_declaration( type_ ) + else: + return None + + arg_1_class = find_class( oper.arguments[0].type ) + arg_2_class = None + if 2 == len( oper.arguments ): + arg_2_class = find_class( oper.arguments[1].type ) + + if arg_1_class: + return arg_1_class + else: + return arg_2_class + + class member_operator_t( declarations.member_operator_t, calldef_t ): """defines a set of properties, that will instruct Py++ how to expose the member operator""" def __init__(self, *arguments, **keywords): @@ -446,6 +472,9 @@ return messages.W1015 return operators_helper.exportable( self ) + @property + def target_class( self ): + return self.parent class casting_operator_t( declarations.casting_operator_t, calldef_t ): """defines a set of properties, that will instruct Py++ how to expose the casting operator""" @@ -557,6 +586,22 @@ def __init__(self, *arguments, **keywords): declarations.free_operator_t.__init__( self, *arguments, **keywords ) calldef_t.__init__( self ) + self._target_class = None def _exportable_impl_derived( self ): return operators_helper.exportable( self ) + + def get_target_class( self ): + if self._target_class is None: + self._target_class = operators_helper.target_class( self ) + return self._target_class + + def set_target_class( self, class_ ): + self._target_class = class_ + + _target_class_doc_ = "reference to class_t or class_declaration_t object." \ + + " There are use cases, where Py++ doesn't guess right, in what scope" \ + + " free operator should be registered( exposed ). If this is your use case " \ + + " than setting the class will allow you to quickly fix the situation. " + + target_class = property( get_target_class, set_target_class, doc=_target_class_doc_ ) Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2008-11-01 19:04:11 UTC (rev 1449) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2008-11-22 21:36:02 UTC (rev 1450) @@ -174,7 +174,14 @@ pass else: assert not "Found %d class code creators" % len(creator) + find = code_creators.creator_finder.find_by_declaration + if operator.target_class and operator.target_class.ignore == False: + found = find( lambda decl: operator.target_class is decl + , self.__extmodule.body.creators ) + adopt_operator_impl( operator, found ) + """ + find = code_creators.creator_finder.find_by_declaration if isinstance( operator.parent, declarations.class_t ): found = find( lambda decl: operator.parent is decl , self.__extmodule.body.creators ) @@ -190,7 +197,7 @@ found = find( lambda decl: included[0] is decl, self.__extmodule.body.creators ) adopt_operator_impl( operator, found ) - + """ def _is_registered_smart_pointer_creator( self, creator, db ): for registered in db: if not isinstance( creator, registered.__class__ ): @@ -254,20 +261,20 @@ cls_creator.associated_decl_creators.extend( uc_creators ) def __get_exposed_containers(self): - """list of exposed declarations, which were not ``included``, but still + """list of exposed declarations, which were not ``included``, but still were exposed. For example, std containers - + std containers exposed by Py++, even if the user didn't ``include`` them. """ cmp_by_name = lambda cls1, cls2: cmp( cls1.decl_string, cls2.decl_string ) used_containers = list( self.__types_db.used_containers ) used_containers = filter( lambda cls: cls.indexing_suite.include_files , used_containers ) - used_containers.sort( cmp_by_name ) + used_containers.sort( cmp_by_name ) used_containers = filter( lambda cnt: cnt.already_exposed == False , used_containers ) return used_containers - + def _treat_indexing_suite( self ): def create_explanation(cls): msg = '//WARNING: the next line of code will not compile, because "%s" does not have operator== !' Modified: pyplusplus_dev/unittests/data/operators_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/operators_to_be_exported.hpp 2008-11-01 19:04:11 UTC (rev 1449) +++ pyplusplus_dev/unittests/data/operators_to_be_exported.hpp 2008-11-22 21:36:02 UTC (rev 1450) @@ -8,21 +8,22 @@ #include "boost/rational.hpp" #include <iostream> +#include <vector> namespace pyplusplus{ namespace rational{ typedef boost::rational< long int > pyrational; struct helper{ - + void instantiate(){ sizeof( pyrational ); boost::gcd<long int>( 1, 1); boost::lcm<long int>( 1, 1); - std::cout << pyrational( 1,1); + std::cout << pyrational( 1,1); pyrational x(1,1); x = pyrational( 2, 3 ); - + } }; @@ -36,14 +37,46 @@ //Boost.Python does not support member operator<< struct YYY{ - std::ostream& operator<<(std::ostream& s) const{ + std::ostream& operator<<(std::ostream& s) const{ return s; //return s << "<YYY instance at " << reinterpret_cast<unsigned long>( this )<< ">"; } }; +typedef std::vector< pyrational > rationals_t; +inline rationals_t& +operator+=( rationals_t& v, const pyrational& n ){ + for( rationals_t::iterator i = v.begin(); i != v.end(); ++i ){ + *i += n; + } + return v; +} + +inline rationals_t create_randome_rationals(){ + return rationals_t(); +} + + } } - + +namespace Geometry{ + + namespace PointsUtils{ + struct VecOfInts{}; + //typedef std::vector<int> VecOfInts; + } + + class Class2 { + int i; + }; + + extern PointsUtils::VecOfInts& + operator += ( PointsUtils::VecOfInts &vec, const Class2&){ + return vec; + } +} + + #endif//__operators_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/indexing_suites2_tester.py =================================================================== --- pyplusplus_dev/unittests/indexing_suites2_tester.py 2008-11-01 19:04:11 UTC (rev 1449) +++ pyplusplus_dev/unittests/indexing_suites2_tester.py 2008-11-22 21:36:02 UTC (rev 1450) @@ -25,6 +25,11 @@ items = generator.global_ns.typedef( 'items_t' ) items = declarations.remove_declarated( items.type ) items.alias = "items_t" + + strings = generator.global_ns.typedef( 'strings_t' ) + strings = declarations.remove_declarated( strings.type ) + strings.include() + fvector = generator.global_ns.typedef( 'fvector' ) fvector = declarations.remove_declarated( fvector.type ) fvector.indexing_suite.disable_method( 'extend' ) Modified: pyplusplus_dev/unittests/operators_tester.py =================================================================== --- pyplusplus_dev/unittests/operators_tester.py 2008-11-01 19:04:11 UTC (rev 1449) +++ pyplusplus_dev/unittests/operators_tester.py 2008-11-22 21:36:02 UTC (rev 1450) @@ -22,6 +22,8 @@ def customize( self, mb ): mb.global_ns.exclude() + mb.free_function( 'create_randome_rationals' ).include() + xxx = mb.class_( 'XXX' ) xxx.include() xxx_ref = declarations.reference_t( declarations.const_t( declarations.declarated_t( xxx ) ) ) @@ -61,6 +63,8 @@ bad_rational = mb.class_('bad_rational' ) bad_rational.include() + mb.namespace( 'Geometry' ).include() + mb.namespace( 'Geometry' ).class_( 'VecOfInts' ).exclude() def run_tests(self, module): pyrational = module.pyrational This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |