27 #include <gtsam/base/GenericValue.h> 28 #include <gtsam/base/VectorSpace.h> 30 #include <boost/iterator/transform_iterator.hpp> 31 #include <boost/iterator/filter_iterator.hpp> 33 #pragma GCC diagnostic push 34 #pragma GCC diagnostic ignored "-Wunused-variable" 35 #pragma GCC diagnostic ignored "-Wunused-local-typedefs" 37 #include <boost/bind.hpp> 39 #pragma GCC diagnostic pop 41 #include <boost/ptr_container/serialize_ptr_map.hpp> 50 class ValueAutomaticCasting;
51 template<
typename T>
static bool _truePredicate(
const T&) {
return true; }
78 typedef boost::ptr_map<
83 boost::fast_pool_allocator<std::pair<const Key, void*> > > KeyValueMap;
89 typedef KeyValueMap::const_iterator::value_type ConstKeyValuePtrPair;
90 typedef KeyValueMap::iterator::value_type KeyValuePtrPair;
118 typedef boost::transform_iterator<
119 boost::function1<KeyValuePair, const KeyValuePtrPair&>, KeyValueMap::iterator>
iterator;
122 typedef boost::transform_iterator<
123 boost::function1<ConstKeyValuePair, const ConstKeyValuePtrPair&>, KeyValueMap::const_iterator>
const_iterator;
126 typedef boost::transform_iterator<
127 boost::function1<KeyValuePair, const KeyValuePtrPair&>, KeyValueMap::reverse_iterator>
reverse_iterator;
130 typedef boost::transform_iterator<
131 boost::function1<ConstKeyValuePair, const ConstKeyValuePtrPair&>, KeyValueMap::const_reverse_iterator>
const_reverse_iterator;
136 template<
class ValueType = Value>
140 template<
class ValueType = Value>
156 template<
class ValueType>
157 Values(
const Filtered<ValueType>& view);
160 template<
class ValueType>
161 Values(
const ConstFiltered<ValueType>& view);
167 void print(
const std::string& str =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
170 bool equals(
const Values& other,
double tol=1e-9)
const;
182 template<
typename ValueType>
183 ValueType at(
Key j)
const;
186 double atDouble(
size_t key)
const {
return at<double>(key);}
198 bool exists(
Key j)
const;
204 template<
typename ValueType>
205 boost::optional<const ValueType&> exists(
Key j)
const;
209 iterator find(
Key j) {
return boost::make_transform_iterator(values_.find(j), &make_deref_pair); }
213 const_iterator find(
Key j)
const {
return boost::make_transform_iterator(values_.find(j), &make_const_deref_pair); }
228 size_t size()
const {
return values_.size(); }
231 bool empty()
const {
return values_.empty(); }
233 const_iterator begin()
const {
return boost::make_transform_iterator(values_.begin(), &make_const_deref_pair); }
234 const_iterator end()
const {
return boost::make_transform_iterator(values_.end(), &make_const_deref_pair); }
235 iterator begin() {
return boost::make_transform_iterator(values_.begin(), &make_deref_pair); }
236 iterator end() {
return boost::make_transform_iterator(values_.end(), &make_deref_pair); }
237 const_reverse_iterator rbegin()
const {
return boost::make_transform_iterator(values_.rbegin(), &make_const_deref_pair); }
238 const_reverse_iterator rend()
const {
return boost::make_transform_iterator(values_.rend(), &make_const_deref_pair); }
239 reverse_iterator rbegin() {
return boost::make_transform_iterator(values_.rbegin(), &make_deref_pair); }
240 reverse_iterator rend() {
return boost::make_transform_iterator(values_.rend(), &make_deref_pair); }
246 Values retract(
const VectorValues& delta)
const;
249 VectorValues localCoordinates(
const Values& cp)
const;
254 void insert(
Key j,
const Value& val);
257 void insert(
const Values& values);
262 template <
typename ValueType>
263 void insert(
Key j,
const ValueType& val);
272 std::pair<iterator, bool> tryInsert(
Key j,
const Value& value);
275 void update(
Key j,
const Value& val);
281 template <
typename T>
282 void update(
Key j,
const T& val);
285 void update(
const Values& values);
325 filter(
const boost::function<
bool(
Key)>& filterFcn);
346 template<
class ValueType>
348 filter(
const boost::function<
bool(
Key)>& filterFcn = &_truePredicate<Key>);
364 filter(
const boost::function<
bool(
Key)>& filterFcn)
const;
384 template<
class ValueType>
385 ConstFiltered<ValueType>
386 filter(
const boost::function<
bool(
Key)>& filterFcn = &_truePredicate<Key>)
const;
389 template<
class ValueType>
390 size_t count()
const {
392 for (
const auto& key_value : *
this) {
402 template<
class ValueType>
403 static bool filterHelper(
const boost::function<
bool(
Key)> filter,
const ConstKeyValuePair& key_value) {
404 BOOST_STATIC_ASSERT((!boost::is_same<ValueType, Value>::value));
406 return filter(key_value.key) && (
dynamic_cast<const GenericValue<ValueType>*
>(&key_value.value));
410 friend class boost::serialization::access;
411 template<
class ARCHIVE>
412 void serialize(ARCHIVE & ar,
const unsigned int ) {
413 ar & BOOST_SERIALIZATION_NVP(values_);
416 static ConstKeyValuePair make_const_deref_pair(
const KeyValueMap::const_iterator::value_type& key_value) {
417 return ConstKeyValuePair(key_value.first, *key_value.second); }
419 static KeyValuePair make_deref_pair(
const KeyValueMap::iterator::value_type& key_value) {
420 return KeyValuePair(key_value.first, *key_value.second); }
430 mutable std::string message_;
443 virtual const char* what()
const throw();
453 mutable std::string message_;
458 operation_(operation), key_(key) {}
466 virtual const char* what()
const throw();
473 const std::type_info& storedTypeId_;
474 const std::type_info& requestedTypeId_;
477 mutable std::string message_;
482 const std::type_info& storedTypeId,
const std::type_info& requestedTypeId)
throw() :
483 key_(key), storedTypeId_(storedTypeId), requestedTypeId_(requestedTypeId) {}
497 virtual const char* what()
const throw();
508 virtual const char* what()
const throw() {
509 return "The Values 'this' and the argument passed to Values::localCoordinates have mismatched keys and values";
517 const size_t M1_, N1_;
518 const size_t M2_, N2_;
521 mutable std::string message_;
525 M1_(M1), N1_(N1), M2_(M2), N2_(N2) {
531 virtual const char* what()
const throw ();
543 #include <gtsam/nonlinear/Values-inl.h> Key key() const
The key that was attempted to be accessed that does not exist.
Definition: Values.h:488
const Value & value
The value.
Definition: Values.h:111
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
virtual void deallocate_() const =0
Deallocate a raw pointer of this value.
boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
Definition: Values.h:123
void insertDouble(Key j, double c)
version for double
Definition: Values.h:266
Values()
Default constructor creates an empty Values class.
Definition: Values.h:144
This is the base class for any type to be stored in Values.
Definition: Value.h:36
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
A filtered view of a Values, returned from Values::filter.
Definition: Values-inl.h:93
boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::reverse_iterator > reverse_iterator
Mutable reverse iterator, with value type KeyValuePair.
Definition: Values.h:127
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
ValuesKeyAlreadyExists(Key key)
Construct with the key-value pair attempted to be added.
Definition: Values.h:434
const_iterator upper_bound(Key j) const
Find the lowest-ordered element greater than the specified key.
Definition: Values.h:225
Template to create a binary predicate.
Definition: Testable.h:110
const Key key_
The key that already existed.
Definition: Values.h:427
double atDouble(size_t key) const
version for double
Definition: Values.h:186
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
Value & value
The value.
Definition: Values.h:103
boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_reverse_iterator > const_reverse_iterator
Const reverse iterator, with value type ConstKeyValuePair.
Definition: Values.h:131
boost::shared_ptr< Values > shared_ptr
A shared_ptr to this class.
Definition: Values.h:95
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:109
void clear()
Remove all variables from the config.
Definition: Values.h:303
Wraps any type T so it can play as a Value.
Definition: GenericValue.h:38
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:213
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::iterator > iterator
Mutable forward iterator, with value type KeyValuePair.
Definition: Values.h:119
boost::shared_ptr< const Values > const_shared_ptr
A const shared_ptr to this class.
Definition: Values.h:98
A filtered view of a const Values, returned from Values::filter.
Definition: Values-inl.h:167
iterator find(Key j)
Find an element by key, returning an iterator, or end() if the key was not found.
Definition: Values.h:209
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:73
const Key key
The key.
Definition: Values.h:102
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:101
const Key key_
The key requested.
Definition: Values.h:472
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:56
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
const char * operation_
The operation that attempted to access the key.
Definition: Values.h:449
virtual Value * clone_() const =0
Clone this value in a special memory pool, must be deleted with Value::deallocate_,...
void swap(Values &other)
Swap the contents of two Values without copying data.
Definition: Values.h:300
Key key() const
The duplicate key that was attempted to be added.
Definition: Values.h:440
Key key() const
The key that was attempted to be accessed that does not exist.
Definition: Values.h:463
ValuesKeyDoesNotExist(const char *operation, Key key)
Construct with the key that does not exist in the values.
Definition: Values.h:457
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
ValuesIncorrectType(Key key, const std::type_info &storedTypeId, const std::type_info &requestedTypeId)
Construct with the key that does not exist in the values.
Definition: Values.h:481
iterator upper_bound(Key j)
Find the lowest-ordered element greater than the specified key.
Definition: Values.h:222
const Key key_
The key that does not exist.
Definition: Values.h:450
const Key key
The key.
Definition: Values.h:110
iterator lower_bound(Key j)
Find the element greater than or equal to the specified key.
Definition: Values.h:216
const std::type_info & storedTypeId() const
The typeid of the value stores in the Values.
Definition: Values.h:491
const std::type_info & requestedTypeId() const
The requested typeid.
Definition: Values.h:494
bool empty() const
whether the config is empty
Definition: Values.h:231
size_t size() const
The number of variables in this config.
Definition: Values.h:228
const_iterator lower_bound(Key j) const
Find the element greater than or equal to the specified key.
Definition: Values.h:219