# HG changeset patch # User Jaroslav Hajek # Date 1278924735 -7200 # Node ID f7584d0ba5d3d2bc491c96743ff0f7e0472bb5b8 # Parent 6e7590d003dc67c38fe704269337679d1ba8150b allow unwind_protect register actions with const T& args diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-07-12 Jaroslav Hajek + + * unwind-prot.h (unwind_protect::fcn_crefarg_elem): New class. + (unwind_protect::add_fcn (void (*) (const T&), T)): New method + overload. + 2010-07-08 David Bateman * DLD-FUNCTIONS/__magick_read__,cc (F__magick_read__): Add the syntax diff --git a/src/unwind-prot.h b/src/unwind-prot.h --- a/src/unwind-prot.h +++ b/src/unwind-prot.h @@ -81,6 +81,23 @@ T e_arg; }; + // An element that stores a variable of type T along with a void (*) (const T&) + // function pointer, and calls the function with the parameter. + + template + class fcn_crefarg_elem : public elem + { + public: + fcn_crefarg_elem (void (*fcn) (const T&), T arg) + : e_fcn (fcn), e_arg (arg) { } + + void run (void) { e_fcn (e_arg); } + + private: + void (*e_fcn) (const T&); + T e_arg; + }; + // An element for calling a member function. template @@ -154,6 +171,13 @@ add (new fcn_arg_elem (action, val)); } + // Call to void func (const T&). + template + void add_fcn (void (*action) (const T&), T val) + { + add (new fcn_crefarg_elem (action, val)); + } + // Call to T::method (void). template void add_method (T *obj, void (T::*method) (void))