GNU Radio 3.7.2 C++ API
tag_checker.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013 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_RUNTIME_TAG_CHECKER_H
24 #define INCLUDED_GR_RUNTIME_TAG_CHECKER_H
25 
26 #include <vector>
27 #include <gnuradio/tags.h>
28 
29 namespace gr {
30 
32  {
33  public:
34  tag_checker(std::vector<tag_t> &tags)
35  {
36  d_tags = tags;
37  std::sort(d_tags.begin(), d_tags.end(), &gr::tag_t::offset_compare);
38  if(d_tags.size() > 0) {
39  d_has_next_tag = true;
40  d_next_tag_index = 0;
41  d_next_tag = tags[0];
42  }
43  };
44 
46 
47  void get_tags(std::vector<tag_t> &tag_list, unsigned int offset)
48  {
49  while(d_has_next_tag && (offset >= d_next_tag.offset)) {
50  if(offset == d_next_tag.offset) {
51  tag_list.push_back(d_next_tag);
52  }
53  d_next_tag_index += 1;
54  if(d_next_tag_index >= d_tags.size()) {
55  d_has_next_tag = false;
56  }
57  else {
58  d_next_tag = d_tags[d_next_tag_index];
59  }
60  }
61  };
62 
63  private:
64  std::vector<tag_t> d_tags;
65  tag_t d_next_tag;
66  unsigned int d_next_tag_index;
67  bool d_has_next_tag;
68  };
69 }
70 
71 #endif /* INCLUDED_GR_RUNTIME_TAG_CHECKER_H */
Definition: tags.h:31
static bool offset_compare(const tag_t &x, const tag_t &y)
Definition: tags.h:52
uint64_t offset
the item tag occurred at (as a uint64_t)
Definition: tags.h:34
void get_tags(std::vector< tag_t > &tag_list, unsigned int offset)
Definition: tag_checker.h:47
~tag_checker()
Definition: tag_checker.h:45
Definition: tag_checker.h:31
tag_checker(std::vector< tag_t > &tags)
Definition: tag_checker.h:34