Re-implement ValidFramesReader and iterators
This commit is contained in:
parent
db45845619
commit
13cabcaab5
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
#include "query/v2/multiframe.hpp"
|
#include "query/v2/multiframe.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include "query/v2/bindings/frame.hpp"
|
#include "query/v2/bindings/frame.hpp"
|
||||||
#include "utils/pmr/vector.hpp"
|
#include "utils/pmr/vector.hpp"
|
||||||
|
|
||||||
@ -71,12 +74,23 @@ ValidFramesConsumer MultiFrame::GetValidFramesConsumer() { return ValidFramesCon
|
|||||||
|
|
||||||
InvalidFramesPopulator MultiFrame::GetInvalidFramesPopulator() { return InvalidFramesPopulator{*this}; }
|
InvalidFramesPopulator MultiFrame::GetInvalidFramesPopulator() { return InvalidFramesPopulator{*this}; }
|
||||||
|
|
||||||
ValidFramesReader::ValidFramesReader(MultiFrame &multiframe) : multiframe_(multiframe) {}
|
ValidFramesReader::ValidFramesReader(MultiFrame &multiframe) : multiframe_(multiframe) {
|
||||||
|
/*
|
||||||
|
From: https://en.cppreference.com/w/cpp/algorithm/find
|
||||||
|
Returns an iterator to the first element in the range [first, last) that satisfies specific criteria:
|
||||||
|
find_if searches for an element for which predicate p returns true
|
||||||
|
Return value
|
||||||
|
Iterator to the first element satisfying the condition or last if no such element is found.
|
||||||
|
|
||||||
|
-> this is what we want. We want the "after" last valid frame (weather this is vector::end or and invalid frame).
|
||||||
|
*/
|
||||||
|
auto it = std::find_if(multiframe.frames_.begin(), multiframe.frames_.end(),
|
||||||
|
[](const auto &frame) { return !frame.IsValid(); });
|
||||||
|
after_last_valid_frame_ = multiframe_.frames_.data() + std::distance(multiframe.frames_.begin(), it);
|
||||||
|
}
|
||||||
|
|
||||||
ValidFramesReader::Iterator ValidFramesReader::begin() { return Iterator{&multiframe_.frames_[0], *this}; }
|
ValidFramesReader::Iterator ValidFramesReader::begin() { return Iterator{&multiframe_.frames_[0], *this}; }
|
||||||
ValidFramesReader::Iterator ValidFramesReader::end() {
|
ValidFramesReader::Iterator ValidFramesReader::end() { return Iterator{after_last_valid_frame_, *this}; }
|
||||||
return Iterator{multiframe_.frames_.data() + multiframe_.frames_.size(), *this};
|
|
||||||
}
|
|
||||||
|
|
||||||
ValidFramesModifier::ValidFramesModifier(MultiFrame &multiframe) : multiframe_(multiframe) {}
|
ValidFramesModifier::ValidFramesModifier(MultiFrame &multiframe) : multiframe_(multiframe) {}
|
||||||
|
|
||||||
|
@ -107,18 +107,14 @@ class ValidFramesReader {
|
|||||||
using pointer = value_type *;
|
using pointer = value_type *;
|
||||||
using reference = const Frame &;
|
using reference = const Frame &;
|
||||||
|
|
||||||
Iterator(FrameWithValidity *ptr, ValidFramesReader &iterator_wrapper)
|
explicit Iterator(FrameWithValidity *ptr, ValidFramesReader &iterator_wrapper) : ptr_(ptr) {}
|
||||||
: ptr_(ptr), iterator_wrapper_(&iterator_wrapper) {}
|
|
||||||
|
|
||||||
reference operator*() const { return *ptr_; }
|
reference operator*() const { return *ptr_; }
|
||||||
pointer operator->() { return ptr_; }
|
pointer operator->() { return ptr_; }
|
||||||
|
|
||||||
// Prefix increment
|
// Prefix increment
|
||||||
Iterator &operator++() {
|
Iterator &operator++() {
|
||||||
do {
|
ptr_++;
|
||||||
ptr_++;
|
|
||||||
} while (*this != iterator_wrapper_->end() && !ptr_->IsValid());
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,13 +123,13 @@ class ValidFramesReader {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
FrameWithValidity *ptr_;
|
FrameWithValidity *ptr_;
|
||||||
ValidFramesReader *iterator_wrapper_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Iterator begin();
|
Iterator begin();
|
||||||
Iterator end();
|
Iterator end();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
FrameWithValidity *after_last_valid_frame_;
|
||||||
MultiFrame &multiframe_;
|
MultiFrame &multiframe_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user