Added some more functions and fixed both flag paths.
parent
b281f62e24
commit
f2fff1936b
|
@ -163,14 +163,14 @@ namespace gtsam {
|
||||||
&ValuesCastHelper<ValueType, KeyValuePair, Values::KeyValuePair>::cast)), constBegin_(
|
&ValuesCastHelper<ValueType, KeyValuePair, Values::KeyValuePair>::cast)), constBegin_(
|
||||||
boost::make_transform_iterator(
|
boost::make_transform_iterator(
|
||||||
boost::make_filter_iterator(filter,
|
boost::make_filter_iterator(filter,
|
||||||
((const Values&) values).begin(),
|
values._begin(),
|
||||||
((const Values&) values).end()),
|
values._end()),
|
||||||
&ValuesCastHelper<ValueType, ConstKeyValuePair,
|
&ValuesCastHelper<ValueType, ConstKeyValuePair,
|
||||||
Values::ConstKeyValuePair>::cast)), constEnd_(
|
Values::ConstKeyValuePair>::cast)), constEnd_(
|
||||||
boost::make_transform_iterator(
|
boost::make_transform_iterator(
|
||||||
boost::make_filter_iterator(filter,
|
boost::make_filter_iterator(filter,
|
||||||
((const Values&) values).end(),
|
values._end(),
|
||||||
((const Values&) values).end()),
|
values._end()),
|
||||||
&ValuesCastHelper<ValueType, ConstKeyValuePair,
|
&ValuesCastHelper<ValueType, ConstKeyValuePair,
|
||||||
Values::ConstKeyValuePair>::cast)) {
|
Values::ConstKeyValuePair>::cast)) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,23 +187,36 @@ namespace gtsam {
|
||||||
/// @name Iterator
|
/// @name Iterator
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
struct const_iterator {
|
struct deref_iterator {
|
||||||
using const_iterator_type = typename KeyValueMap::const_iterator;
|
using const_iterator_type = typename KeyValueMap::const_iterator;
|
||||||
const_iterator_type it_;
|
const_iterator_type it_;
|
||||||
const_iterator(const_iterator_type it) : it_(it) {}
|
deref_iterator(const_iterator_type it) : it_(it) {}
|
||||||
std::pair<size_t, const Value&> operator*() const {
|
ConstKeyValuePair operator*() const { return {it_->first, *(it_->second)}; }
|
||||||
return {it_->first, *(it_->second)};
|
std::unique_ptr<ConstKeyValuePair> operator->() {
|
||||||
|
return std::make_unique<ConstKeyValuePair>(it_->first, *(it_->second));
|
||||||
}
|
}
|
||||||
bool operator==(const const_iterator& other) const { return it_ == other.it_; }
|
bool operator==(const deref_iterator& other) const {
|
||||||
bool operator!=(const const_iterator& other) const { return it_ != other.it_; }
|
return it_ == other.it_;
|
||||||
const_iterator& operator++() {
|
}
|
||||||
|
bool operator!=(const deref_iterator& other) const { return it_ != other.it_; }
|
||||||
|
deref_iterator& operator++() {
|
||||||
++it_;
|
++it_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const_iterator begin() { return const_iterator(values_.begin()); }
|
deref_iterator begin() const { return deref_iterator(values_.begin()); }
|
||||||
const_iterator end() { return const_iterator(values_.end()); }
|
deref_iterator end() const { return deref_iterator(values_.end()); }
|
||||||
|
|
||||||
|
/** Find an element by key, returning an iterator, or end() if the key was
|
||||||
|
* not found. */
|
||||||
|
deref_iterator find(Key j) const { return deref_iterator(values_.find(j)); }
|
||||||
|
|
||||||
|
/** Find the element greater than or equal to the specified key. */
|
||||||
|
deref_iterator lower_bound(Key j) const { return deref_iterator(values_.lower_bound(j)); }
|
||||||
|
|
||||||
|
/** Find the lowest-ordered element greater than the specified key. */
|
||||||
|
deref_iterator upper_bound(Key j) const { return deref_iterator(values_.upper_bound(j)); }
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Manifold Operations
|
/// @name Manifold Operations
|
||||||
|
@ -363,8 +376,8 @@ namespace gtsam {
|
||||||
static KeyValuePair make_deref_pair(const KeyValueMap::iterator::value_type& key_value) {
|
static KeyValuePair make_deref_pair(const KeyValueMap::iterator::value_type& key_value) {
|
||||||
return KeyValuePair(key_value.first, *key_value.second); }
|
return KeyValuePair(key_value.first, *key_value.second); }
|
||||||
|
|
||||||
const_iterator begin() const { return boost::make_transform_iterator(values_.begin(), &make_const_deref_pair); }
|
const_iterator _begin() const { return boost::make_transform_iterator(values_.begin(), &make_const_deref_pair); }
|
||||||
const_iterator end() const { return boost::make_transform_iterator(values_.end(), &make_const_deref_pair); }
|
const_iterator _end() const { return boost::make_transform_iterator(values_.end(), &make_const_deref_pair); }
|
||||||
iterator begin() { return boost::make_transform_iterator(values_.begin(), &make_deref_pair); }
|
iterator begin() { return boost::make_transform_iterator(values_.begin(), &make_deref_pair); }
|
||||||
iterator end() { return boost::make_transform_iterator(values_.end(), &make_deref_pair); }
|
iterator end() { return boost::make_transform_iterator(values_.end(), &make_deref_pair); }
|
||||||
const_reverse_iterator rbegin() const { return boost::make_transform_iterator(values_.rbegin(), &make_const_deref_pair); }
|
const_reverse_iterator rbegin() const { return boost::make_transform_iterator(values_.rbegin(), &make_const_deref_pair); }
|
||||||
|
@ -376,22 +389,12 @@ namespace gtsam {
|
||||||
* not found. */
|
* not found. */
|
||||||
iterator find(Key j) { return boost::make_transform_iterator(values_.find(j), &make_deref_pair); }
|
iterator find(Key j) { return boost::make_transform_iterator(values_.find(j), &make_deref_pair); }
|
||||||
|
|
||||||
/** Find an element by key, returning an iterator, or end() if the key was
|
|
||||||
* not found. */
|
|
||||||
const_iterator find(Key j) const { return boost::make_transform_iterator(values_.find(j), &make_const_deref_pair); }
|
|
||||||
|
|
||||||
/** Find the element greater than or equal to the specified key. */
|
/** Find the element greater than or equal to the specified key. */
|
||||||
iterator lower_bound(Key j) { return boost::make_transform_iterator(values_.lower_bound(j), &make_deref_pair); }
|
iterator lower_bound(Key j) { return boost::make_transform_iterator(values_.lower_bound(j), &make_deref_pair); }
|
||||||
|
|
||||||
/** Find the element greater than or equal to the specified key. */
|
|
||||||
const_iterator lower_bound(Key j) const { return boost::make_transform_iterator(values_.lower_bound(j), &make_const_deref_pair); }
|
|
||||||
|
|
||||||
/** Find the lowest-ordered element greater than the specified key. */
|
/** Find the lowest-ordered element greater than the specified key. */
|
||||||
iterator upper_bound(Key j) { return boost::make_transform_iterator(values_.upper_bound(j), &make_deref_pair); }
|
iterator upper_bound(Key j) { return boost::make_transform_iterator(values_.upper_bound(j), &make_deref_pair); }
|
||||||
|
|
||||||
/** Find the lowest-ordered element greater than the specified key. */
|
|
||||||
const_iterator upper_bound(Key j) const { return boost::make_transform_iterator(values_.upper_bound(j), &make_const_deref_pair); }
|
|
||||||
|
|
||||||
/** A filtered view of a Values, returned from Values::filter. */
|
/** A filtered view of a Values, returned from Values::filter. */
|
||||||
template <class ValueType = Value>
|
template <class ValueType = Value>
|
||||||
class Filtered;
|
class Filtered;
|
||||||
|
|
|
@ -203,7 +203,6 @@ TEST(Values, basic_functions)
|
||||||
}
|
}
|
||||||
EXPECT_LONGS_EQUAL(4, count);
|
EXPECT_LONGS_EQUAL(4, count);
|
||||||
|
|
||||||
#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
|
|
||||||
// find
|
// find
|
||||||
EXPECT_LONGS_EQUAL(4, values.find(4)->key);
|
EXPECT_LONGS_EQUAL(4, values.find(4)->key);
|
||||||
EXPECT_LONGS_EQUAL(4, values_c.find(4)->key);
|
EXPECT_LONGS_EQUAL(4, values_c.find(4)->key);
|
||||||
|
@ -219,7 +218,6 @@ TEST(Values, basic_functions)
|
||||||
EXPECT_LONGS_EQUAL(6, values_c.upper_bound(4)->key);
|
EXPECT_LONGS_EQUAL(6, values_c.upper_bound(4)->key);
|
||||||
EXPECT_LONGS_EQUAL(4, values.upper_bound(3)->key);
|
EXPECT_LONGS_EQUAL(4, values.upper_bound(3)->key);
|
||||||
EXPECT_LONGS_EQUAL(4, values_c.upper_bound(3)->key);
|
EXPECT_LONGS_EQUAL(4, values_c.upper_bound(3)->key);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue