From a3e2b9f0a5b35bd11f64cd7b112692c884b69194 Mon Sep 17 00:00:00 2001 From: wolf Date: Tue, 2 Mar 1999 16:32:41 +0000 Subject: [PATCH] Change the do_loop function to use the STL function objects. This has the advantage that we can now pass function objects using bind2nd etc to pass parameters to the functions we want to have called. git-svn-id: https://svn.dealii.org/trunk@939 0785d39b-7218-0410-832d-ea1e28bc413d --- .../deal.II/include/numerics/time_dependent.h | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/deal.II/deal.II/include/numerics/time_dependent.h b/deal.II/deal.II/include/numerics/time_dependent.h index 57abe1febb..26ef5952e4 100644 --- a/deal.II/deal.II/include/numerics/time_dependent.h +++ b/deal.II/deal.II/include/numerics/time_dependent.h @@ -196,14 +196,14 @@ class TimeDependent * To see how this function work, note that * the function #solve_primal_problem# only * consists of a call to - * # do_loop (&TimeStepBase::init_for_primal_problem, - * &TimeStepBase::solve_primal_problem, + * # do_loop (mem_fun(&TimeStepBase::init_for_primal_problem), + * mem_fun(&TimeStepBase::solve_primal_problem), * timestepping_data_primal);#. * * Note also, that the given class from which * the two functions are taken needs not - * necessarily be a #TimeStepBase#, but it - * should be a derived class, that is + * necessarily be #TimeStepBase#, but it + * could also be a derived class, that is * #static_cast#able from a #TimeStepBase#. * The function may be a virtual function * (even a pure one) of that class, which @@ -212,10 +212,21 @@ class TimeDependent * through virtual base classes and thus * unreachable by #static_cast# from the * #TimeStepBase# class. - */ - template - void do_loop (void (TimeStepClass::*init_function) (), - void (TimeStepClass::*loop_function) (), + * + * Instead of using the above form, you can + * equally well use + * #bind2nd(mem_fun1(&X::unary_function), + * arg)# which lets the #do_loop# + * function call teh given function with + * the specified parameter. Note that you + * need to bind the second parameter since + * the first one implicitely contains + * the object which the function is to + * be called for. + */ + template + void do_loop (InitFunctionObject init_function, + LoopFunctionObject loop_function, const TimeSteppingData ×tepping_data); @@ -276,7 +287,7 @@ class TimeDependent * do. See the documentation of this struct * for more information. */ - TimeSteppingData timestepping_data_primal; + const TimeSteppingData timestepping_data_primal; /** * Some flags telling the @@ -284,7 +295,7 @@ class TimeDependent * do. See the documentation of this struct * for more information. */ - TimeSteppingData timestepping_data_dual; + const TimeSteppingData timestepping_data_dual; /** * Some flags telling the @@ -292,16 +303,16 @@ class TimeDependent * do. See the documentation of this struct * for more information. */ - TimeSteppingData timestepping_data_postprocess; + const TimeSteppingData timestepping_data_postprocess; }; -template -void TimeDependent::do_loop (void (TimeStepClass::*init_function) (), - void (TimeStepClass::*loop_function) (), +template +void TimeDependent::do_loop (InitFunctionObject init_function, + LoopFunctionObject loop_function, const TimeSteppingData ×tepping_data) { const unsigned int n_timesteps = timesteps.size(); @@ -309,7 +320,7 @@ void TimeDependent::do_loop (void (TimeStepClass::*init_function) (), // initialize the time steps for // a round of primal problems for (unsigned int step=0; step(timesteps[step])->*init_function) (); + init_function (static_cast(timesteps[step])); // wake up the first few time levels for (int step=-timestepping_data.look_ahead; step<0; ++step) @@ -328,7 +339,7 @@ void TimeDependent::do_loop (void (TimeStepClass::*init_function) (), timesteps[step+look_ahead]->wake_up(look_ahead); // actually do the work - (static_cast(timesteps[step])->*loop_function) (); + loop_function (static_cast(timesteps[step])); // let the timesteps behind sleep for (unsigned int look_back=0; -- 2.39.5