Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ using boost::multi_index::tag;
* holding measurements of type T. See `wave::internal::measurement_container`.
*/
template <typename T>
struct landmark_container {
struct container_traits<::wave::LandmarkMeasurementContainer<T>> {
// Define to give MeasurementContainerBase access to its derived type
using MeasurementType = T;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need this? I see you're using T for the rest of this struct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. T does not persist outside of this definition. MeasurementType is defined so it can be used by MeasurementContainerBase, from outside of this definition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right...because Base is templated with either the landmark or regular measurement containers.

I was actually wondering about where MeasurementType was defined in the base class; that makes a bit more sense now. Thanks


// Then, set up boost::multi_index_container
// First, define which members of the Measurement object are used as keys
struct time_key : member<T, TimeType, &T::time_point> {};
struct sensor_key : member<T, decltype(T::sensor_id), &T::sensor_id> {};
Expand All @@ -38,18 +42,15 @@ struct landmark_container {
// multi_index_container is generated
struct time_index {};
struct sensor_index {};
struct sensor_composite_index {};
struct landmark_index {};
struct composite_index {};

// Define an index for each key. Each index will be accessible via its tag
struct indices
: indexed_by<
ordered_non_unique<tag<time_index>, time_key>,
ordered_non_unique<tag<sensor_index>, sensor_key>,
ordered_non_unique<tag<landmark_index>, landmark_key>,
ordered_unique<tag<composite_index>, combined_key>,
ordered_unique<tag<sensor_composite_index>, sensor_composite_key>> {};
: indexed_by<ordered_non_unique<tag<time_index>, time_key>,
ordered_non_unique<tag<landmark_index>, landmark_key>,
ordered_unique<tag<composite_index>, combined_key>,
ordered_unique<tag<sensor_index>, sensor_composite_key>> {};

// Finally, define the multi_index_container type.
// This is the container type which can actually be used to make objects
Expand All @@ -58,8 +59,7 @@ struct landmark_container {
// For convenience, get the type of the indices, using their tags
using composite_type = typename type::template index<composite_index>::type;
using time_type = typename type::template index<time_index>::type;
using sensor_composite_type =
typename type::template index<sensor_composite_index>::type;
using sensor_type = typename type::template index<sensor_index>::type;
using landmark_type = typename type::template index<landmark_index>::type;

// Define a view indexed by time, for complex searches
Expand All @@ -73,65 +73,6 @@ struct landmark_container {
template <typename T>
LandmarkMeasurementContainer<T>::LandmarkMeasurementContainer() {}


template <typename T>
template <typename InputIt>
LandmarkMeasurementContainer<T>::LandmarkMeasurementContainer(InputIt first,
InputIt last) {
this->composite().insert(first, last);
};

template <typename T>
std::pair<typename LandmarkMeasurementContainer<T>::iterator, bool>
LandmarkMeasurementContainer<T>::insert(const MeasurementType &m) {
return this->composite().insert(m);
}

template <typename T>
template <typename InputIt>
void LandmarkMeasurementContainer<T>::insert(InputIt first, InputIt last) {
return this->composite().insert(first, last);
}

template <typename T>
template <typename... Args>
std::pair<typename LandmarkMeasurementContainer<T>::iterator, bool>
LandmarkMeasurementContainer<T>::emplace(Args &&... args) {
// Support Boost.MultiIndex <= 1.54, which does not have emplace()
#if BOOST_VERSION < 105500
return this->composite().insert(
MeasurementType{std::forward<Args>(args)...});
#else
return this->composite().emplace(std::forward<Args>(args)...);
#endif
}

template <typename T>
typename LandmarkMeasurementContainer<T>::size_type
LandmarkMeasurementContainer<T>::erase(const TimeType &t,
SensorIdType s,
LandmarkIdType id) {
auto &composite = this->composite();
auto it = composite.find(boost::make_tuple(t, s, id));
if (it == composite.end()) {
return 0;
}
composite.erase(it);
return 1;
}

template <typename T>
typename LandmarkMeasurementContainer<T>::iterator
LandmarkMeasurementContainer<T>::erase(iterator position) noexcept {
return this->composite().erase(position);
}

template <typename T>
typename LandmarkMeasurementContainer<T>::iterator
LandmarkMeasurementContainer<T>::erase(iterator first, iterator last) noexcept {
return this->composite().erase(first, last);
}

template <typename T>
typename LandmarkMeasurementContainer<T>::ValueType
LandmarkMeasurementContainer<T>::get(const TimeType &t,
Expand All @@ -147,38 +88,6 @@ LandmarkMeasurementContainer<T>::get(const TimeType &t,
return iter->value;
}

template <typename T>
std::pair<typename LandmarkMeasurementContainer<T>::sensor_iterator,
typename LandmarkMeasurementContainer<T>::sensor_iterator>
LandmarkMeasurementContainer<T>::getAllFromSensor(const SensorIdType &s) const
noexcept {
// Get the measurements sorted by sensor_id
const auto &sensor_composite_index = this->storage.template get<
typename internal::landmark_container<T>::sensor_composite_index>();

return sensor_composite_index.equal_range(s);
};

template <typename T>
std::pair<typename LandmarkMeasurementContainer<T>::iterator,
typename LandmarkMeasurementContainer<T>::iterator>
LandmarkMeasurementContainer<T>::getTimeWindow(const TimeType &start,
const TimeType &end) const
noexcept {
// Consider a "backward" window empty
if (start > end) {
return {this->end(), this->end()};
}

// The composite index is already sorted by time first, thus it's enough to
// do a partial search. Find the start and end of the range.
const auto &composite = this->composite();
auto iter_begin = composite.lower_bound(boost::make_tuple(start));
auto iter_end = composite.upper_bound(boost::make_tuple(end));

return {iter_begin, iter_end};
}

template <typename T>
std::vector<typename LandmarkMeasurementContainer<T>::LandmarkIdType>
LandmarkMeasurementContainer<T>::getLandmarkIDs() const {
Expand All @@ -190,8 +99,8 @@ std::vector<typename LandmarkMeasurementContainer<T>::LandmarkIdType>
LandmarkMeasurementContainer<T>::getLandmarkIDsInWindow(
const TimeType &start, const TimeType &end) const {
// Use the index sorted by landmark id
const auto &landmark_index = this->storage.template get<
typename internal::landmark_container<T>::landmark_index>();
const auto &landmark_index =
this->storage.template get<typename traits::landmark_index>();
auto unique_ids = std::vector<LandmarkIdType>{};

// Iterate over all measurements sorted by time, first then landmark_id.
Expand Down Expand Up @@ -232,8 +141,8 @@ LandmarkMeasurementContainer<T>::getTrackInWindow(const SensorIdType &s,
return Track{};
}

const auto &landmark_index = this->storage.template get<
typename internal::landmark_container<T>::landmark_index>();
const auto &landmark_index =
this->storage.template get<typename traits::landmark_index>();

// Get all measurements with desired landmark id
const auto res = landmark_index.equal_range(id);
Expand All @@ -245,7 +154,7 @@ LandmarkMeasurementContainer<T>::getTrackInWindow(const SensorIdType &s,
// http://www.boost.org/doc/libs/1_63_0/libs/multi_index/doc/examples.html#example6
//
// While iterating, pick the measurements with desired sensor_id
auto time_view = typename internal::landmark_container<T>::time_view{};
auto time_view = typename traits::time_view{};
for (auto it = res.first; it != res.second; ++it) {
if (it->sensor_id == s) {
// insert a pointer to the measurement
Expand All @@ -266,70 +175,4 @@ LandmarkMeasurementContainer<T>::getTrackInWindow(const SensorIdType &s,
return track;
};

template <typename T>
bool LandmarkMeasurementContainer<T>::empty() const noexcept {
return this->composite().empty();
}

template <typename T>
typename LandmarkMeasurementContainer<T>::size_type
LandmarkMeasurementContainer<T>::size() const noexcept {
return this->composite().size();
}

template <typename T>
void LandmarkMeasurementContainer<T>::clear() noexcept {
return this->composite().clear();
}

template <typename T>
typename LandmarkMeasurementContainer<T>::iterator
LandmarkMeasurementContainer<T>::begin() noexcept {
return this->composite().begin();
}

template <typename T>
typename LandmarkMeasurementContainer<T>::iterator
LandmarkMeasurementContainer<T>::end() noexcept {
return this->composite().end();
}

template <typename T>
typename LandmarkMeasurementContainer<T>::const_iterator
LandmarkMeasurementContainer<T>::begin() const noexcept {
return this->composite().begin();
}

template <typename T>
typename LandmarkMeasurementContainer<T>::const_iterator
LandmarkMeasurementContainer<T>::end() const noexcept {
return this->composite().end();
}

template <typename T>
typename LandmarkMeasurementContainer<T>::const_iterator
LandmarkMeasurementContainer<T>::cbegin() const noexcept {
return this->composite().cbegin();
}

template <typename T>
typename LandmarkMeasurementContainer<T>::const_iterator
LandmarkMeasurementContainer<T>::cend() const noexcept {
return this->composite().cend();
}

template <typename T>
typename LandmarkMeasurementContainer<T>::composite_type &
LandmarkMeasurementContainer<T>::composite() noexcept {
return this->storage.template get<
typename internal::landmark_container<T>::composite_index>();
}

template <typename T>
const typename LandmarkMeasurementContainer<T>::composite_type &
LandmarkMeasurementContainer<T>::composite() const noexcept {
return this->storage.template get<
typename internal::landmark_container<T>::composite_index>();
}

} // namespace wave
Loading