28#include <boost/bind/bind.hpp>
35 template<
class ValueType>
44 template<
class ValueType>
61 template<
class ValueType,
class CastedKeyValuePairType,
class KeyValuePairType>
63 static CastedKeyValuePairType cast(KeyValuePairType key_value) {
65 return CastedKeyValuePairType(key_value.key,
67 ValueType
>&>(key_value.value)).
value());
71 template<
class CastedKeyValuePairType,
class KeyValuePairType>
73 static CastedKeyValuePairType cast(KeyValuePairType key_value) {
77 return CastedKeyValuePairType(key_value.key, key_value.value);
81 template<
class CastedKeyValuePairType,
class KeyValuePairType>
83 static CastedKeyValuePairType cast(KeyValuePairType key_value) {
87 return CastedKeyValuePairType(key_value.key, key_value.value);
92 template <
class ValueType>
93 std::map<Key, ValueType>
95 std::map<Key, ValueType> result;
96 for (
const auto& key_value : values_) {
98 if (filterFcn(key_value.first)) {
102 result[key_value.first] = t->value();
109#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
110#include <boost/bind/bind.hpp>
112 template<
class ValueType>
113 class Values::Filtered {
118 typedef KeyValuePair value_type;
121 boost::transform_iterator<
123 boost::filter_iterator<
128 typedef iterator const_iterator;
131 boost::transform_iterator<
133 boost::filter_iterator<
135 Values::const_iterator> >
136 const_const_iterator;
138 iterator begin() {
return begin_; }
139 iterator end() {
return end_; }
140 const_iterator begin()
const {
return begin_; }
141 const_iterator end()
const {
return end_; }
142 const_const_iterator beginConst()
const {
return constBegin_; }
143 const_const_iterator endConst()
const {
return constEnd_; }
146 size_t size()
const {
148 for (const_const_iterator it = beginConst(); it != endConst(); ++it)
155 const std::function<
bool(
const Values::ConstKeyValuePair&)>& filter,
158 boost::make_transform_iterator(
159 boost::make_filter_iterator(filter, values.begin(), values.end()),
160 &ValuesCastHelper<ValueType, KeyValuePair,
Values::KeyValuePair>::cast)), end_(
161 boost::make_transform_iterator(
162 boost::make_filter_iterator(filter, values.end(), values.end()),
163 &ValuesCastHelper<ValueType, KeyValuePair,
Values::KeyValuePair>::cast)), constBegin_(
164 boost::make_transform_iterator(
165 boost::make_filter_iterator(filter,
168 &ValuesCastHelper<ValueType, ConstKeyValuePair,
169 Values::ConstKeyValuePair>::cast)), constEnd_(
170 boost::make_transform_iterator(
171 boost::make_filter_iterator(filter,
174 &ValuesCastHelper<ValueType, ConstKeyValuePair,
175 Values::ConstKeyValuePair>::cast)) {
181 const_const_iterator constBegin_;
182 const_const_iterator constEnd_;
185 template<
class ValueType>
186 class Values::ConstFiltered {
189 typedef _ValuesConstKeyValuePair<ValueType> KeyValuePair;
190 typedef KeyValuePair value_type;
192 typedef typename Filtered<ValueType>::const_const_iterator iterator;
193 typedef typename Filtered<ValueType>::const_const_iterator const_iterator;
196 ConstFiltered(
const Filtered<ValueType>& rhs) :
197 begin_(rhs.beginConst()),
198 end_(rhs.endConst()) {}
200 iterator begin() {
return begin_; }
201 iterator end() {
return end_; }
202 const_iterator begin()
const {
return begin_; }
203 const_iterator end()
const {
return end_; }
206 size_t size()
const {
208 for (const_iterator it = begin(); it != end(); ++it)
213 FastList<Key> keys()
const {
214 FastList<Key> result;
215 for(const_iterator it = begin(); it != end(); ++it)
216 result.push_back(it->key);
222 const_iterator begin_;
225 const std::function<
bool(
const Values::ConstKeyValuePair&)>& filter,
229 const Filtered<ValueType> filtered(filter,
const_cast<Values&
>(values));
230 begin_ = filtered.beginConst();
231 end_ = filtered.endConst();
235 template<
class ValueType>
237 for(
const auto key_value: view) {
238 Key key = key_value.key;
239 insert(key,
static_cast<const ValueType&
>(key_value.value));
243 template<
class ValueType>
245 for(
const auto key_value: view) {
246 Key key = key_value.key;
247 insert(key,
static_cast<const ValueType&
>(key_value.value));
251 Values::Filtered<Value>
252 inline Values::filter(
const std::function<
bool(
Key)>& filterFcn) {
253 return filter<Value>(filterFcn);
256 template<
class ValueType>
257 Values::Filtered<ValueType>
258 Values::filter(
const std::function<
bool(
Key)>& filterFcn) {
259 return Filtered<ValueType>(std::bind(&filterHelper<ValueType>, filterFcn,
260 std::placeholders::_1), *
this);
263 Values::ConstFiltered<Value>
264 inline Values::filter(
const std::function<
bool(
Key)>& filterFcn)
const {
265 return filter<Value>(filterFcn);
268 template<
class ValueType>
269 Values::ConstFiltered<ValueType>
270 Values::filter(
const std::function<
bool(
Key)>& filterFcn)
const {
271 return ConstFiltered<ValueType>(std::bind(&filterHelper<ValueType>,
272 filterFcn, std::placeholders::_1), *
this);
278 inline bool Values::filterHelper<Value>(
const std::function<
bool(
Key)> filter,
279 const ConstKeyValuePair& key_value) {
281 return filter(key_value.key);
290 template <
typename ValueType>
292 ValueType operator()(
Key j,
const Value*
const pointer) {
303 template <
typename MatrixType,
bool isDynamic>
307 template <
int M,
int N>
309 inline Eigen::Matrix<double, M, N> operator()(
Key j,
const Value*
const pointer) {
322 template <
int M,
int N>
324 inline Eigen::Matrix<double, M, N> operator()(
Key j,
const Value*
const pointer) {
340 if (A.rows() != M || A.cols() != N)
349 template <
int M,
int N>
350 struct handle<Eigen::Matrix<double, M, N>> {
351 Eigen::Matrix<double, M, N> operator()(
Key j,
const Value*
const pointer) {
353 (M == Eigen::Dynamic || N == Eigen::Dynamic)>()(j, pointer);
360 template <
typename ValueType>
363 KeyValueMap::const_iterator item = values_.find(j);
371 return h(j, item->second);
375 template<
typename ValueType>
378 KeyValueMap::const_iterator item = values_.find(j);
380 if(item != values_.end()) {
387 const Value* value = item->second;
398 template<
typename ValueType>
404 template <
typename ValueType>
410 template <
typename ValueType>
A non-templated config holding any types of Manifold-group elements.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
Wraps any type T so it can play as a Value.
Definition GenericValue.h:47
const T & value() const
Return a constant value.
Definition GenericValue.h:67
This is the base class for any type to be stored in Values.
Definition Value.h:37
Definition Values-inl.h:36
const Key key
The key.
Definition Values-inl.h:37
ValueType & value
The value.
Definition Values-inl.h:38
Definition Values-inl.h:45
const Key key
The key.
Definition Values-inl.h:46
const ValueType & value
The value.
Definition Values-inl.h:47
Definition Values-inl.h:62
Definition Values-inl.h:291
Definition Values-inl.h:304
void update(Key j, const Value &val)
single element change of existing element
Definition Values.cpp:180
std::map< Key, ValueType > extract(const std::function< bool(Key)> &filterFcn=&_truePredicate< Key >) const
Extract a subset of values of the given type ValueType.
Definition Values-inl.h:94
const ValueType at(Key j) const
Retrieve a variable by key j.
Definition Values-inl.h:361
void insert(Key j, const Value &val)
Add a variable with the given j, throws KeyAlreadyExists<J> if j is already present.
Definition Values.cpp:157
void insert_or_assign(Key j, const Value &val)
If key j exists, update value, else perform an insert.
Definition Values.cpp:203
Values()=default
Default constructor creates an empty Values class.
bool exists(Key j) const
Check if a value exists with key j.
Definition Values.cpp:94
A key-value pair, which you get by dereferencing iterators.
Definition Values.h:93
A key-value pair, which you get by dereferencing iterators.
Definition Values.h:101
In nonlinear factors, the error function returns the negative log-likelihood as a non-linear function...