Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_basic_block.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 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 #ifndef INCLUDED_GR_BASIC_BLOCK_H
24 #define INCLUDED_GR_BASIC_BLOCK_H
25
26 #include <gr_runtime_types.h>
27 #include <boost/enable_shared_from_this.hpp>
28 #include <string>
29
30 /*!
31  * \brief The abstract base class for all signal processing blocks.
32  * \ingroup block
33  *
34  * Basic blocks are the bare abstraction of an entity that has a name
35  * and a set of inputs and outputs.  These are never instantiated
36  * directly; rather, this is the abstract parent class of both gr_hier_block,
37  * which is a recursive container, and gr_block, which implements actual
38  * signal processing functions.
39  */
40
41 class gr_basic_block : public boost::enable_shared_from_this<gr_basic_block>
42 {
43 protected:
44     std::string          d_name;
45     gr_io_signature_sptr d_input_signature;
46     gr_io_signature_sptr d_output_signature;
47     long                 d_unique_id;
48
49     //! Protected constructor prevents instantiation by non-derived classes
50     gr_basic_block(const std::string &name,
51                    gr_io_signature_sptr input_signature,
52                    gr_io_signature_sptr output_signature);
53
54     //! may only be called during constructor
55     void set_input_signature(gr_io_signature_sptr iosig) {
56         d_input_signature = iosig;
57     }
58     
59     //! may only be called during constructor
60     void set_output_signature(gr_io_signature_sptr iosig) {
61         d_output_signature = iosig;
62     }
63
64 public:
65     virtual ~gr_basic_block();
66     long unique_id() const { return d_unique_id; }
67     std::string name() const { return d_name; }
68     gr_io_signature_sptr input_signature() const  { return d_input_signature; }
69     gr_io_signature_sptr output_signature() const { return d_output_signature; }
70     gr_basic_block_sptr basic_block(); // Needed for Python type coercion
71
72     /*!
73      * \brief Confirm that ninputs and noutputs is an acceptable combination.
74      *
75      * \param ninputs   number of input streams connected
76      * \param noutputs  number of output streams connected
77      *
78      * \returns true if this is a valid configuration for this block.
79      *
80      * This function is called by the runtime system whenever the
81      * topology changes.  Most classes do not need to override this.
82      * This check is in addition to the constraints specified by the input
83      * and output gr_io_signatures.
84      */
85     virtual bool check_topology(int ninputs, int noutputs) { return true; }
86 };
87
88 typedef std::vector<gr_basic_block_sptr> gr_basic_block_vector_t;
89 typedef std::vector<gr_basic_block_sptr>::iterator gr_basic_block_viter_t;
90
91 long gr_basic_block_ncurrently_allocated();
92
93 inline std::ostream &operator << (std::ostream &os, gr_basic_block_sptr basic_block)
94 {
95     os << basic_block->name() << "(" << basic_block->unique_id() << ")";
96     return os;
97 }
98
99 #endif /* INCLUDED_GR_BASIC_BLOCK_H */