GNU Radio 3.6.0 C++ API
|
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_ADD_CONST_H 00023 #define INCLUDED_GR_EXTRAS_ADD_CONST_H 00024 00025 #include <gnuradio/extras/api.h> 00026 #include <gr_sync_block.h> 00027 #include <complex> 00028 00029 namespace gnuradio{ namespace extras{ 00030 00031 class GR_EXTRAS_API add_const : virtual public gr_sync_block{ 00032 public: 00033 typedef boost::shared_ptr<add_const> sptr; 00034 00035 static sptr make_fc32_fc32(const std::complex<double> &val = 0); 00036 static sptr make_sc32_sc32(const std::complex<double> &val = 0); 00037 static sptr make_sc16_sc16(const std::complex<double> &val = 0); 00038 static sptr make_sc8_sc8(const std::complex<double> &val = 0); 00039 static sptr make_f32_f32(const std::complex<double> &val = 0); 00040 static sptr make_s32_s32(const std::complex<double> &val = 0); 00041 static sptr make_s16_s16(const std::complex<double> &val = 0); 00042 static sptr make_s8_s8(const std::complex<double> &val = 0); 00043 00044 //! Set the value from any type 00045 virtual void set_const(const std::complex<double> &val) = 0; 00046 00047 //! Get the constant value as a complex double 00048 virtual std::complex<double> get_const(void) = 0; 00049 }; 00050 00051 class GR_EXTRAS_API add_const_v : virtual public gr_sync_block{ 00052 public: 00053 typedef boost::shared_ptr<add_const_v> sptr; 00054 00055 /*! 00056 * Make an add const from type and const value. 00057 * The length of value is the vector length of this block. 00058 */ 00059 static sptr make_fc32_fc32(const std::vector<std::complex<float> > &vec); 00060 static sptr make_sc32_sc32(const std::vector<std::complex<int32_t> > &vec); 00061 static sptr make_sc16_sc16(const std::vector<std::complex<int16_t> > &vec); 00062 static sptr make_sc8_sc8(const std::vector<std::complex<int8_t> > &vec); 00063 static sptr make_f32_f32(const std::vector<float> &vec); 00064 static sptr make_s32_s32(const std::vector<int32_t> &vec); 00065 static sptr make_s16_s16(const std::vector<int16_t> &vec); 00066 static sptr make_s8_s8(const std::vector<int8_t> &vec); 00067 00068 //! Set the value from any vector type 00069 template <typename type> 00070 void set_const(const std::vector<type> &val); 00071 00072 //! Get the constant value as a vector of complex double 00073 virtual std::vector<std::complex<double> > get_const(void) = 0; 00074 00075 private: 00076 virtual void _set_const(const std::vector<std::complex<double> > &val) = 0; 00077 00078 }; 00079 00080 }} 00081 00082 //--- template implementation details below ---// 00083 00084 template <typename type> 00085 void gnuradio::extras::add_const_v::set_const(const std::vector<type> &val){ 00086 std::vector<std::complex<double> > new_val; 00087 for (size_t i = 0; i < val.size(); i++){ 00088 new_val.push_back(gr_num_to_complex_double(val[i])); 00089 } 00090 return this->_set_const(new_val); 00091 } 00092 00093 #endif /* INCLUDED_GR_EXTRAS_ADD_CONST_H */