diff options
Diffstat (limited to 'gnuradio-core/src/lib/general')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_vector_map.cc | 93 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_vector_map.h | 34 |
2 files changed, 69 insertions, 58 deletions
diff --git a/gnuradio-core/src/lib/general/gr_vector_map.cc b/gnuradio-core/src/lib/general/gr_vector_map.cc index 361daa490..4cf2ed118 100644 --- a/gnuradio-core/src/lib/general/gr_vector_map.cc +++ b/gnuradio-core/src/lib/general/gr_vector_map.cc @@ -29,39 +29,43 @@ #include <string.h> std::vector<int> -get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) { +get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) +{ std::vector<int> in_sizeofs; - for (unsigned int i; i < in_vlens.size(); i++) { - in_sizeofs.push_back(in_vlens[i]*item_size); + for(unsigned int i; i < in_vlens.size(); i++) { + in_sizeofs.push_back(in_vlens[i]*item_size); } return in_sizeofs; } std::vector<int> get_out_sizeofs(size_t item_size, - std::vector< std::vector< std::vector<size_t> > > mapping) { + std::vector< std::vector< std::vector<size_t> > > mapping) +{ std::vector<int> out_sizeofs; - for (unsigned int i; i < mapping.size(); i++) { - out_sizeofs.push_back(mapping[i].size()*item_size); + for(unsigned int i; i < mapping.size(); i++) { + out_sizeofs.push_back(mapping[i].size()*item_size); } return out_sizeofs; } gr_vector_map_sptr gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping) + std::vector< std::vector< std::vector<size_t> > > mapping) { - return gnuradio::get_initial_sptr(new gr_vector_map (item_size, in_vlens, mapping)); + return gnuradio::get_initial_sptr(new gr_vector_map(item_size, + in_vlens, + mapping)); } -gr_vector_map::gr_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping) - : gr_sync_block ("vector_map", - gr_make_io_signaturev (in_vlens.size(), in_vlens.size(), - get_in_sizeofs(item_size, in_vlens)), - gr_make_io_signaturev (mapping.size(), mapping.size(), - get_out_sizeofs(item_size, mapping))), - d_item_size(item_size), d_in_vlens(in_vlens) +gr_vector_map::gr_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping) + : gr_sync_block("vector_map", + gr_make_io_signaturev(in_vlens.size(), in_vlens.size(), + get_in_sizeofs(item_size, in_vlens)), + gr_make_io_signaturev(mapping.size(), mapping.size(), + get_out_sizeofs(item_size, mapping))), + d_item_size(item_size), d_in_vlens(in_vlens) { set_mapping(mapping); } @@ -69,43 +73,44 @@ gr_vector_map::gr_vector_map (size_t item_size, std::vector<size_t> in_vlens, void gr_vector_map::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) { // Make sure the contents of the mapping vectors are possible. - for (unsigned int i=0; i<mapping.size(); i++) { - for (unsigned int j=0; j<mapping[i].size(); j++) { - if (mapping[i][j].size() != 2) { - throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items."); - } - unsigned int s = mapping[i][j][0]; - unsigned int index = mapping[i][j][1]; - if (s >= d_in_vlens.size()) { - throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); - } - if ((index < 0) || (index >= d_in_vlens[s])) { - throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths."); - } - } - } + for(unsigned int i=0; i<mapping.size(); i++) { + for(unsigned int j=0; j<mapping[i].size(); j++) { + if(mapping[i][j].size() != 2) { + throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items."); + } + unsigned int s = mapping[i][j][0]; + unsigned int index = mapping[i][j][1]; + if(s >= d_in_vlens.size()) { + throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); + } + if((index < 0) || (index >= d_in_vlens[s])) { + throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths."); + } + } + } gruel::scoped_lock guard(d_mutex); d_mapping = mapping; } int -gr_vector_map::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_vector_map::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { - const char **inv = (const char **) &input_items[0]; char **outv = (char **) &output_items[0]; - for (unsigned int n=0; n<(unsigned int)(noutput_items); n++) { - for (unsigned int i=0; i<d_mapping.size(); i++) { - unsigned int out_vlen = d_mapping[i].size(); - for (unsigned int j=0; j<out_vlen; j++) { - unsigned int s = d_mapping[i][j][0]; - unsigned int k = d_mapping[i][j][1]; - memcpy(outv[i] + out_vlen*d_item_size*n + d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + k*d_item_size, d_item_size); - } - } + for(unsigned int n = 0; n < (unsigned int)(noutput_items); n++) { + for(unsigned int i = 0; i < d_mapping.size(); i++) { + unsigned int out_vlen = d_mapping[i].size(); + for(unsigned int j = 0; j < out_vlen; j++) { + unsigned int s = d_mapping[i][j][0]; + unsigned int k = d_mapping[i][j][1]; + memcpy(outv[i] + out_vlen*d_item_size*n + + d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + + k*d_item_size, d_item_size); + } + } } return noutput_items; diff --git a/gnuradio-core/src/lib/general/gr_vector_map.h b/gnuradio-core/src/lib/general/gr_vector_map.h index ccb05bc53..f5492b1e3 100644 --- a/gnuradio-core/src/lib/general/gr_vector_map.h +++ b/gnuradio-core/src/lib/general/gr_vector_map.h @@ -33,43 +33,49 @@ typedef boost::shared_ptr<gr_vector_map> gr_vector_map_sptr; GR_CORE_API gr_vector_map_sptr gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping); + std::vector< std::vector< std::vector<size_t> > > mapping); /*! * \brief Maps elements from a set of input vectors to a set of output vectors. * - * If in[i] is the input vector in the i'th stream then the output vector in the j'th stream is: + * If in[i] is the input vector in the i'th stream then the output + * vector in the j'th stream is: + * * out[j][k] = in[mapping[j][k][0]][mapping[j][k][1]] - * That is mapping is of the form (out_stream1_mapping, out_stream2_mapping, ...) - * and out_stream1_mapping is of the form (element1_mapping, element2_mapping, ...) - * and element1_mapping is of the form (in_stream, in_element). + * + * That is mapping is of the form (out_stream1_mapping, + * out_stream2_mapping, ...) and out_stream1_mapping is of the form + * (element1_mapping, element2_mapping, ...) and element1_mapping is + * of the form (in_stream, in_element). * * \param item_size (integer) size of vector elements * - * \param in_vlens (vector of integers) number of elements in each input vector + * \param in_vlens (vector of integers) number of elements in each + * input vector * - * \param mapping (vector of vectors of vectors of integers) how to map elements from input to output vectors + * \param mapping (vector of vectors of vectors of integers) how to + * map elements from input to output vectors * * \ingroup slicedice_blk */ class GR_CORE_API gr_vector_map : public gr_sync_block { friend GR_CORE_API gr_vector_map_sptr - gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping); + gr_make_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); size_t d_item_size; std::vector<size_t> d_in_vlens; std::vector< std::vector< std::vector<size_t> > > d_mapping; gruel::mutex d_mutex; // mutex to protect set/work access protected: - gr_vector_map (size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping); + gr_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); public: - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping); }; |