diff --git a/gr-blocks/include/gnuradio/blocks/vector_map.h b/gr-blocks/include/gnuradio/blocks/vector_map.h
index bd0e74c..587c642 100644
a
|
b
|
namespace gr { |
50 | 50 | public: |
51 | 51 | // gr::blocks::vector_map::sptr |
52 | 52 | typedef boost::shared_ptr<vector_map> sptr; |
| 53 | typedef unsigned int vmap_t; |
53 | 54 | |
54 | 55 | /*! |
55 | 56 | * Build a vector map block. |
… |
… |
namespace gr { |
60 | 61 | * \param mapping (vector of vectors of vectors of integers) how to |
61 | 62 | * map elements from input to output vectors |
62 | 63 | */ |
63 | | static sptr make(size_t item_size, std::vector<size_t> in_vlens, |
64 | | std::vector< std::vector< std::vector<size_t> > > mapping); |
| 64 | static sptr make(size_t item_size, const std::vector<vmap_t>& in_vlens, |
| 65 | const std::vector< std::vector< std::vector<vmap_t> > >& mapping); |
65 | 66 | |
66 | | virtual void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) = 0; |
| 67 | virtual void set_mapping(const std::vector< std::vector< std::vector<vmap_t> > >& mapping) = 0; |
67 | 68 | }; |
68 | 69 | |
69 | 70 | } /* namespace blocks */ |
diff --git a/gr-blocks/lib/vector_map_impl.cc b/gr-blocks/lib/vector_map_impl.cc
index d50dcb5..eae26c6 100644
a
|
b
|
|
31 | 31 | namespace gr { |
32 | 32 | namespace blocks { |
33 | 33 | |
34 | | std::vector<int> |
35 | | get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) |
| 34 | static std::vector<int> |
| 35 | get_in_sizeofs(size_t item_size, const std::vector<vector_map::vmap_t> &in_vlens) |
36 | 36 | { |
37 | 37 | std::vector<int> in_sizeofs; |
38 | | for(unsigned int i = 0; i < in_vlens.size(); i++) { |
| 38 | for(size_t i = 0; i < in_vlens.size(); i++) { |
39 | 39 | in_sizeofs.push_back(in_vlens[i]*item_size); |
40 | 40 | } |
41 | 41 | return in_sizeofs; |
42 | 42 | } |
43 | 43 | |
44 | | std::vector<int> |
| 44 | static std::vector<int> |
45 | 45 | get_out_sizeofs(size_t item_size, |
46 | | std::vector< std::vector< std::vector<size_t> > > mapping) |
| 46 | const std::vector< std::vector< std::vector<vector_map::vmap_t> > > &mapping) |
47 | 47 | { |
48 | 48 | std::vector<int> out_sizeofs; |
49 | | for(unsigned int i = 0; i < mapping.size(); i++) { |
| 49 | for(size_t i = 0; i < mapping.size(); i++) { |
50 | 50 | out_sizeofs.push_back(mapping[i].size()*item_size); |
51 | 51 | } |
52 | 52 | return out_sizeofs; |
53 | | } |
| 53 | } |
54 | 54 | |
55 | 55 | vector_map::sptr |
56 | | vector_map::make(size_t item_size, std::vector<size_t> in_vlens, |
57 | | std::vector< std::vector< std::vector<size_t> > > mapping) |
| 56 | vector_map::make(size_t item_size, const std::vector<vector_map::vmap_t> &in_vlens, |
| 57 | const std::vector< std::vector< std::vector<vector_map::vmap_t> > > &mapping) |
58 | 58 | { |
59 | 59 | return gnuradio::get_initial_sptr |
60 | 60 | (new vector_map_impl(item_size, in_vlens, mapping)); |
61 | 61 | } |
62 | 62 | |
63 | | vector_map_impl::vector_map_impl(size_t item_size, std::vector<size_t> in_vlens, |
64 | | std::vector< std::vector< std::vector<size_t> > > mapping) |
| 63 | vector_map_impl::vector_map_impl(size_t item_size, const std::vector<vector_map::vmap_t> &in_vlens, |
| 64 | const std::vector< std::vector< std::vector<vector_map::vmap_t> > > &mapping) |
65 | 65 | : sync_block("vector_map", |
66 | 66 | io_signature::makev(in_vlens.size(), in_vlens.size(), |
67 | 67 | get_in_sizeofs(item_size, in_vlens)), |
… |
… |
namespace gr { |
77 | 77 | } |
78 | 78 | |
79 | 79 | void |
80 | | vector_map_impl::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) |
| 80 | vector_map_impl::set_mapping(const std::vector< std::vector< std::vector<vector_map::vmap_t> > > &mapping) |
81 | 81 | { |
82 | 82 | // Make sure the contents of the mapping vectors are possible. |
83 | | for(unsigned int i=0; i<mapping.size(); i++) { |
84 | | for(unsigned int j=0; j<mapping[i].size(); j++) { |
| 83 | for(size_t i=0; i<mapping.size(); i++) { |
| 84 | for(size_t j=0; j<mapping[i].size(); j++) { |
85 | 85 | if(mapping[i][j].size() != 2) { |
86 | 86 | 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."); |
87 | 87 | } |
88 | | unsigned int s = mapping[i][j][0]; |
89 | | unsigned int index = mapping[i][j][1]; |
| 88 | vector_map::vmap_t s = mapping[i][j][0]; |
| 89 | vector_map::vmap_t index = mapping[i][j][1]; |
90 | 90 | if(s >= d_in_vlens.size()) { |
91 | 91 | throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); |
92 | 92 | } |
… |
… |
namespace gr { |
107 | 107 | const char **inv = (const char**)&input_items[0]; |
108 | 108 | char **outv = (char**)&output_items[0]; |
109 | 109 | |
110 | | for(unsigned int n = 0; n < (unsigned int)(noutput_items); n++) { |
111 | | for(unsigned int i = 0; i < d_mapping.size(); i++) { |
112 | | unsigned int out_vlen = d_mapping[i].size(); |
113 | | for(unsigned int j = 0; j < out_vlen; j++) { |
114 | | unsigned int s = d_mapping[i][j][0]; |
115 | | unsigned int k = d_mapping[i][j][1]; |
| 110 | for(size_t n = 0; n < (size_t)(noutput_items); n++) { |
| 111 | for(size_t i = 0; i < d_mapping.size(); i++) { |
| 112 | size_t out_vlen = d_mapping[i].size(); |
| 113 | for(size_t j = 0; j < out_vlen; j++) { |
| 114 | vector_map::vmap_t s = d_mapping[i][j][0]; |
| 115 | vector_map::vmap_t k = d_mapping[i][j][1]; |
116 | 116 | memcpy(outv[i] + out_vlen*d_item_size*n + |
117 | 117 | d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + |
118 | 118 | k*d_item_size, d_item_size); |
diff --git a/gr-blocks/lib/vector_map_impl.h b/gr-blocks/lib/vector_map_impl.h
index 64f5e09..c0565da 100644
a
|
b
|
namespace gr { |
33 | 33 | { |
34 | 34 | private: |
35 | 35 | size_t d_item_size; |
36 | | std::vector<size_t> d_in_vlens; |
37 | | std::vector< std::vector< std::vector<size_t> > > d_mapping; |
| 36 | std::vector<vmap_t> d_in_vlens; |
| 37 | std::vector< std::vector< std::vector<vmap_t> > > d_mapping; |
38 | 38 | gr::thread::mutex d_mutex; // mutex to protect set/work access |
39 | 39 | |
40 | 40 | public: |
41 | | vector_map_impl(size_t item_size, std::vector<size_t> in_vlens, |
42 | | std::vector< std::vector< std::vector<size_t> > > mapping); |
| 41 | vector_map_impl(size_t item_size, const std::vector<vmap_t> &in_vlens, |
| 42 | const std::vector< std::vector< std::vector<vmap_t> > > &mapping); |
43 | 43 | ~vector_map_impl(); |
44 | 44 | |
45 | | void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping); |
| 45 | void set_mapping(const std::vector< std::vector< std::vector<vmap_t> > > &mapping); |
46 | 46 | |
47 | 47 | int work(int noutput_items, |
48 | 48 | gr_vector_const_void_star &input_items, |