1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014,2018 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 #include "tsb_vector_sink_impl.h"
29 #include <gnuradio/io_signature.h>
30 
31 namespace gr {
32 namespace blocks {
33 
34 template <class T>
make(unsigned int vlen,const std::string & tsb_key)35 typename tsb_vector_sink<T>::sptr tsb_vector_sink<T>::make(unsigned int vlen,
36                                                            const std::string& tsb_key)
37 {
38     return gnuradio::get_initial_sptr(new tsb_vector_sink_impl<T>(vlen, tsb_key));
39 }
40 
41 template <class T>
tsb_vector_sink_impl(unsigned int vlen,const std::string & tsb_key)42 tsb_vector_sink_impl<T>::tsb_vector_sink_impl(unsigned int vlen,
43                                               const std::string& tsb_key)
44     : gr::tagged_stream_block("tsb_vector_sink",
45                               gr::io_signature::make(1, 1, vlen * sizeof(T)),
46                               gr::io_signature::make(0, 0, 0),
47                               tsb_key),
48       d_vlen(vlen)
49 {
50 }
51 
52 template <class T>
~tsb_vector_sink_impl()53 tsb_vector_sink_impl<T>::~tsb_vector_sink_impl()
54 {
55 }
56 
57 template <class T>
data() const58 std::vector<std::vector<T>> tsb_vector_sink_impl<T>::data() const
59 {
60     return d_data;
61 }
62 
63 template <class T>
tags() const64 std::vector<tag_t> tsb_vector_sink_impl<T>::tags() const
65 {
66     return d_tags;
67 }
68 
69 template <class T>
work(int noutput_items,gr_vector_int & ninput_items,gr_vector_const_void_star & input_items,gr_vector_void_star & output_items)70 int tsb_vector_sink_impl<T>::work(int noutput_items,
71                                   gr_vector_int& ninput_items,
72                                   gr_vector_const_void_star& input_items,
73                                   gr_vector_void_star& output_items)
74 {
75     const T* in = (const T*)input_items[0];
76 
77     std::vector<T> new_data(in, in + (ninput_items[0] * d_vlen));
78     d_data.push_back(new_data);
79 
80     std::vector<tag_t> tags;
81     this->get_tags_in_window(tags, 0, 0, ninput_items[0]);
82     d_tags.insert(d_tags.end(), tags.begin(), tags.end());
83 
84     return ninput_items[0];
85 }
86 
87 template class tsb_vector_sink<std::uint8_t>;
88 template class tsb_vector_sink<std::int16_t>;
89 template class tsb_vector_sink<std::int32_t>;
90 template class tsb_vector_sink<float>;
91 template class tsb_vector_sink<gr_complex>;
92 } /* namespace blocks */
93 } /* namespace gr */
94