* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include <boost/bind.hpp>
-
-#include <assert.h>
-
-#include "rowdata.h"
+#include <pv/data/decode/decoder.hpp>
+#include <pv/data/decode/row.hpp>
+#include <pv/data/decode/rowdata.hpp>
using std::vector;
namespace data {
namespace decode {
-RowData::RowData()
+RowData::RowData(Row* row) :
+ row_(row)
{
+ assert(row);
}
uint64_t RowData::get_max_sample() const
{
- if (_annotations.empty())
+ if (annotations_.empty())
return 0;
- return _annotations.back().end_sample();
-}
-
-void RowData::get_annotation_subset(
- std::vector<pv::data::decode::Annotation> &dest,
- uint64_t start_sample, uint64_t end_sample) const
-{
- const vector<size_t>::const_iterator start_iter =
- lower_bound(_ann_end_index.begin(),
- _ann_end_index.end(), start_sample,
- bind(&RowData::index_entry_end_sample_lt,
- this, _1, _2));
-
- const vector<size_t>::const_iterator end_iter =
- upper_bound(_ann_start_index.begin(),
- _ann_start_index.end(), end_sample,
- bind(&RowData::index_entry_start_sample_gt,
- this, _1, _2));
-
- for (vector<size_t>::const_iterator i = start_iter;
- i != _ann_end_index.end() && *i != *end_iter; i++)
- dest.push_back(_annotations[*i]);
+ return annotations_.back().end_sample();
}
-void RowData::push_annotation(const Annotation &a)
+uint64_t RowData::get_annotation_count() const
{
- const size_t offset = _annotations.size();
- _annotations.push_back(a);
-
- // Insert the annotation into the start index
- vector<size_t>::iterator i = _ann_start_index.end();
- if (!_ann_start_index.empty() &&
- _annotations[_ann_start_index.back()].start_sample() >
- a.start_sample())
- i = upper_bound(_ann_start_index.begin(),
- _ann_start_index.end(), a.start_sample(),
- bind(&RowData::index_entry_start_sample_gt,
- this, _1, _2));
-
- _ann_start_index.insert(i, offset);
-
- // Insert the annotation into the end index
- vector<size_t>::iterator j = _ann_end_index.end();
- if (!_ann_end_index.empty() &&
- _annotations[_ann_end_index.back()].end_sample() <
- a.end_sample())
- j = upper_bound(_ann_end_index.begin(),
- _ann_end_index.end(), a.end_sample(),
- bind(&RowData::index_entry_end_sample_gt,
- this, _1, _2));
-
- _ann_end_index.insert(j, offset);
+ return annotations_.size();
}
-bool RowData::index_entry_start_sample_gt(
- const uint64_t sample, const size_t index) const
-{
- assert(index < _annotations.size());
- return _annotations[index].start_sample() > sample;
-}
-
-bool RowData::index_entry_end_sample_lt(
- const size_t index, const uint64_t sample) const
+void RowData::get_annotation_subset(
+ vector<pv::data::decode::Annotation> &dest,
+ uint64_t start_sample, uint64_t end_sample) const
{
- assert(index < _annotations.size());
- return _annotations[index].end_sample() < sample;
+ // Determine whether we must apply per-class filtering or not
+ bool all_ann_classes_enabled = true;
+ bool all_ann_classes_disabled = true;
+
+ uint32_t max_ann_class_id = 0;
+ for (AnnotationClass* c : row_->ann_classes()) {
+ if (!c->visible)
+ all_ann_classes_enabled = false;
+ else
+ all_ann_classes_disabled = false;
+ if (c->id > max_ann_class_id)
+ max_ann_class_id = c->id;
+ }
+
+ if (all_ann_classes_enabled) {
+ // No filtering, send everyting out as-is
+ for (const auto& annotation : annotations_)
+ if ((annotation.end_sample() > start_sample) &&
+ (annotation.start_sample() <= end_sample))
+ dest.push_back(annotation);
+ } else {
+ if (!all_ann_classes_disabled) {
+ // Filter out invisible annotation classes
+ vector<size_t> class_visible;
+ class_visible.resize(max_ann_class_id + 1, 0);
+ for (AnnotationClass* c : row_->ann_classes())
+ if (c->visible)
+ class_visible[c->id] = 1;
+
+ for (const auto& annotation : annotations_)
+ if ((class_visible[annotation.ann_class()]) &&
+ (annotation.end_sample() > start_sample) &&
+ (annotation.start_sample() <= end_sample))
+ dest.push_back(annotation);
+ }
+ }
}
-bool RowData::index_entry_end_sample_gt(
- const uint64_t sample, const size_t index) const
+void RowData::emplace_annotation(srd_proto_data *pdata)
{
- assert(index < _annotations.size());
- return _annotations[index].end_sample() > sample;
+ annotations_.emplace_back(pdata, row_);
}
-} // decode
-} // data
-} // pv
+} // namespace decode
+} // namespace data
+} // namespace pv