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;
105 KeyValuePair(Key _key, Value& _value) : key(_key), value(_value) {}
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>
160 template<
class ValueType>
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);}
193 const Value& at(Key j)
const;
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); }
216 iterator
lower_bound(Key j) {
return boost::make_transform_iterator(values_.lower_bound(j), &make_deref_pair); }
219 const_iterator
lower_bound(Key j)
const {
return boost::make_transform_iterator(values_.lower_bound(j), &make_const_deref_pair); }
222 iterator
upper_bound(Key j) {
return boost::make_transform_iterator(values_.upper_bound(j), &make_deref_pair); }
225 const_iterator
upper_bound(Key j)
const {
return boost::make_transform_iterator(values_.upper_bound(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); }
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>
386 filter(
const boost::function<
bool(Key)>& filterFcn = &_truePredicate<Key>)
const;
391 template<
class ValueType>
392 static bool filterHelper(
const boost::function<
bool(Key)> filter,
const ConstKeyValuePair& key_value) {
393 BOOST_STATIC_ASSERT((!boost::is_same<ValueType, Value>::value));
399 friend class boost::serialization::access;
400 template<
class ARCHIVE>
401 void serialize(ARCHIVE & ar,
const unsigned int ) {
402 ar & BOOST_SERIALIZATION_NVP(values_);
405 static ConstKeyValuePair make_const_deref_pair(
const KeyValueMap::const_iterator::value_type& key_value) {
408 static KeyValuePair make_deref_pair(
const KeyValueMap::iterator::value_type& key_value) {
409 return KeyValuePair(key_value.first, *key_value.second); }
419 mutable std::string message_;
432 virtual const char* what()
const throw();
442 mutable std::string message_;
447 operation_(operation), key_(key) {}
455 virtual const char* what()
const throw();
462 const std::type_info& storedTypeId_;
463 const std::type_info& requestedTypeId_;
466 mutable std::string message_;
471 const std::type_info& storedTypeId,
const std::type_info& requestedTypeId)
throw() :
472 key_(key), storedTypeId_(storedTypeId), requestedTypeId_(requestedTypeId) {}
486 virtual const char* what()
const throw();
497 virtual const char* what()
const throw() {
498 return "The Values 'this' and the argument passed to Values::localCoordinates have mismatched keys and values";
506 const size_t M1_, N1_;
507 const size_t M2_, N2_;
510 mutable std::string message_;
514 M1_(M1), N1_(N1), M2_(M2), N2_(N2) {
520 virtual const char* what()
const throw ();
532 #include <gtsam/nonlinear/Values-inl.h>
const char * operation_
The operation that attempted to access the key.
Definition: Values.h:438
A filtered view of a Values, returned from Values::filter.
Definition: Values-inl.h:94
const Key key_
The key that already existed.
Definition: Values.h:416
const_iterator lower_bound(Key j) const
Find the element greater than or equal to the specified key.
Definition: Values.h:219
Value & value
The value.
Definition: Values.h:103
iterator find(Key j)
Find an element by key, returning an iterator, or end() if the key was not found. ...
Definition: Values.h:209
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::reverse_iterator > reverse_iterator
Mutable reverse iterator, with value type KeyValuePair.
Definition: Values.h:127
const Key key_
The key that does not exist.
Definition: Values.h:439
const Key key
The key.
Definition: Values.h:110
Wraps any type T so it can play as a Value.
Definition: GenericValue.h:38
const_iterator upper_bound(Key j) const
Find the lowest-ordered element greater than the specified key.
Definition: Values.h:225
boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
Definition: Values.h:123
virtual void deallocate_() const =0
Deallocate a raw pointer of this value.
A filtered view of a const Values, returned from Values::filter.
Definition: Values-inl.h:168
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
boost::shared_ptr< const Values > const_shared_ptr
A const shared_ptr to this class.
Definition: Values.h:98
Key key() const
The key that was attempted to be accessed that does not exist.
Definition: Values.h:452
size_t size() const
The number of variables in this config.
Definition: Values.h:228
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
const std::type_info & requestedTypeId() const
The requested typeid.
Definition: Values.h:483
double atDouble(size_t key) const
version for double
Definition: Values.h:186
void insertDouble(Key j, double c)
version for double
Definition: Values.h:266
Template to create a binary predicate.
Definition: Testable.h:110
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_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
ValuesKeyAlreadyExists(Key key)
Construct with the key-value pair attempted to be added.
Definition: Values.h:423
void swap(Values &other)
Swap the contents of two Values without copying data.
Definition: Values.h:300
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:90
Values()
Default constructor creates an empty Values class.
Definition: Values.h:144
iterator upper_bound(Key j)
Find the lowest-ordered element greater than the specified key.
Definition: Values.h:222
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
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:470
Key key() const
The duplicate key that was attempted to be added.
Definition: Values.h:429
const Key key_
The key requested.
Definition: Values.h:461
const std::type_info & storedTypeId() const
The typeid of the value stores in the Values.
Definition: Values.h:480
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:101
Key key() const
The key that was attempted to be accessed that does not exist.
Definition: Values.h:477
const Value & value
The value.
Definition: Values.h:111
ValuesKeyDoesNotExist(const char *operation, Key key)
Construct with the key that does not exist in the values.
Definition: Values.h:446
iterator lower_bound(Key j)
Find the element greater than or equal to the specified key.
Definition: Values.h:216
boost::shared_ptr< Values > shared_ptr
A shared_ptr to this class.
Definition: Values.h:95
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
void clear()
Remove all variables from the config.
Definition: Values.h:303
const Key key
The key.
Definition: Values.h:102
This is the interface class for any value that may be used as a variable assignment in a factor graph...
Definition: Value.h:83
boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::iterator > iterator
Mutable forward iterator, with value type KeyValuePair.
Definition: Values.h:119
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:109
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
bool empty() const
whether the config is empty
Definition: Values.h:231