Added conversion from Values::Filtered to Values::ConstFiltered and bug fix in Values::ConstFiltered
parent
c2947ea633
commit
908f2ac561
|
|
@ -124,20 +124,17 @@ namespace gtsam {
|
||||||
struct _KeyValuePair {
|
struct _KeyValuePair {
|
||||||
const Key key; ///< The key
|
const Key key; ///< The key
|
||||||
ValueType& value; ///< The value
|
ValueType& value; ///< The value
|
||||||
const Key& first; ///< For std::pair compatibility, the key
|
|
||||||
ValueType& second; ///< For std::pair compatibility, the value
|
|
||||||
|
|
||||||
_KeyValuePair(Key _key, ValueType& _value) : key(_key), value(_value), first(key), second(value) {}
|
_KeyValuePair(Key _key, ValueType& _value) : key(_key), value(_value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
struct _ConstKeyValuePair {
|
struct _ConstKeyValuePair {
|
||||||
const Key key; ///< The key
|
const Key key; ///< The key
|
||||||
const ValueType& value; ///< The value
|
const ValueType& value; ///< The value
|
||||||
const Key& first; ///< For std::pair compatibility, the key
|
|
||||||
const ValueType& second; ///< For std::pair compatibility, the value
|
|
||||||
|
|
||||||
_ConstKeyValuePair(Key _key, const Value& _value) : key(_key), value(_value), first(key), second(value) {}
|
_ConstKeyValuePair(Key _key, const ValueType& _value) : key(_key), value(_value) {}
|
||||||
|
_ConstKeyValuePair(const _KeyValuePair<ValueType>& rhs) : key(rhs.key), value(rhs.value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -150,13 +147,6 @@ namespace gtsam {
|
||||||
public:
|
public:
|
||||||
typedef _KeyValuePair<ValueType> KeyValuePair;
|
typedef _KeyValuePair<ValueType> KeyValuePair;
|
||||||
|
|
||||||
private:
|
|
||||||
typedef boost::transformed_range<
|
|
||||||
KeyValuePair(*)(Values::KeyValuePair key_value),
|
|
||||||
const boost::filtered_range<
|
|
||||||
boost::function<bool(const Values::ConstKeyValuePair&)>,
|
|
||||||
const boost::iterator_range<iterator> > > Base;
|
|
||||||
public:
|
|
||||||
/** Returns the number of values in this view */
|
/** Returns the number of values in this view */
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
typename Base::iterator it = this->begin();
|
typename Base::iterator it = this->begin();
|
||||||
|
|
@ -168,6 +158,12 @@ namespace gtsam {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
typedef boost::transformed_range<
|
||||||
|
KeyValuePair(*)(Values::KeyValuePair key_value),
|
||||||
|
const boost::filtered_range<
|
||||||
|
boost::function<bool(const Values::ConstKeyValuePair&)>,
|
||||||
|
const boost::iterator_range<iterator> > > Base;
|
||||||
|
|
||||||
Filtered(const Base& base) : Base(base) {}
|
Filtered(const Base& base) : Base(base) {}
|
||||||
|
|
||||||
friend class Values;
|
friend class Values;
|
||||||
|
|
@ -182,14 +178,16 @@ namespace gtsam {
|
||||||
public:
|
public:
|
||||||
typedef _ConstKeyValuePair<ValueType> KeyValuePair;
|
typedef _ConstKeyValuePair<ValueType> KeyValuePair;
|
||||||
|
|
||||||
private:
|
/** Conversion from Filtered<ValueType> to ConstFiltered<ValueType> */
|
||||||
typedef boost::transformed_range<
|
ConstFiltered(const Filtered<ValueType>& rhs) : Base(
|
||||||
KeyValuePair(*)(Values::ConstKeyValuePair key_value),
|
boost::adaptors::transform(
|
||||||
const boost::filtered_range<
|
boost::adaptors::filter(
|
||||||
boost::function<bool(const Values::ConstKeyValuePair&)>,
|
boost::make_iterator_range(
|
||||||
const boost::iterator_range<const_iterator> > > Base;
|
const_iterator(rhs.begin().base().base().base(), &make_const_deref_pair),
|
||||||
|
const_iterator(rhs.end().base().base().base(), &make_const_deref_pair)),
|
||||||
|
rhs.begin().base().predicate()),
|
||||||
|
&castHelper<const ValueType, _ConstKeyValuePair<ValueType>, ConstKeyValuePair>)) {}
|
||||||
|
|
||||||
public:
|
|
||||||
/** Returns the number of values in this view */
|
/** Returns the number of values in this view */
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
typename Base::const_iterator it = this->begin();
|
typename Base::const_iterator it = this->begin();
|
||||||
|
|
@ -201,6 +199,12 @@ namespace gtsam {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
typedef boost::transformed_range<
|
||||||
|
KeyValuePair(*)(Values::ConstKeyValuePair key_value),
|
||||||
|
const boost::filtered_range<
|
||||||
|
boost::function<bool(const Values::ConstKeyValuePair&)>,
|
||||||
|
const boost::iterator_range<const_iterator> > > Base;
|
||||||
|
|
||||||
ConstFiltered(const Base& base) : Base(base) {}
|
ConstFiltered(const Base& base) : Base(base) {}
|
||||||
|
|
||||||
friend class Values;
|
friend class Values;
|
||||||
|
|
|
||||||
|
|
@ -300,9 +300,9 @@ TEST(Values, filter) {
|
||||||
|
|
||||||
// Filter by type
|
// Filter by type
|
||||||
i = 0;
|
i = 0;
|
||||||
Values::Filtered<Pose3> pose_filtered = values.filter<Pose3>();
|
Values::ConstFiltered<Pose3> pose_filtered = values.filter<Pose3>();
|
||||||
EXPECT_LONGS_EQUAL(2, pose_filtered.size());
|
EXPECT_LONGS_EQUAL(2, pose_filtered.size());
|
||||||
BOOST_FOREACH(const Values::Filtered<Pose3>::KeyValuePair& key_value, pose_filtered) {
|
BOOST_FOREACH(const Values::ConstFiltered<Pose3>::KeyValuePair& key_value, pose_filtered) {
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
EXPECT_LONGS_EQUAL(1, key_value.key);
|
EXPECT_LONGS_EQUAL(1, key_value.key);
|
||||||
EXPECT(assert_equal(pose1, key_value.value));
|
EXPECT(assert_equal(pose1, key_value.value));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue