28#include <gtsam/base/GenericValue.h>
29#include <gtsam/base/VectorSpace.h>
31#include <boost/iterator/transform_iterator.hpp>
32#include <boost/iterator/filter_iterator.hpp>
33#include <boost/ptr_container/serialize_ptr_map.hpp>
34#include <boost/shared_ptr.hpp>
43 class ValueAutomaticCasting;
44 template<
typename T>
static bool _truePredicate(
const T&) {
return true; }
72 typedef boost::ptr_map<
77 KeyValuePtrPairAllocator > KeyValueMap;
83 typedef KeyValueMap::const_iterator::value_type ConstKeyValuePtrPair;
84 typedef KeyValueMap::iterator::value_type KeyValuePtrPair;
112 typedef boost::transform_iterator<
116 typedef boost::transform_iterator<
120 typedef boost::transform_iterator<
124 typedef boost::transform_iterator<
130 template<
class ValueType = Value>
134 template<
class ValueType = Value>
151 Values(std::initializer_list<ConstKeyValuePair> init);
157 template<
class ValueType>
158 Values(
const Filtered<ValueType>& view);
161 template<
class ValueType>
162 Values(
const ConstFiltered<ValueType>& view);
168 void print(
const std::string& str =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
171 bool equals(
const Values& other,
double tol=1e-9)
const;
183 template <
typename ValueType>
184 const ValueType at(
Key j)
const;
187 double atDouble(
size_t key)
const {
return at<double>(key);}
199 bool exists(
Key j)
const;
205 template<
typename ValueType>
206 boost::optional<const ValueType&> exists(
Key j)
const;
210 iterator find(
Key j) {
return boost::make_transform_iterator(values_.find(j), &make_deref_pair); }
214 const_iterator find(
Key j)
const {
return boost::make_transform_iterator(values_.find(j), &make_const_deref_pair); }
229 size_t size()
const {
return values_.size(); }
232 bool empty()
const {
return values_.empty(); }
234 const_iterator begin()
const {
return boost::make_transform_iterator(values_.begin(), &make_const_deref_pair); }
235 const_iterator end()
const {
return boost::make_transform_iterator(values_.end(), &make_const_deref_pair); }
236 iterator begin() {
return boost::make_transform_iterator(values_.begin(), &make_deref_pair); }
237 iterator end() {
return boost::make_transform_iterator(values_.end(), &make_deref_pair); }
238 const_reverse_iterator rbegin()
const {
return boost::make_transform_iterator(values_.rbegin(), &make_const_deref_pair); }
239 const_reverse_iterator rend()
const {
return boost::make_transform_iterator(values_.rend(), &make_const_deref_pair); }
240 reverse_iterator rbegin() {
return boost::make_transform_iterator(values_.rbegin(), &make_deref_pair); }
241 reverse_iterator rend() {
return boost::make_transform_iterator(values_.rend(), &make_deref_pair); }
247 Values retract(
const VectorValues& delta)
const;
250 VectorValues localCoordinates(
const Values& cp)
const;
255 void insert(
Key j,
const Value& val);
258 void insert(
const Values& values);
263 template <
typename ValueType>
264 void insert(
Key j,
const ValueType& val);
273 std::pair<iterator, bool> tryInsert(
Key j,
const Value& value);
276 void update(
Key j,
const Value& val);
282 template <
typename T>
286 void update(
const Values& values);
326 filter(
const std::function<
bool(
Key)>& filterFcn);
347 template<
class ValueType>
349 filter(
const std::function<
bool(
Key)>& filterFcn = &_truePredicate<Key>);
365 filter(
const std::function<
bool(
Key)>& filterFcn)
const;
385 template<
class ValueType>
386 ConstFiltered<ValueType>
387 filter(
const std::function<
bool(
Key)>& filterFcn = &_truePredicate<Key>)
const;
390 template<
class ValueType>
391 size_t count()
const {
393 for (
const auto key_value : *
this) {
403 template<
class ValueType>
404 static bool filterHelper(
const std::function<
bool(
Key)> filter,
const ConstKeyValuePair& key_value) {
405 BOOST_STATIC_ASSERT((!boost::is_same<ValueType, Value>::value));
407 return filter(key_value.key) && (
dynamic_cast<const GenericValue<ValueType>*
>(&key_value.value));
411 friend class boost::serialization::access;
412 template<
class ARCHIVE>
413 void serialize(ARCHIVE & ar,
const unsigned int ) {
414 ar & BOOST_SERIALIZATION_NVP(values_);
417 static ConstKeyValuePair make_const_deref_pair(
const KeyValueMap::const_iterator::value_type& key_value) {
418 return ConstKeyValuePair(key_value.first, *key_value.second); }
420 static KeyValuePair make_deref_pair(
const KeyValueMap::iterator::value_type& key_value) {
421 return KeyValuePair(key_value.first, *key_value.second); }
431 mutable std::string message_;
444 GTSAM_EXPORT
const char*
what() const noexcept override;
454 mutable std::string message_;
459 operation_(operation),
key_(
key) {}
467 GTSAM_EXPORT
const char*
what() const noexcept override;
474 const std::type_info& storedTypeId_;
475 const std::type_info& requestedTypeId_;
478 mutable std::string message_;
483 const std::type_info& storedTypeId,
const std::type_info& requestedTypeId) noexcept :
484 key_(
key), storedTypeId_(storedTypeId), requestedTypeId_(requestedTypeId) {}
498 GTSAM_EXPORT
const char*
what() const noexcept override;
509 const char*
what()
const noexcept override {
510 return "The Values 'this' and the argument passed to Values::localCoordinates have mismatched keys and values";
518 const size_t M1_, N1_;
519 const size_t M2_, N2_;
522 mutable std::string message_;
526 M1_(M1), N1_(N1), M2_(M2), N2_(N2) {
532 GTSAM_EXPORT
const char*
what()
const noexcept override;
544#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
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:112
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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
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:36
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_,...
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:74
A filtered view of a Values, returned from Values::filter.
Definition: Values-inl.h:95
A filtered view of a const Values, returned from Values::filter.
Definition: Values-inl.h:169
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:63
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:232
iterator upper_bound(Key j)
Find the lowest-ordered element greater than the specified key.
Definition: Values.h:223
const_iterator upper_bound(Key j) const
Find the lowest-ordered element greater than the specified key.
Definition: Values.h:226
boost::transform_iterator< std::function< KeyValuePair(const KeyValuePtrPair &)>, KeyValueMap::reverse_iterator > reverse_iterator
Mutable reverse iterator, with value type KeyValuePair.
Definition: Values.h:121
boost::transform_iterator< std::function< ConstKeyValuePair(const ConstKeyValuePtrPair &)>, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
Definition: Values.h:117
boost::shared_ptr< Values > shared_ptr
A shared_ptr to this class.
Definition: Values.h:89
void clear()
Remove all variables from the config.
Definition: Values.h:304
const_iterator find(Key j) const
Find an element by key, returning an iterator, or end() if the key was not found.
Definition: Values.h:214
const_iterator lower_bound(Key j) const
Find the element greater than or equal to the specified key.
Definition: Values.h:220
boost::transform_iterator< std::function< ConstKeyValuePair(const ConstKeyValuePtrPair &)>, KeyValueMap::const_reverse_iterator > const_reverse_iterator
Const reverse iterator, with value type ConstKeyValuePair.
Definition: Values.h:125
void swap(Values &other)
Swap the contents of two Values without copying data.
Definition: Values.h:301
void insertDouble(Key j, double c)
version for double
Definition: Values.h:267
size_t size() const
The number of variables in this config.
Definition: Values.h:229
iterator find(Key j)
Find an element by key, returning an iterator, or end() if the key was not found.
Definition: Values.h:210
boost::shared_ptr< const Values > const_shared_ptr
A const shared_ptr to this class.
Definition: Values.h:92
Values()
Default constructor creates an empty Values class.
Definition: Values.h:138
iterator lower_bound(Key j)
Find the element greater than or equal to the specified key.
Definition: Values.h:217
boost::transform_iterator< std::function< KeyValuePair(const KeyValuePtrPair &)>, KeyValueMap::iterator > iterator
Mutable forward iterator, with value type KeyValuePair.
Definition: Values.h:113
double atDouble(size_t key) const
version for double
Definition: Values.h:187
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:95
Value & value
The value.
Definition: Values.h:97
const Key key
The key.
Definition: Values.h:96
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:103
const Key key
The key.
Definition: Values.h:104
const Value & value
The value.
Definition: Values.h:105
const Key key_
The key that already existed.
Definition: Values.h:428
GTSAM_EXPORT const char * what() const noexcept override
The message to be displayed to the user.
Definition: Values.cpp:216
ValuesKeyAlreadyExists(Key key) noexcept
Construct with the key-value pair attempted to be added.
Definition: Values.h:435
Key key() const noexcept
The duplicate key that was attempted to be added.
Definition: Values.h:441
ValuesKeyDoesNotExist(const char *operation, Key key) noexcept
Construct with the key that does not exist in the values.
Definition: Values.h:458
const Key key_
The key that does not exist.
Definition: Values.h:451
Key key() const noexcept
The key that was attempted to be accessed that does not exist.
Definition: Values.h:464
const char * operation_
The operation that attempted to access the key.
Definition: Values.h:450
const std::type_info & storedTypeId() const
The typeid of the value stores in the Values.
Definition: Values.h:492
Key key() const noexcept
The key that was attempted to be accessed that does not exist.
Definition: Values.h:489
const Key key_
The key requested.
Definition: Values.h:473
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:482
const std::type_info & requestedTypeId() const
The requested typeid.
Definition: Values.h:495