]> git.gag.com Git - debian/gnuradio/commitdiff
added void callback to feval family
authoreb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Tue, 24 Oct 2006 21:03:11 +0000 (21:03 +0000)
committereb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Tue, 24 Oct 2006 21:03:11 +0000 (21:03 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3847 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/general/gr_feval.cc
gnuradio-core/src/lib/general/gr_feval.h
gnuradio-core/src/lib/general/gr_feval.i
gnuradio-core/src/python/gnuradio/gr/qa_feval.py

index 532a140187925b2262d5c4670234b60ae98a119c..3617620b57cd49ab7751192c033e1e0a181e0c20 100644 (file)
@@ -50,6 +50,14 @@ gr_feval_ll::eval(long x)
   return 0;
 }
 
+gr_feval::~gr_feval(){}
+
+void
+gr_feval::eval(void)
+{
+  // nop
+}
+
 /*
  * Trivial examples showing C++ (transparently) calling Python
  */
@@ -70,3 +78,9 @@ gr_feval_ll_example(gr_feval_ll *f, long x)
 {
   return f->eval(x);
 }
+
+void
+gr_feval_example(gr_feval *f)
+{
+  f->eval();
+}
index 18bb4007e53626b31187b0ae81f30e6fb620dacf..a2f7020a4441b89f60e2ffe88c75f8fac7a782b8 100644 (file)
@@ -84,12 +84,32 @@ public:
   virtual long eval(long x);
 };
 
+/*!
+ * \brief base class for evaluating a function: void -> void
+ *
+ * This class is designed to be subclassed in Python or C++
+ * and is callable from both places.  It uses SWIG's
+ * "director" feature to implement the magic.
+ * It's slow. Don't use it in a performance critical path.
+ */
+class gr_feval
+{
+public:
+  gr_feval() {}
+  virtual ~gr_feval();
+
+  /*!
+   * \brief override this to define the function
+   */
+  virtual void eval();
+};
+
 /*!
  * \brief trivial examples / test cases showing C++ calling Python code
  */
 double     gr_feval_dd_example(gr_feval_dd *f, double x);
 gr_complex gr_feval_cc_example(gr_feval_cc *f, gr_complex x);
 long       gr_feval_ll_example(gr_feval_ll *f, long x);
-
+void       gr_feval_example(gr_feval *f);
 
 #endif /* INCLUDED_GR_FEVAL_H */
index 586e143d07a252f03657fe9a736968ba63dba569..09d98b6481737adc53f8673943770572966a9fe1 100644 (file)
@@ -24,6 +24,7 @@
 %feature("director") gr_feval_dd;
 %feature("director") gr_feval_cc;
 %feature("director") gr_feval_ll;
+%feature("director") gr_feval;
 
 
 %rename(feval_dd) gr_feval_dd;
@@ -56,6 +57,16 @@ public:
   virtual long eval(long x);
 };
 
+%rename(feval) gr_feval;
+class gr_feval
+{
+public:
+  gr_feval() {}
+  virtual ~gr_feval();
+
+  virtual void eval();
+};
+
 
 // examples / test cases
 
@@ -67,3 +78,6 @@ gr_complex gr_feval_cc_example(gr_feval_cc *f, gr_complex x);
 
 %rename(feval_ll_example) gr_feval_ll_example;
 long gr_feval_ll_example(gr_feval_ll *f, long x);
+
+%rename(feval_example) gr_feval_example;
+void gr_feval_example(gr_feval *f);
index 7afc5ec0eea5b7366fe31e9f24878fb532c2bcf9..f630e09aa71f54eab3909f55da3ab3c24f81aeac 100755 (executable)
@@ -34,6 +34,12 @@ class my_add2_cc(gr.feval_cc):
     def eval(self, x):
         return x + (2 - 2j)
 
+class my_feval(gr.feval):
+    def __init__(self):
+        gr.feval.__init__(self)
+        self.fired = False
+    def eval(self):
+        self.fired = True
 
 class test_feval(gr_unittest.TestCase):
 
@@ -87,6 +93,18 @@ class test_feval(gr_unittest.TestCase):
         actual_result = tuple([gr.feval_cc_example(f, x) for x in src_data])
         self.assertEqual(expected_result, actual_result)
         
+    def test_void_1(self):
+        # this is all in python
+        f = my_feval()
+        f.eval()
+        self.assertEqual(True, f.fired)
+
+    def test_void_2(self):
+        # this is python -> C++ -> python and back again
+        f = my_feval()
+        gr.feval_example(f)
+        self.assertEqual(True, f.fired)
+
 
 if __name__ == '__main__':
     gr_unittest.main ()