diff options
author | eb | 2007-02-20 20:49:54 +0000 |
---|---|---|
committer | eb | 2007-02-20 20:49:54 +0000 |
commit | 8097ab89e6e26c08e6ed9bd57502f7fbb1385299 (patch) | |
tree | 42003da96bf2736b2c774b1a54de334a58b5e942 /gnuradio-core/src | |
parent | 0ff13bf5b3ab73ebf77974a91f466385591d4ec7 (diff) | |
download | gnuradio-8097ab89e6e26c08e6ed9bd57502f7fbb1385299.tar.gz gnuradio-8097ab89e6e26c08e6ed9bd57502f7fbb1385299.tar.bz2 gnuradio-8097ab89e6e26c08e6ed9bd57502f7fbb1385299.zip |
Merged eb/iosig r4533:4539 into trunk. This adds support for
io_signatures with heterogeneous stream element sizes.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4541 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_io_signature.cc | 80 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_io_signature.h | 95 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_io_signature.i | 42 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_gr_block.cc | 8 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc | 13 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_gr_io_signature.h | 1 |
7 files changed, 190 insertions, 51 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.cc b/gnuradio-core/src/lib/runtime/gr_io_signature.cc index 51ab9286c..ace27314e 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,28 +27,86 @@ #include <stdexcept> #include <iostream> -gr_io_signature::gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item) +gr_io_signature_sptr +gr_make_io_signaturev(int min_streams, int max_streams, + const std::vector<int> &sizeof_stream_items) +{ + return gr_io_signature_sptr (new gr_io_signature (min_streams, max_streams, + sizeof_stream_items)); +} + +gr_io_signature_sptr +gr_make_io_signature(int min_streams, int max_streams, + int sizeof_stream_item) +{ + std::vector<int> sizeof_items(1); + sizeof_items[0] = sizeof_stream_item; + return gr_make_io_signaturev(min_streams, max_streams, sizeof_items); +} + +gr_io_signature_sptr +gr_make_io_signature2(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2) +{ + std::vector<int> sizeof_items(2); + sizeof_items[0] = sizeof_stream_item1; + sizeof_items[1] = sizeof_stream_item2; + return gr_make_io_signaturev(min_streams, max_streams, sizeof_items); +} + +gr_io_signature_sptr +gr_make_io_signature3(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3) +{ + std::vector<int> sizeof_items(3); + sizeof_items[0] = sizeof_stream_item1; + sizeof_items[1] = sizeof_stream_item2; + sizeof_items[2] = sizeof_stream_item3; + return gr_make_io_signaturev(min_streams, max_streams, sizeof_items); +} + +// ------------------------------------------------------------------------ + + +gr_io_signature::gr_io_signature (int min_streams, int max_streams, + const std::vector<int> &sizeof_stream_items) { if (min_streams < 0 || (max_streams != IO_INFINITE && max_streams < min_streams)) - throw std::invalid_argument ("gr_io_signature"); + throw std::invalid_argument ("gr_io_signature(1)"); + if (sizeof_stream_items.size() < 1) + throw std::invalid_argument("gr_io_signature(2)"); + + for (size_t i = 0; i < sizeof_stream_items.size(); i++){ + if (max_streams != 0 && sizeof_stream_items[i] < 1) + throw std::invalid_argument("gr_io_signature(3)"); + } + d_min_streams = min_streams; d_max_streams = max_streams; - d_sizeof_stream_item = sizeof_stream_item; + d_sizeof_stream_item = sizeof_stream_items; } gr_io_signature::~gr_io_signature () { - // NOP for now - // std::cout << "destroying gr_io_signature: " << this << '\n'; } -gr_io_signature_sptr -gr_make_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item) +int +gr_io_signature::sizeof_stream_item (int _index) const { - return gr_io_signature_sptr (new gr_io_signature (min_streams, max_streams, - sizeof_stream_item)); + if (_index < 0) + throw std::invalid_argument ("gr_io_signature::sizeof_stream_item"); + + size_t index = _index; + return d_sizeof_stream_item[std::min(index, d_sizeof_stream_item.size() - 1)]; } - +std::vector<int> +gr_io_signature::sizeof_stream_items() const +{ + return d_sizeof_stream_item; +} diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index e5e009781..d33a1cf34 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,13 +26,78 @@ #include <gr_runtime_types.h> /*! - * \brief i/o signature for input and output ports. + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item specify the size of the items in each stream + */ +gr_io_signature_sptr +gr_make_io_signature(int min_streams, int max_streams, + int sizeof_stream_item); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item1 specify the size of the items in the first stream + * \param sizeof_stream_item2 specify the size of the items in the second and subsequent streams + */ +gr_io_signature_sptr +gr_make_io_signature2(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2 + ); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item1 specify the size of the items in the first stream + * \param sizeof_stream_item2 specify the size of the items in the second stream + * \param sizeof_stream_item3 specify the size of the items in the third and subsequent streams + */ +gr_io_signature_sptr +gr_make_io_signature3(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3 + ); + +/*! + * \brief Create an i/o signature * - * For now, we restrict all streams to be the same type. - * We can fix this later. + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_items specify the size of the items in the streams + * + * If there are more streams than there are entries in sizeof_stream_items, the + * value of the last entry in sizeof_stream_items is used for the missing values. + * sizeof_stream_items must contain at least 1 entry. + */ +gr_io_signature_sptr +gr_make_io_signaturev(int min_streams, int max_streams, + const std::vector<int> &sizeof_stream_items); + + +/*! + * \brief i/o signature for input and output ports. */ - class gr_io_signature { + int d_min_streams; + int d_max_streams; + std::vector<int> d_sizeof_stream_item; + + gr_io_signature(int min_streams, int max_streams, + const std::vector<int> &sizeof_stream_items); + + friend gr_io_signature_sptr + gr_make_io_signaturev(int min_streams, + int max_streams, + const std::vector<int> &sizeof_stream_item); + public: static const int IO_INFINITE = -1; @@ -41,25 +106,9 @@ class gr_io_signature { int min_streams () const { return d_min_streams; } int max_streams () const { return d_max_streams; } - size_t sizeof_stream_item (int index) const { return d_sizeof_stream_item; } - - // ---------------------------------------------------------------------------- - - private: - - int d_min_streams; - int d_max_streams; - size_t d_sizeof_stream_item; - - gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); - - friend gr_io_signature_sptr gr_make_io_signature (int min_streams, - int max_streams, - size_t sizeof_stream_item); + int sizeof_stream_item (int index) const; + std::vector<int> sizeof_stream_items() const; }; -gr_io_signature_sptr -gr_make_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); - #endif /* INCLUDED_IO_SIGNATURE_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.i b/gnuradio-core/src/lib/runtime/gr_io_signature.i index ca5ee215e..ef79cd2fb 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.i +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2005 Free Software Foundation, Inc. + * Copyright 2004,2005,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,14 +24,40 @@ class gr_io_signature; typedef boost::shared_ptr<gr_io_signature> gr_io_signature_sptr; %template(gr_io_signature_sptr) boost::shared_ptr<gr_io_signature>; -%rename(io_signature) gr_make_io_signature; +%rename(io_signature) gr_make_io_signature; +%rename(io_signature2) gr_make_io_signature2; +%rename(io_signature3) gr_make_io_signature3; +%rename(io_signaturev) gr_make_io_signaturev; + +gr_io_signature_sptr +gr_make_io_signature(int min_streams, int max_streams, + int sizeof_stream_item); + +gr_io_signature_sptr +gr_make_io_signature2(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2 + ); +gr_io_signature_sptr +gr_make_io_signature3(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3 + ); gr_io_signature_sptr -gr_make_io_signature (int min_streams, - int max_streams, - size_t sizeof_stream_item); +gr_make_io_signaturev(int min_streams, int max_streams, + const std::vector<int> &sizeof_stream_items); + class gr_io_signature { + gr_io_signature (int min_streams, int max_streams, int sizeof_stream_item); + + friend gr_io_signature_sptr + gr_make_io_signaturev(int min_streams, + int max_streams, + const std::vector<int> &sizeof_stream_item); + public: // disabled. Suspected bug in SWIG 1.3.24 @@ -41,9 +67,7 @@ class gr_io_signature { int min_streams () const { return d_min_streams; } int max_streams () const { return d_max_streams; } - size_t sizeof_stream_item (int index) const { return d_sizeof_stream_item; } - - private: - gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); + int sizeof_stream_item (int index) const; + std::vector<int> sizeof_stream_items() const; }; diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_block.cc index 630d72749..5a0875335 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.cc @@ -42,7 +42,7 @@ qa_gr_block::t0 () CPPUNIT_ASSERT_EQUAL (0, src1->input_signature()->max_streams ()); CPPUNIT_ASSERT_EQUAL (1, src1->output_signature()->min_streams ()); CPPUNIT_ASSERT_EQUAL (1, src1->output_signature()->max_streams ()); - CPPUNIT_ASSERT_EQUAL (sizeof (int), + CPPUNIT_ASSERT_EQUAL ((int) sizeof(int), src1->output_signature()->sizeof_stream_item (0)); gr_block_sptr src2 (gr_make_null_source (sizeof (short))); @@ -50,7 +50,7 @@ qa_gr_block::t0 () CPPUNIT_ASSERT_EQUAL (0, src2->input_signature()->max_streams ()); CPPUNIT_ASSERT_EQUAL (1, src2->output_signature()->min_streams ()); CPPUNIT_ASSERT_EQUAL (1, src2->output_signature()->max_streams ()); - CPPUNIT_ASSERT_EQUAL (sizeof (short), + CPPUNIT_ASSERT_EQUAL ((int) sizeof (short), src2->output_signature()->sizeof_stream_item (0)); } @@ -63,7 +63,7 @@ qa_gr_block::t1 () CPPUNIT_ASSERT_EQUAL (std::string ("null_sink"), dst1->name ()); CPPUNIT_ASSERT_EQUAL (1, dst1->input_signature()->min_streams ()); CPPUNIT_ASSERT_EQUAL (1, dst1->input_signature()->max_streams ()); - CPPUNIT_ASSERT_EQUAL (sizeof (int), + CPPUNIT_ASSERT_EQUAL ((int) sizeof (int), dst1->input_signature()->sizeof_stream_item (0)); CPPUNIT_ASSERT_EQUAL (0, dst1->output_signature()->max_streams ()); @@ -72,7 +72,7 @@ qa_gr_block::t1 () CPPUNIT_ASSERT_EQUAL (std::string ("null_sink"), dst2->name ()); CPPUNIT_ASSERT_EQUAL (1, dst2->input_signature()->min_streams ()); CPPUNIT_ASSERT_EQUAL (1, dst2->input_signature()->max_streams ()); - CPPUNIT_ASSERT_EQUAL (sizeof (short), + CPPUNIT_ASSERT_EQUAL ((int) sizeof (short), dst2->input_signature()->sizeof_stream_item (0)); CPPUNIT_ASSERT_EQUAL (0, dst2->output_signature()->max_streams ()); } diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc index 766ea2f6b..b800b57b5 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc @@ -41,6 +41,6 @@ void qa_gr_hier_block2::test_make() CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->max_streams()); CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->min_streams()); CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->max_streams()); - CPPUNIT_ASSERT_EQUAL(sizeof(int), + CPPUNIT_ASSERT_EQUAL((int) sizeof(int), src1->output_signature()->sizeof_stream_item(0)); } diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc index ed32f9554..3b8976c6e 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc @@ -45,11 +45,20 @@ qa_gr_io_signature::t2 () gr_make_io_signature (3, gr_io_signature::IO_INFINITE, sizeof (int)); CPPUNIT_ASSERT_EQUAL (p->min_streams (), 3); - CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item (0), sizeof (int)); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item (0), (int) sizeof (int)); } void qa_gr_io_signature::t3 () { -} + gr_io_signature_sptr p = + gr_make_io_signature3 (0, 5, 1, 2, 3); + CPPUNIT_ASSERT_EQUAL (p->min_streams (), 0); + CPPUNIT_ASSERT_EQUAL (p->max_streams (), 5); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(0), 1); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(1), 2); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(2), 3); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(3), 3); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(4), 3); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h index ef14ab1cd..3b22105f6 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h @@ -41,7 +41,6 @@ class qa_gr_io_signature : public CppUnit::TestCase { void t1 (); void t2 (); void t3 (); - }; #endif /* INCLUDED_QA_GR_IO_SIGNATURE_H */ |