[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r3779 - in gnuradio/branches/developers/eb/power/gnura
From: |
eb |
Subject: |
[Commit-gnuradio] r3779 - in gnuradio/branches/developers/eb/power/gnuradio-core/src: lib/general python/gnuradio/gr |
Date: |
Wed, 11 Oct 2006 19:37:34 -0600 (MDT) |
Author: eb
Date: 2006-10-11 19:37:34 -0600 (Wed, 11 Oct 2006)
New Revision: 3779
Modified:
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.cc
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.h
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.i
gnuradio/branches/developers/eb/power/gnuradio-core/src/python/gnuradio/gr/qa_feval.py
Log:
added void callback to feval family
Modified:
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.cc
===================================================================
---
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.cc
2006-10-12 00:52:33 UTC (rev 3778)
+++
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.cc
2006-10-12 01:37:34 UTC (rev 3779)
@@ -50,6 +50,14 @@
return 0;
}
+gr_feval::~gr_feval(){}
+
+void
+gr_feval::eval(void)
+{
+ // nop
+}
+
/*
* Trivial examples showing C++ (transparently) calling Python
*/
@@ -70,3 +78,9 @@
{
return f->eval(x);
}
+
+void
+gr_feval_example(gr_feval *f)
+{
+ f->eval();
+}
Modified:
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.h
===================================================================
---
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.h
2006-10-12 00:52:33 UTC (rev 3778)
+++
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.h
2006-10-12 01:37:34 UTC (rev 3779)
@@ -85,11 +85,31 @@
};
/*!
+ * \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 */
Modified:
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.i
===================================================================
---
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.i
2006-10-12 00:52:33 UTC (rev 3778)
+++
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_feval.i
2006-10-12 01:37:34 UTC (rev 3779)
@@ -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,7 +57,17 @@
virtual long eval(long x);
};
+%rename(feval) gr_feval;
+class gr_feval
+{
+public:
+ gr_feval() {}
+ virtual ~gr_feval();
+ virtual void eval();
+};
+
+
// examples / test cases
%rename(feval_dd_example) gr_feval_dd_example;
@@ -67,3 +78,6 @@
%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);
Modified:
gnuradio/branches/developers/eb/power/gnuradio-core/src/python/gnuradio/gr/qa_feval.py
===================================================================
---
gnuradio/branches/developers/eb/power/gnuradio-core/src/python/gnuradio/gr/qa_feval.py
2006-10-12 00:52:33 UTC (rev 3778)
+++
gnuradio/branches/developers/eb/power/gnuradio-core/src/python/gnuradio/gr/qa_feval.py
2006-10-12 01:37:34 UTC (rev 3779)
@@ -34,6 +34,12 @@
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 @@
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 ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r3779 - in gnuradio/branches/developers/eb/power/gnuradio-core/src: lib/general python/gnuradio/gr,
eb <=