00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2006,2008 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_GR_BASIC_BLOCK_H 00024 #define INCLUDED_GR_BASIC_BLOCK_H 00025 00026 #include <gr_runtime_types.h> 00027 #include <gr_sptr_magic.h> 00028 #include <boost/enable_shared_from_this.hpp> 00029 #include <string> 00030 00042 class gr_basic_block : public boost::enable_shared_from_this<gr_basic_block> 00043 { 00044 protected: 00045 friend class gr_flowgraph; 00046 friend class gr_flat_flowgraph; // TODO: will be redundant 00047 00048 enum vcolor { WHITE, GREY, BLACK }; 00049 00050 std::string d_name; 00051 gr_io_signature_sptr d_input_signature; 00052 gr_io_signature_sptr d_output_signature; 00053 long d_unique_id; 00054 vcolor d_color; 00055 00057 gr_basic_block(const std::string &name, 00058 gr_io_signature_sptr input_signature, 00059 gr_io_signature_sptr output_signature); 00060 00062 void set_input_signature(gr_io_signature_sptr iosig) { 00063 d_input_signature = iosig; 00064 } 00065 00067 void set_output_signature(gr_io_signature_sptr iosig) { 00068 d_output_signature = iosig; 00069 } 00070 00074 void set_color(vcolor color) { d_color = color; } 00075 vcolor color() const { return d_color; } 00076 00077 public: 00078 virtual ~gr_basic_block(); 00079 long unique_id() const { return d_unique_id; } 00080 std::string name() const { return d_name; } 00081 gr_io_signature_sptr input_signature() const { return d_input_signature; } 00082 gr_io_signature_sptr output_signature() const { return d_output_signature; } 00083 gr_basic_block_sptr basic_block(); // Needed for Python type coercion 00084 00098 virtual bool check_topology(int ninputs, int noutputs) { return true; } 00099 }; 00100 00101 inline bool operator<(gr_basic_block_sptr lhs, gr_basic_block_sptr rhs) 00102 { 00103 return lhs->unique_id() < rhs->unique_id(); 00104 } 00105 00106 typedef std::vector<gr_basic_block_sptr> gr_basic_block_vector_t; 00107 typedef std::vector<gr_basic_block_sptr>::iterator gr_basic_block_viter_t; 00108 00109 long gr_basic_block_ncurrently_allocated(); 00110 00111 inline std::ostream &operator << (std::ostream &os, gr_basic_block_sptr basic_block) 00112 { 00113 os << basic_block->name() << "(" << basic_block->unique_id() << ")"; 00114 return os; 00115 } 00116 00117 #endif /* INCLUDED_GR_BASIC_BLOCK_H */