diff options
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_feval.cc | 14 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_feval.h | 22 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_feval.i | 14 |
3 files changed, 49 insertions, 1 deletions
diff --git a/gnuradio-core/src/lib/general/gr_feval.cc b/gnuradio-core/src/lib/general/gr_feval.cc index 532a14018..3617620b5 100644 --- a/gnuradio-core/src/lib/general/gr_feval.cc +++ b/gnuradio-core/src/lib/general/gr_feval.cc @@ -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(); +} diff --git a/gnuradio-core/src/lib/general/gr_feval.h b/gnuradio-core/src/lib/general/gr_feval.h index 18bb4007e..a2f7020a4 100644 --- a/gnuradio-core/src/lib/general/gr_feval.h +++ b/gnuradio-core/src/lib/general/gr_feval.h @@ -85,11 +85,31 @@ public: }; /*! + * \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 */ diff --git a/gnuradio-core/src/lib/general/gr_feval.i b/gnuradio-core/src/lib/general/gr_feval.i index 586e143d0..09d98b648 100644 --- a/gnuradio-core/src/lib/general/gr_feval.i +++ b/gnuradio-core/src/lib/general/gr_feval.i @@ -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); |