[Cppunit-cvs] cppunit2/include/cpptl forwards.h,1.2,1.3 functor.h,1.2,1.3 functor.py,1.2,1.3
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-02-27 14:39:05
|
Update of /cvsroot/cppunit/cppunit2/include/cpptl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11085/include/cpptl Modified Files: forwards.h functor.h functor.py Log Message: * changed cppunit 2 to use the new functors (cpptl/functor.h). bind_cfn & bind_memfn simplified some of the test code. Index: forwards.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/forwards.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** forwards.h 27 Feb 2005 10:14:03 -0000 1.2 --- forwards.h 27 Feb 2005 14:38:25 -0000 1.3 *************** *** 23,26 **** --- 23,28 ---- // functor.h class Functor0; + template<class ReturnType> + class Functor0R; Index: functor.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/functor.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** functor.h 26 Feb 2005 11:40:58 -0000 1.2 --- functor.h 27 Feb 2005 14:38:25 -0000 1.3 *************** *** 1028,1031 **** --- 1028,1054 ---- } + template< class Functor, class Arg1 > + inline Functor0 + bind( Functor functor, Arg1 a1 ) + { + return fn0( bind1( functor, a1 ) ); + } + + template< class Arg1, class FA1 > + inline Functor0 + bind_cfn( void (*function)( FA1 ), Arg1 a1 ) + { + return fn0( bind1( cfn1( function ), a1 ) ); + } + + template< class Holder, class Object, class Arg1, class FA1 > + inline Functor0 + bind_memfn( const Holder &holder, + void (Object::*member)( FA1 ), + Arg1 a1 ) + { + return fn0( bind1( memfn1( holder, member ), a1 ) ); + } + // Functor1R *************** *** 1067,1070 **** --- 1090,1116 ---- } + template< class Functor, class Arg1 > + inline Functor0R<CPPTL_TYPENAME Functor::result_type> + bindr( Functor functor, Arg1 a1 ) + { + return fn0r( bind1r( functor, a1 ) ); + } + + template< class Return, class Arg1, class FA1 > + inline Functor0R<Return> + bind_cfnr( Return (*function)( FA1 ), Arg1 a1 ) + { + return fn0r( bind1r( cfn1r( function ), a1 ) ); + } + + template< class Holder, class Object, class Return, class Arg1, class FA1 > + inline Functor0R<Return> + bind_memfnr( const Holder &holder, + Return (Object::*member)( FA1 ), + Arg1 a1 ) + { + return fn0r( bind1r( memfn1r( holder, member ), a1 ) ); + } + // Functor2 *************** *** 1106,1109 **** --- 1152,1178 ---- } + template< class Functor, class Arg1, class Arg2 > + inline Functor0 + bind( Functor functor, Arg1 a1, Arg2 a2 ) + { + return fn0( bind1( bind2( functor, a2 ), a1 ) ); + } + + template< class Arg1, class Arg2, class FA1, class FA2 > + inline Functor0 + bind_cfn( void (*function)( FA1, FA2 ), Arg1 a1, Arg2 a2 ) + { + return fn0( bind1( bind2( cfn2( function ), a2 ), a1 ) ); + } + + template< class Holder, class Object, class Arg1, class Arg2, class FA1, class FA2 > + inline Functor0 + bind_memfn( const Holder &holder, + void (Object::*member)( FA1, FA2 ), + Arg1 a1, Arg2 a2 ) + { + return fn0( bind1( bind2( memfn2( holder, member ), a2 ), a1 ) ); + } + // Functor2R *************** *** 1149,1152 **** --- 1218,1244 ---- } + template< class Functor, class Arg1, class Arg2 > + inline Functor0R<CPPTL_TYPENAME Functor::result_type> + bindr( Functor functor, Arg1 a1, Arg2 a2 ) + { + return fn0r( bind1r( bind2r( functor, a2 ), a1 ) ); + } + + template< class Return, class Arg1, class Arg2, class FA1, class FA2 > + inline Functor0R<Return> + bind_cfnr( Return (*function)( FA1, FA2 ), Arg1 a1, Arg2 a2 ) + { + return fn0r( bind1r( bind2r( cfn2r( function ), a2 ), a1 ) ); + } + + template< class Holder, class Object, class Return, class Arg1, class Arg2, class FA1, class FA2 > + inline Functor0R<Return> + bind_memfnr( const Holder &holder, + Return (Object::*member)( FA1, FA2 ), + Arg1 a1, Arg2 a2 ) + { + return fn0r( bind1r( bind2r( memfn2r( holder, member ), a2 ), a1 ) ); + } + Index: functor.py =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/functor.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** functor.py 26 Feb 2005 11:40:58 -0000 1.2 --- functor.py 27 Feb 2005 14:38:25 -0000 1.3 *************** *** 349,352 **** --- 349,391 ---- # ,BindArg + multi_bind_generator = \ + """%(multi_bind_template_decl)s + inline %(multi_bind_functor_instantiation)s + %(multi_bind)s( Functor functor, %(fn_parameters)s ) + { + return %(multi_bind_fn)s( %(multi_functor_generation)s ); + } + + %(multi_bind_cfn_template_decl)s + inline %(multi_bind_cfn_instantiation)s + %(multi_bind_cfn)s( %(return_type)s (*function)( %(multi_bind_fn_parameter_types)s ), %(fn_parameters)s ) + { + return %(multi_bind_fn)s( %(multi_cfn_functor_generation)s ); + } + + %(multi_bind_memfn_template_decl)s + inline %(multi_bind_cfn_instantiation)s + %(multi_bind_memfn)s( const Holder &holder, + %(return_type)s (Object::*member)( %(multi_bind_fn_parameter_types)s ), + %(fn_parameters)s ) + { + return %(multi_bind_fn)s( %(multi_memfn_functor_generation)s ); + } + + """ + # multi_bind_template_decl : template<class Functor, class Return, class Arg1> + # multi_bind_functor_instantiation : Functor0R<CPPTL_TYPENAME Functor::result_type> + # multi_bind : bindr + # multi_bind_fn : fn0r + # multi_functor_generation : bind1r( bind2r( functor, a2 ), a1 ) + # multi_bind_cfn_template_decl : template<class Return, class FA1, class FA2, class Arg1, class Arg2> + # multi_bind_cfn_instantiation : Functor0R<Return> + # multi_bind_cfn : bind_cfnr + # multi_bind_fn_parameter_types : Arg1, Arg2 + # multi_cfn_functor_generation : bind1r( bind2r( cfn2r(function), a2 ), a1 ) + # multi_bind_memfn_template_decl : template<class Holder, class Object, class Return, class FA1, class FA2, class Arg1, class Arg2> + # multi_bind_memfn : bind_memfnr + # multi_memfn_functor_generation : bind1r( bind2r( memfn2r(member), a2 ), a1 ) + *************** *** 364,368 **** if not is_void: base_template_parameters.append( 'Return' ) ! base_template_parameters.extend( [ 'Arg%d' % n for n in xrange(1,count+1) ] ) self.base_template_decl = self.makeTemplateDecl( base_template_parameters ) self.impl_base_instantiation = self.impl_base + self.makeTemplateInstantiation( base_template_parameters ) --- 403,408 ---- if not is_void: base_template_parameters.append( 'Return' ) ! args_template_parameters = [ 'Arg%d' % n for n in xrange(1,count+1) ] ! base_template_parameters.extend( args_template_parameters ) self.base_template_decl = self.makeTemplateDecl( base_template_parameters ) self.impl_base_instantiation = self.impl_base + self.makeTemplateInstantiation( base_template_parameters ) *************** *** 410,413 **** --- 450,479 ---- bind_functor_deduced_types = ['Functor'] + functor_deduced_types + ['BindArg'] self.bind_functor_deduced_types = '<' + '\n ,'.join( bind_functor_deduced_types ) + ' >' + self.multi_bind_template_decl = self.makeTemplateDecl( ['Functor'] + args_template_parameters ) + if is_void: + self.multi_bind_functor_instantiation = 'Functor0' + self.multi_bind_cfn_instantiation = self.multi_bind_functor_instantiation + else: + self.multi_bind_functor_instantiation = 'Functor0R<CPPTL_TYPENAME Functor::result_type>' + self.multi_bind_cfn_instantiation = 'Functor0R<Return>' + self.multi_bind = 'bind%s' % return_suffix.lower() + self.multi_bind_fn = 'fn0%s' % return_suffix.lower() + self.multi_functor_generation = self.generateMultiBindFunctor( count, + 'bind%d' + return_suffix.lower(), + 'functor' ) + multi_bind_fn_types = [ 'FA%d' % n for n in xrange(1,count+1) ] + multi_bind_cfn_template_parameters = base_template_parameters + multi_bind_fn_types + self.multi_bind_cfn_template_decl = self.makeTemplateDecl( multi_bind_cfn_template_parameters ) + self.multi_bind_cfn = 'bind_cfn%s' % return_suffix.lower() + self.multi_bind_fn_parameter_types = ', '.join( multi_bind_fn_types ) + self.multi_cfn_functor_generation = self.generateMultiBindFunctor( count, + 'bind%d' + return_suffix.lower(), + self.cfn + '( function )' ) + multi_bind_memfn_template_parameters = ['Holder','Object'] + multi_bind_cfn_template_parameters + self.multi_bind_memfn_template_decl = self.makeTemplateDecl( multi_bind_memfn_template_parameters ) + self.multi_bind_memfn = 'bind_memfn%s' % return_suffix.lower() + self.multi_memfn_functor_generation = self.generateMultiBindFunctor( count, + 'bind%d' + return_suffix.lower(), + self.memfn + '( holder, member )' ) def __getitem__( self, key ): *************** *** 424,428 **** return '< ' + ', '.join( parameters ) + ' >' ! def getFunctorArgTypeName( self, n ): names = [ 'arg%d_type' % n ] if n == 1: --- 490,494 ---- return '< ' + ', '.join( parameters ) + ' >' ! def getFunctorArgTypeNames( self, n ): names = [ 'arg%d_type' % n ] if n == 1: *************** *** 430,443 **** elif n == 2: names.append( 'second_argument_type' ) ! return names[-1] def makeArgumentTypedef( self, n ): ! names = [ 'arg%d_type' % n ] ! if n == 1: ! names.append( 'first_argument_type' ) ! elif n == 2: ! names.append( 'second_argument_type' ) return '\n'.join( [ ' typedef Arg%d %s;' % (n, name) for name in names ] ) + '\n' functors_impl = '' functors = '' --- 496,516 ---- elif n == 2: names.append( 'second_argument_type' ) ! return names ! ! def getFunctorArgTypeName( self, n ): ! return self.getFunctorArgTypeNames(n)[-1] def makeArgumentTypedef( self, n ): ! names = self.getFunctorArgTypeNames(n) return '\n'.join( [ ' typedef Arg%d %s;' % (n, name) for name in names ] ) + '\n' + def generateMultiBindFunctor( self, n, bind_fn, bind_args ): + functor = bind_args + while n > 0: + functor = (bind_fn % n) + '( ' + functor + ', a%d' % n + ' )' + n -= 1 + return functor + + functors_impl = '' functors = '' *************** *** 453,456 **** --- 526,531 ---- functors += functor % parameters functor_generators += generator % parameters + if argument_count > 0: + functor_generators += multi_bind_generator % parameters final_header = header % locals() |