GNU Radio 3.7.1 C++ API
feval.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006,2013 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_GR_FEVAL_H
00024 #define INCLUDED_GR_FEVAL_H
00025 
00026 #include <gnuradio/api.h>
00027 #include <gnuradio/gr_complex.h>
00028 #include <pmt/pmt.h>
00029 
00030 namespace gr {
00031 
00032   /*!
00033    * \brief base class for evaluating a function: double -> double
00034    * \ingroup misc
00035    *
00036    * This class is designed to be subclassed in Python or C++ and is
00037    * callable from both places. It uses SWIG's "director" feature to
00038    * implement the magic.
00039    *
00040    * It's slow. Don't use it in a performance critical path.
00041    *
00042    * Override eval to define the behavior.
00043    * Use calleval to invoke eval (this kludge is required to allow a
00044    * python specific "shim" to be inserted.
00045    */
00046   class GR_RUNTIME_API feval_dd
00047   {
00048   protected:
00049     /*!
00050      * \brief override this to define the function
00051      */
00052     virtual double eval(double x);
00053 
00054   public:
00055     feval_dd() {}
00056     virtual ~feval_dd();
00057 
00058     virtual double calleval(double x);  // invoke "eval"
00059   };
00060 
00061   /*!
00062    * \brief base class for evaluating a function: complex -> complex
00063    * \ingroup misc
00064    *
00065    * This class is designed to be subclassed in Python or C++ and is
00066    * callable from both places. It uses SWIG's "director" feature to
00067    * implement the magic.
00068    *
00069    * It's slow. Don't use it in a performance critical path.
00070    *
00071    * Override eval to define the behavior.
00072    * Use calleval to invoke eval (this kludge is required to allow a
00073    * python specific "shim" to be inserted.
00074    */
00075   class GR_RUNTIME_API feval_cc
00076   {
00077   protected:
00078     /*!
00079      * \brief override this to define the function
00080      */
00081     virtual gr_complex eval(gr_complex x);
00082 
00083   public:
00084     feval_cc() {}
00085     virtual ~feval_cc();
00086 
00087     virtual gr_complex calleval(gr_complex x);  // invoke "eval"
00088   };
00089 
00090   /*!
00091    * \brief base class for evaluating a function: long -> long
00092    * \ingroup misc
00093    *
00094    * This class is designed to be subclassed in Python or C++ and is
00095    * callable from both places. It uses SWIG's "director" feature to
00096    * implement the magic.
00097    *
00098    * It's slow. Don't use it in a performance critical path.
00099    *
00100    * Override eval to define the behavior.
00101    * Use calleval to invoke eval (this kludge is required to allow a
00102    * python specific "shim" to be inserted.
00103    */
00104   class GR_RUNTIME_API feval_ll
00105   {
00106   protected:
00107     /*!
00108      * \brief override this to define the function
00109      */
00110     virtual long eval(long x);
00111 
00112   public:
00113     feval_ll() {}
00114     virtual ~feval_ll();
00115 
00116     virtual long calleval(long x);      // invoke "eval"
00117   };
00118 
00119   /*!
00120    * \brief base class for evaluating a function: void -> void
00121    * \ingroup misc
00122    *
00123    * This class is designed to be subclassed in Python or C++ and is
00124    * callable from both places. It uses SWIG's "director" feature to
00125    * implement the magic.
00126    *
00127    * It's slow. Don't use it in a performance critical path.
00128    *
00129    * Override eval to define the behavior.
00130    * Use calleval to invoke eval (this kludge is required to allow a
00131    * python specific "shim" to be inserted.
00132    */
00133   class GR_RUNTIME_API feval
00134   {
00135   protected:
00136     /*!
00137      * \brief override this to define the function
00138      */
00139     virtual void eval();
00140 
00141   public:
00142     feval() {}
00143     virtual ~feval();
00144 
00145     virtual void calleval();    // invoke "eval"
00146   };
00147 
00148   /*!
00149    * \brief base class for evaluating a function: pmt -> void
00150    * \ingroup misc
00151    *
00152    * This class is designed to be subclassed in Python or C++ and is
00153    * callable from both places. It uses SWIG's "director" feature to
00154    * implement the magic.
00155    *
00156    * It's slow. Don't use it in a performance critical path.
00157    *
00158    * Override eval to define the behavior.
00159    * Use calleval to invoke eval (this kludge is required to allow a
00160    * python specific "shim" to be inserted.
00161    */
00162   class GR_RUNTIME_API feval_p
00163   {
00164   protected:
00165     /*!
00166      * \brief override this to define the function
00167      */
00168     virtual void eval(pmt::pmt_t x);
00169 
00170   public:
00171     feval_p() {}
00172     virtual ~feval_p();
00173 
00174     virtual void calleval(pmt::pmt_t x);        // invoke "eval"
00175   };
00176 
00177   /*!
00178    * \brief trivial examples / test cases showing C++ calling Python code
00179    */
00180   GR_RUNTIME_API double     feval_dd_example(feval_dd *f, double x);
00181   GR_RUNTIME_API gr_complex feval_cc_example(feval_cc *f, gr_complex x);
00182   GR_RUNTIME_API long       feval_ll_example(feval_ll *f, long x);
00183   GR_RUNTIME_API void       feval_example(feval *f);
00184 
00185 } /* namespace gr */
00186 
00187 #endif /* INCLUDED_GR_FEVAL_H */