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	Fri Jul 09 19:56:21 2010 +0200
+++ b/src/ChangeLog	Mon Jul 12 10:52:15 2010 +0200
@@ -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	Fri Jul 09 19:56:21 2010 +0200
+++ b/src/unwind-prot.h	Mon Jul 12 10:52:15 2010 +0200
@@ -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))