27 #include <boost/optional.hpp>
28 #include <boost/pool/pool_alloc.hpp>
29 #include <boost/ptr_container/ptr_map.hpp>
30 #include <boost/iterator/transform_iterator.hpp>
31 #include <boost/iterator/filter_iterator.hpp>
32 #include <boost/function.hpp>
34 #pragma GCC diagnostic push
35 #pragma GCC diagnostic ignored "-Wunused-variable"
37 #include <boost/bind.hpp>
39 #pragma GCC diagnostic pop
41 #include <boost/ptr_container/serialize_ptr_map.hpp>
42 #include <boost/iterator_adaptors.hpp>
55 class ValueAutomaticCasting;
56 template<
typename T>
static bool _truePredicate(
const T&) {
return true; }
83 typedef boost::ptr_map<
88 boost::fast_pool_allocator<std::pair<const Key, void*> > > KeyValueMap;
94 typedef KeyValueMap::const_iterator::value_type ConstKeyValuePtrPair;
95 typedef KeyValueMap::iterator::value_type KeyValuePtrPair;
123 typedef boost::transform_iterator<
124 boost::function1<KeyValuePair, const KeyValuePtrPair&>, KeyValueMap::iterator>
iterator;
127 typedef boost::transform_iterator<
128 boost::function1<ConstKeyValuePair, const ConstKeyValuePtrPair&>, KeyValueMap::const_iterator>
const_iterator;
131 typedef boost::transform_iterator<
132 boost::function1<KeyValuePair, const KeyValuePtrPair&>, KeyValueMap::reverse_iterator>
reverse_iterator;
135 typedef boost::transform_iterator<
136 boost::function1<ConstKeyValuePair, const ConstKeyValuePtrPair&>, KeyValueMap::const_reverse_iterator>
const_reverse_iterator;
141 template<
class ValueType = Value>
145 template<
class ValueType = Value>
155 template<
class ValueType>
156 Values(
const Filtered<ValueType>& view);
159 template<
class ValueType>
160 Values(
const ConstFiltered<ValueType>& view);
166 void print(
const std::string& str =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
169 bool equals(
const Values& other,
double tol=1e-9)
const;
180 template<
typename ValueType>
181 const ValueType& at(
Key j)
const;
193 bool exists(
Key j)
const;
199 template<
typename ValueType>
200 boost::optional<const ValueType&> exists(
Key j)
const;
204 iterator find(
Key j) {
return boost::make_transform_iterator(values_.find(j), &make_deref_pair); }
208 const_iterator find(
Key j)
const {
return boost::make_transform_iterator(values_.find(j), &make_const_deref_pair); }
223 size_t size()
const {
return values_.size(); }
226 bool empty()
const {
return values_.empty(); }
228 const_iterator begin()
const {
return boost::make_transform_iterator(values_.begin(), &make_const_deref_pair); }
229 const_iterator end()
const {
return boost::make_transform_iterator(values_.end(), &make_const_deref_pair); }
230 iterator begin() {
return boost::make_transform_iterator(values_.begin(), &make_deref_pair); }
231 iterator end() {
return boost::make_transform_iterator(values_.end(), &make_deref_pair); }
232 const_reverse_iterator rbegin()
const {
return boost::make_transform_iterator(values_.rbegin(), &make_const_deref_pair); }
233 const_reverse_iterator rend()
const {
return boost::make_transform_iterator(values_.rend(), &make_const_deref_pair); }
234 reverse_iterator rbegin() {
return boost::make_transform_iterator(values_.rbegin(), &make_deref_pair); }
235 reverse_iterator rend() {
return boost::make_transform_iterator(values_.rend(), &make_deref_pair); }
241 Values retract(
const VectorValues&
delta)
const;
244 VectorValues localCoordinates(
const Values& cp)
const;
249 void insert(
Key j,
const Value& val);
252 void insert(
const Values& values);
258 std::pair<iterator, bool> tryInsert(
Key j,
const Value& value);
261 void update(
Key j,
const Value& val);
264 void update(
const Values& values);
276 Values& operator=(
const Values& rhs);
304 filter(
const boost::function<
bool(
Key)>& filterFcn);
325 template<
class ValueType>
327 filter(
const boost::function<
bool(
Key)>& filterFcn = &_truePredicate<Key>);
343 filter(
const boost::function<
bool(
Key)>& filterFcn)
const;
363 template<
class ValueType>
364 ConstFiltered<ValueType>
365 filter(
const boost::function<
bool(
Key)>& filterFcn = &_truePredicate<Key>)
const;
370 template<
class ValueType>
371 static bool filterHelper(
const boost::function<
bool(
Key)> filter,
const ConstKeyValuePair& key_value) {
373 return filter(key_value.key) && (
typeid(ValueType) ==
typeid(key_value.value) ||
typeid(ValueType) ==
typeid(
Value));
377 template<
class ValueType,
class CastedKeyValuePairType,
class KeyValuePairType>
378 static CastedKeyValuePairType castHelper(KeyValuePairType key_value) {
380 return CastedKeyValuePairType(key_value.key, static_cast<ValueType&>(key_value.value));
384 friend class boost::serialization::access;
385 template<
class ARCHIVE>
386 void serialize(ARCHIVE & ar,
const unsigned int version) {
387 ar & BOOST_SERIALIZATION_NVP(values_);
390 static ConstKeyValuePair make_const_deref_pair(
const KeyValueMap::const_iterator::value_type& key_value) {
391 return ConstKeyValuePair(key_value.first, *key_value.second); }
393 static KeyValuePair make_deref_pair(
const KeyValueMap::iterator::value_type& key_value) {
394 return KeyValuePair(key_value.first, *key_value.second); }
404 mutable std::string message_;
417 virtual const char* what()
const throw();
427 mutable std::string message_;
432 operation_(operation), key_(key) {}
440 virtual const char* what()
const throw();
447 const std::type_info& storedTypeId_;
448 const std::type_info& requestedTypeId_;
451 mutable std::string message_;
456 const std::type_info& storedTypeId,
const std::type_info& requestedTypeId)
throw() :
457 key_(key), storedTypeId_(storedTypeId), requestedTypeId_(requestedTypeId) {}
471 virtual const char* what()
const throw();
482 virtual const char* what()
const throw() {
483 return "The Values 'this' and the argument passed to Values::localCoordinates have mismatched keys and values";
489 #include <gtsam/nonlinear/Values-inl.h>
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:208
ValuesKeyDoesNotExist(const char *operation, Key key)
Construct with the key that does not exist in the values.
Definition: Values.h:431
Key key() const
The key that was attempted to be accessed that does not exist.
Definition: Values.h:462
const Key key_
The key that does not exist.
Definition: Values.h:424
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:455
A filtered view of a const Values, returned from Values::filter.
Definition: Values-inl.h:125
virtual Value * clone_() const =0
Clone this value in a special memory pool, must be deleted with Value::deallocate_, not with the 'delete' operator.
const std::type_info & storedTypeId() const
The typeid of the value stores in the Values.
Definition: Values.h:465
void clear()
Remove all variables from the config.
Definition: Values.h:282
const Key key_
The key that already existed.
Definition: Values.h:401
This is the interface class for any value that may be used as a variable assignment in a factor graph...
Definition: Value.h:81
const Key key_
The key requested.
Definition: Values.h:446
const char * operation_
The operation that attempted to access the key.
Definition: Values.h:423
const Value & value
The value.
Definition: Values.h:116
boost::shared_ptr< const Values > const_shared_ptr
A const shared_ptr to this class.
Definition: Values.h:103
Value & value
The value.
Definition: Values.h:108
boost::shared_ptr< Values > shared_ptr
A shared_ptr to this class.
Definition: Values.h:100
size_t dim(const Vector &v)
dimensionality == size
Definition: Vector.h:90
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:75
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
A thin wrapper around std::map that uses boost's fast_pool_allocator.
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:136
Key key() const
The key that was attempted to be accessed that does not exist.
Definition: Values.h:437
Key key() const
The duplicate key that was attempted to be added.
Definition: Values.h:414
const_iterator lower_bound(Key j) const
Find the element greater than or equal to the specified key.
Definition: Values.h:214
iterator lower_bound(Key j)
Find the element greater than or equal to the specified key.
Definition: Values.h:211
size_t size() const
The number of variables in this config.
Definition: Values.h:223
virtual void deallocate_() const =0
Deallocate a raw pointer of this value.
iterator find(Key j)
Find an element by key, returning an iterator, or end() if the key was not found. ...
Definition: Values.h:204
Template to create a binary predicate.
Definition: Testable.h:102
boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::reverse_iterator > reverse_iterator
Mutable reverse iterator, with value type KeyValuePair.
Definition: Values.h:132
ValuesKeyAlreadyExists(Key key)
Construct with the key-value pair attempted to be added.
Definition: Values.h:408
size_t Key
Integer nonlinear key type.
Definition: types.h:59
The interface class for any variable that can be optimized or used in a factor.
A filtered view of a Values, returned from Values::filter.
Definition: Values-inl.h:57
const Key key
The key.
Definition: Values.h:115
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:89
const_iterator upper_bound(Key j) const
Find the lowest-ordered element greater than the specified key.
Definition: Values.h:220
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:114
FastList< Key > KeyList
Useful typedefs for operations with Values - allow for matlab interfaces.
Definition: Key.h:44
Values()
Default constructor creates an empty Values class.
Definition: Values.h:149
void swap(Values &other)
Swap the contents of two Values without copying data.
Definition: Values.h:279
const std::type_info & requestedTypeId() const
The requested typeid.
Definition: Values.h:468
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:106
Vector delta(size_t n, size_t i, double value)
Create basis vector of dimension n, with a constant in spot i.
Definition: Vector.cpp:53
boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
Definition: Values.h:128
iterator upper_bound(Key j)
Find the lowest-ordered element greater than the specified key.
Definition: Values.h:217
boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::iterator > iterator
Mutable forward iterator, with value type KeyValuePair.
Definition: Values.h:124
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62
bool empty() const
whether the config is empty
Definition: Values.h:226
const Key key
The key.
Definition: Values.h:107