28#include <gtsam/base/GenericValue.h>
29#include <gtsam/base/VectorSpace.h>
31#include <boost/ptr_container/serialize_ptr_map.hpp>
32#include <boost/shared_ptr.hpp>
33#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
34#include <boost/iterator/transform_iterator.hpp>
35#include <boost/iterator/filter_iterator.hpp>
45 class ValueAutomaticCasting;
46 template<
typename T>
static bool _truePredicate(
const T&) {
return true; }
74 typedef boost::ptr_map<
79 KeyValuePtrPairAllocator > KeyValueMap;
109 typedef KeyValuePair value_type;
128 Values(std::initializer_list<ConstKeyValuePair> init);
138 void print(
const std::string& str =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
141 bool equals(
const Values& other,
double tol=1e-9)
const;
155 template <
typename ValueType>
156 const ValueType at(
Key j)
const;
159 double atDouble(
size_t key)
const {
return at<double>(key);}
171 bool exists(
Key j)
const;
177 template<
typename ValueType>
178 boost::optional<const ValueType&> exists(
Key j)
const;
181 size_t size()
const {
return values_.size(); }
184 bool empty()
const {
return values_.empty(); }
191 using const_iterator_type =
typename KeyValueMap::const_iterator;
192 const_iterator_type it_;
195 boost::shared_ptr<ConstKeyValuePair> operator->() {
196 return boost::make_shared<ConstKeyValuePair>(it_->first, *(it_->second));
199 return it_ == other.it_;
209 deref_iterator end()
const {
return deref_iterator(values_.end()); }
240 void insert(
Key j,
const Value& val);
243 void insert(
const Values& values);
248 template <
typename ValueType>
249 void insert(
Key j,
const ValueType& val);
255 void update(
Key j,
const Value& val);
261 template <
typename T>
265 void update(
const Values& values);
268 void insert_or_assign(
Key j,
const Value& val);
274 void insert_or_assign(
const Values& values);
277 template <
typename ValueType>
278 void insert_or_assign(
Key j,
const ValueType& val);
307 std::map<Key,size_t> dims()
const;
313 template<
class ValueType>
314 size_t count()
const {
316 for (
const auto key_value : values_) {
342 template <
class ValueType>
343 std::map<Key, ValueType>
344 extract(
const std::function<
bool(Key)>& filterFcn = &_truePredicate<Key>)
const;
346#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
348 typedef KeyValueMap::const_iterator::value_type ConstKeyValuePtrPair;
349 typedef KeyValueMap::iterator::value_type KeyValuePtrPair;
352 typedef boost::transform_iterator<
353 std::function<KeyValuePair(
const KeyValuePtrPair&)>, KeyValueMap::iterator> iterator;
356 typedef boost::transform_iterator<
357 std::function<ConstKeyValuePair(
const ConstKeyValuePtrPair&)>, KeyValueMap::const_iterator> const_iterator;
360 typedef boost::transform_iterator<
361 std::function<KeyValuePair(
const KeyValuePtrPair&)>, KeyValueMap::reverse_iterator> reverse_iterator;
364 typedef boost::transform_iterator<
365 std::function<ConstKeyValuePair(
const ConstKeyValuePtrPair&)>, KeyValueMap::const_reverse_iterator> const_reverse_iterator;
371 std::pair<iterator, bool> tryInsert(Key j,
const Value& value);
373 static ConstKeyValuePair make_const_deref_pair(
const KeyValueMap::const_iterator::value_type& key_value) {
374 return ConstKeyValuePair(key_value.first, *key_value.second); }
376 static KeyValuePair make_deref_pair(
const KeyValueMap::iterator::value_type& key_value) {
377 return KeyValuePair(key_value.first, *key_value.second); }
379 const_iterator _begin()
const {
return boost::make_transform_iterator(values_.begin(), &make_const_deref_pair); }
380 const_iterator _end()
const {
return boost::make_transform_iterator(values_.end(), &make_const_deref_pair); }
381 iterator begin() {
return boost::make_transform_iterator(values_.begin(), &make_deref_pair); }
382 iterator end() {
return boost::make_transform_iterator(values_.end(), &make_deref_pair); }
383 const_reverse_iterator rbegin()
const {
return boost::make_transform_iterator(values_.rbegin(), &make_const_deref_pair); }
384 const_reverse_iterator rend()
const {
return boost::make_transform_iterator(values_.rend(), &make_const_deref_pair); }
385 reverse_iterator rbegin() {
return boost::make_transform_iterator(values_.rbegin(), &make_deref_pair); }
386 reverse_iterator rend() {
return boost::make_transform_iterator(values_.rend(), &make_deref_pair); }
390 iterator find(Key j) {
return boost::make_transform_iterator(values_.find(j), &make_deref_pair); }
393 iterator lower_bound(Key j) {
return boost::make_transform_iterator(values_.lower_bound(j), &make_deref_pair); }
396 iterator upper_bound(Key j) {
return boost::make_transform_iterator(values_.upper_bound(j), &make_deref_pair); }
399 template <
class ValueType = Value>
403 template <
class ValueType = Value>
407 template <
class ValueType>
408 Values(
const Filtered<ValueType>& view);
411 template <
class ValueType>
412 Values(
const ConstFiltered<ValueType>& view);
415 Filtered<Value> GTSAM_DEPRECATED
416 filter(
const std::function<
bool(Key)>& filterFcn);
419 template <
class ValueType>
420 Filtered<ValueType> GTSAM_DEPRECATED
421 filter(
const std::function<
bool(Key)>& filterFcn = &_truePredicate<Key>);
424 ConstFiltered<Value> GTSAM_DEPRECATED
425 filter(
const std::function<
bool(Key)>& filterFcn)
const;
428 template <
class ValueType>
429 ConstFiltered<ValueType> GTSAM_DEPRECATED filter(
430 const std::function<
bool(Key)>& filterFcn = &_truePredicate<Key>)
const;
436 template<
class ValueType>
437 static bool filterHelper(
const std::function<
bool(Key)> filter,
const ConstKeyValuePair& key_value) {
438 BOOST_STATIC_ASSERT((!boost::is_same<ValueType, Value>::value));
440 return filter(key_value.key) && (
dynamic_cast<const GenericValue<ValueType>*
>(&key_value.value));
444 friend class boost::serialization::access;
445 template<
class ARCHIVE>
446 void serialize(ARCHIVE & ar,
const unsigned int ) {
447 ar & BOOST_SERIALIZATION_NVP(values_);
458 mutable std::string message_;
471 GTSAM_EXPORT
const char*
what() const noexcept override;
481 mutable std::string message_;
486 operation_(operation),
key_(
key) {}
494 GTSAM_EXPORT
const char*
what() const noexcept override;
501 const std::type_info& storedTypeId_;
502 const std::type_info& requestedTypeId_;
505 mutable std::string message_;
510 const std::type_info& storedTypeId,
const std::type_info& requestedTypeId) noexcept :
511 key_(
key), storedTypeId_(storedTypeId), requestedTypeId_(requestedTypeId) {}
525 GTSAM_EXPORT
const char*
what() const noexcept override;
536 const char*
what()
const noexcept override {
537 return "The Values 'this' and the argument passed to Values::localCoordinates have mismatched keys and values";
545 const size_t M1_, N1_;
546 const size_t M2_, N2_;
549 mutable std::string message_;
553 M1_(M1), N1_(N1), M2_(M2), N2_(N2) {
559 GTSAM_EXPORT
const char* what()
const noexcept override;
571#include <gtsam/nonlinear/Values-inl.h>
An easy way to control which allocator is used for Fast* collections.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition Point2.h:47
bool operator!=(const Matrix &A, const Matrix &B)
inequality
Definition Matrix.h:107
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition Matrix.h:100
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
Default allocator for list, map, and set types.
Definition FastDefaultAllocator.h:50
Wraps any type T so it can play as a Value.
Definition GenericValue.h:47
Template to create a binary predicate.
Definition Testable.h:111
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
This is the base class for any type to be stored in Values.
Definition Value.h:37
virtual void deallocate_() const =0
Deallocate a raw pointer of this value.
virtual Value * clone_() const =0
Clone this value in a special memory pool, must be deleted with Value::deallocate_,...
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:74
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
void update(Key j, const T &val)
Templated version to update a variable with the given j, throws KeyDoesNotExist<J> if j is not presen...
bool empty() const
whether the config is empty
Definition Values.h:184
deref_iterator upper_bound(Key j) const
Find the lowest-ordered element greater than the specified key.
Definition Values.h:219
boost::shared_ptr< Values > shared_ptr
A shared_ptr to this class.
Definition Values.h:87
void clear()
Remove all variables from the config.
Definition Values.h:301
void swap(Values &other)
Swap the contents of two Values without copying data.
Definition Values.h:298
void insertDouble(Key j, double c)
version for double
Definition Values.h:252
size_t size() const
The number of variables in this config.
Definition Values.h:181
deref_iterator find(Key j) const
Find an element by key, returning an iterator, or end() if the key was not found.
Definition Values.h:213
boost::shared_ptr< const Values > const_shared_ptr
A const shared_ptr to this class.
Definition Values.h:90
Values()=default
Default constructor creates an empty Values class.
deref_iterator lower_bound(Key j) const
Find the element greater than or equal to the specified key.
Definition Values.h:216
double atDouble(size_t key) const
version for double
Definition Values.h:159
A key-value pair, which you get by dereferencing iterators.
Definition Values.h:93
Value & value
The value.
Definition Values.h:95
const Key key
The key.
Definition Values.h:94
A key-value pair, which you get by dereferencing iterators.
Definition Values.h:101
const Key key
The key.
Definition Values.h:102
const Value & value
The value.
Definition Values.h:103
const Key key_
The key that already existed.
Definition Values.h:455
GTSAM_EXPORT const char * what() const noexcept override
The message to be displayed to the user.
Definition Values.cpp:280
ValuesKeyAlreadyExists(Key key) noexcept
Construct with the key-value pair attempted to be added.
Definition Values.h:462
Key key() const noexcept
The duplicate key that was attempted to be added.
Definition Values.h:468
ValuesKeyDoesNotExist(const char *operation, Key key) noexcept
Construct with the key that does not exist in the values.
Definition Values.h:485
const Key key_
The key that does not exist.
Definition Values.h:478
Key key() const noexcept
The key that was attempted to be accessed that does not exist.
Definition Values.h:491
const char * operation_
The operation that attempted to access the key.
Definition Values.h:477
const std::type_info & storedTypeId() const
The typeid of the value stores in the Values.
Definition Values.h:519
Key key() const noexcept
The key that was attempted to be accessed that does not exist.
Definition Values.h:516
const Key key_
The key requested.
Definition Values.h:500
ValuesIncorrectType(Key key, const std::type_info &storedTypeId, const std::type_info &requestedTypeId) noexcept
Construct with the key that does not exist in the values.
Definition Values.h:509
const std::type_info & requestedTypeId() const
The requested typeid.
Definition Values.h:522
The Factor::error simply extracts the.
In nonlinear factors, the error function returns the negative log-likelihood as a non-linear function...