Mercurial > hg > octave-terminal
changeset 10781:f7584d0ba5d3
allow unwind_protect register actions with const T& args
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 12 Jul 2010 10:52:15 +0200 |
parents | 6e7590d003dc |
children | d1f920d1ce0c |
files | src/ChangeLog src/unwind-prot.h |
diffstat | 2 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-07-12 Jaroslav Hajek <highegg@gmail.com> + + * 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 <dbateman@free.fr> * DLD-FUNCTIONS/__magick_read__,cc (F__magick_read__): Add the syntax
--- 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 T> + 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 <class T> @@ -154,6 +171,13 @@ add (new fcn_arg_elem<T> (action, val)); } + // Call to void func (const T&). + template <class T> + void add_fcn (void (*action) (const T&), T val) + { + add (new fcn_crefarg_elem<T> (action, val)); + } + // Call to T::method (void). template <class T> void add_method (T *obj, void (T::*method) (void))