diff options
author | Tom Rondeau | 2010-10-31 18:06:39 -0400 |
---|---|---|
committer | Tom Rondeau | 2010-10-31 18:06:39 -0400 |
commit | 13f00f0ad96ee54a98751f9dceca005078850c93 (patch) | |
tree | 8a6d9c101dc16fc9e5999a0f87b104f06fb9dea8 /gnuradio-core/src/lib | |
parent | 246c0b96f22b3eb945fb1cef1aafd32bbb7cd815 (diff) | |
download | gnuradio-13f00f0ad96ee54a98751f9dceca005078850c93.tar.gz gnuradio-13f00f0ad96ee54a98751f9dceca005078850c93.tar.bz2 gnuradio-13f00f0ad96ee54a98751f9dceca005078850c93.zip |
Checks for duplicate entry when adding a new tag.
add_item_tag looks at the last tag entered with the given key and tests if the value is the same. If it is the same value, then don't do add a new item. If the value is different, add a new tag of that key to the list.
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block_detail.cc | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 69f65f0d0..1007f13ef 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -142,18 +142,38 @@ gr_block_detail::_post(pmt::pmt_t msg) void gr_block_detail::add_item_tag(unsigned int which_output, gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value) + const pmt::pmt_t &key, + const pmt::pmt_t &value) { if(pmt::pmt_is_symbol(key) == false) { throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { - pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); - pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); - pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); - d_item_tags.push_back(tuple); + bool duplicate = false; + + // Search through list of tags to see if new tag is a duplicate + std::list<pmt::pmt_t>::reverse_iterator itr = d_item_tags.rbegin(); + while(itr != d_item_tags.rend()) { + // find the last item with this key if there is one + if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 2), key)) { + // check if this value is the same as last; its a duplicate if yes + if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 3), value)) { + duplicate = true; + } + break; // only looking for the last item of this key + } + itr++; + } + + // It not a duplicate, add new tag to the list + if(!duplicate) { + pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); + pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); + pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); + d_item_tags.push_back(tuple); + } - // need to add prunning routing + // need to add prunning routine } } |