GNU Radio 3.6.0 C++ API
multiply_const.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Free Software Foundation, Inc.
00003  * 
00004  * This file is part of GNU Radio
00005  * 
00006  * GNU Radio is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 3, or (at your option)
00009  * any later version.
00010  * 
00011  * GNU Radio is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with GNU Radio; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #ifndef INCLUDED_GR_EXTRAS_MULTIPLY_CONST_H
00023 #define INCLUDED_GR_EXTRAS_MULTIPLY_CONST_H
00024 
00025 #include <gnuradio/extras/api.h>
00026 #include <gnuradio/extras/op_types.h>
00027 #include <gr_sync_block.h>
00028 #include <complex>
00029 
00030 namespace gnuradio{ namespace extras{
00031 
00032 class GR_EXTRAS_API multiply_const : virtual public gr_sync_block{
00033 public:
00034     typedef boost::shared_ptr<multiply_const> sptr;
00035 
00036     static sptr make_fc32_fc32(const std::complex<double> &val = 0);
00037     static sptr make_sc32_sc32(const std::complex<double> &val = 0);
00038     static sptr make_sc16_sc16(const std::complex<double> &val = 0);
00039     static sptr make_sc8_sc8(const std::complex<double> &val = 0);
00040     static sptr make_f32_f32(const std::complex<double> &val = 0);
00041     static sptr make_s32_s32(const std::complex<double> &val = 0);
00042     static sptr make_s16_s16(const std::complex<double> &val = 0);
00043     static sptr make_s8_s8(const std::complex<double> &val = 0);
00044 
00045     //! Set the value from any type
00046     virtual void set_const(const std::complex<double> &val) = 0;
00047 
00048     //! Get the constant value as a complex double
00049     virtual std::complex<double> get_const(void) = 0;
00050 };
00051 
00052 class GR_EXTRAS_API multiply_const_v : virtual public gr_sync_block{
00053 public:
00054     typedef boost::shared_ptr<multiply_const_v> sptr;
00055 
00056     /*!
00057      * Make a multiply const from type and const value.
00058      * The length of value is the vector length of this block.
00059      */
00060     static sptr make_fc32_fc32(const std::vector<std::complex<float> > &vec);
00061     static sptr make_sc32_sc32(const std::vector<std::complex<int32_t> > &vec);
00062     static sptr make_sc16_sc16(const std::vector<std::complex<int16_t> > &vec);
00063     static sptr make_sc8_sc8(const std::vector<std::complex<int8_t> > &vec);
00064     static sptr make_f32_f32(const std::vector<float> &vec);
00065     static sptr make_s32_s32(const std::vector<int32_t> &vec);
00066     static sptr make_s16_s16(const std::vector<int16_t> &vec);
00067     static sptr make_s8_s8(const std::vector<int8_t> &vec);
00068 
00069     //! Set the value from any vector type
00070     template <typename type>
00071     void set_const(const std::vector<type> &val);
00072 
00073     //! Get the constant value as a vector of complex double
00074     virtual std::vector<std::complex<double> > get_const(void) = 0;
00075 
00076 private:
00077     virtual void _set_const(const std::vector<std::complex<double> > &val) = 0;
00078 
00079 };
00080 
00081 }}
00082 
00083 //--- template implementation details below ---//
00084 
00085 template <typename type>
00086 void gnuradio::extras::multiply_const_v::set_const(const std::vector<type> &val){
00087     std::vector<std::complex<double> > new_val;
00088     for (size_t i = 0; i < val.size(); i++){
00089         new_val.push_back(gr_num_to_complex_double(val[i]));
00090     }
00091     return this->_set_const(new_val);
00092 }
00093 
00094 #endif /* INCLUDED_GR_EXTRAS_MULTIPLY_CONST_H */