29 #include <gtsam/base/GenericValue.h> 30 #include <gtsam/base/VectorSpace.h> 32 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 33 #include <boost/serialization/unique_ptr.hpp> 45 class ValueAutomaticCasting;
46 template<
typename T>
static bool _truePredicate(
const T&) {
return true; }
75 std::map<Key, std::unique_ptr<Value>, std::less<Key>,
76 std::allocator<std::pair<const Key, std::unique_ptr<Value>>>>;
125 Values(std::initializer_list<ConstKeyValuePair> init);
135 void print(
const std::string& str =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
138 bool equals(
const Values& other,
double tol=1e-9)
const;
152 template <
typename ValueType>
153 const ValueType at(
Key j)
const;
156 double atDouble(
size_t key)
const {
return at<double>(key);}
168 bool exists(
Key j)
const;
174 template<
typename ValueType>
175 const ValueType * exists(
Key j)
const;
178 size_t size()
const {
return values_.size(); }
181 bool empty()
const {
return values_.empty(); }
188 using const_iterator_type =
typename KeyValueMap::const_iterator;
189 const_iterator_type it_;
192 std::unique_ptr<ConstKeyValuePair> operator->() {
193 return std::make_unique<ConstKeyValuePair>(it_->first, *(it_->second));
196 return it_ == other.it_;
237 void insert(
Key j,
const Value& val);
240 void insert(
const Values& values);
245 template <
typename ValueType>
246 void insert(
Key j,
const ValueType& val);
252 void update(
Key j,
const Value& val);
258 template <
typename T>
259 void update(
Key j,
const T& val);
262 void update(
const Values& values);
265 void insert_or_assign(
Key j,
const Value& val);
271 void insert_or_assign(
const Values& values);
274 template <
typename ValueType>
275 void insert_or_assign(
Key j,
const ValueType& val);
304 std::map<Key,size_t> dims()
const;
310 template <
class ValueType>
311 size_t count()
const;
332 template <
class ValueType>
333 std::map<Key, ValueType>
334 extract(
const std::function<
bool(
Key)>& filterFcn = &_truePredicate<Key>)
const;
339 template<
class ValueType>
340 static bool filterHelper(
const std::function<
bool(
Key)> filter,
const ConstKeyValuePair& key_value) {
342 static_assert(!std::is_same<Value, ValueType>::value,
"ValueType must not be type: Value to use this filter");
347 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 349 friend class boost::serialization::access;
350 template<
class ARCHIVE>
351 void serialize(ARCHIVE & ar,
const unsigned int ) {
352 ar & BOOST_SERIALIZATION_NVP(values_);
364 mutable std::string message_;
374 Key key() const noexcept {
return key_; }
377 GTSAM_EXPORT
const char* what()
const noexcept
override;
387 mutable std::string message_;
392 operation_(operation), key_(key) {}
397 Key key() const noexcept {
return key_; }
400 GTSAM_EXPORT
const char* what()
const noexcept
override;
407 const std::type_info& storedTypeId_;
408 const std::type_info& requestedTypeId_;
411 mutable std::string message_;
416 const std::type_info& storedTypeId,
const std::type_info& requestedTypeId) noexcept :
417 key_(key), storedTypeId_(storedTypeId), requestedTypeId_(requestedTypeId) {}
422 Key key() const noexcept {
return key_; }
431 GTSAM_EXPORT
const char* what()
const noexcept
override;
442 const char* what()
const noexcept
override {
443 return "The Values 'this' and the argument passed to Values::localCoordinates have mismatched keys and values";
451 const size_t M1_, N1_;
452 const size_t M2_, N2_;
455 mutable std::string message_;
459 M1_(M1), N1_(N1), M2_(M2), N2_(N2) {
465 GTSAM_EXPORT
const char* what()
const noexcept
override;
477 #include <gtsam/nonlinear/Values-inl.h> void clear()
Definition: Values.h:298
bool operator!=(const Matrix &A, const Matrix &B)
Definition: Matrix.h:106
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
deref_iterator lower_bound(Key j) const
Definition: Values.h:213
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:90
Definition: Testable.h:152
Key key() const noexcept
The key that was attempted to be accessed that does not exist.
Definition: Values.h:422
std::shared_ptr< const Values > const_shared_ptr
A const shared_ptr to this class.
Definition: Values.h:87
virtual Value * clone_() const =0
Key key() const noexcept
The duplicate key that was attempted to be added.
Definition: Values.h:374
bool operator==(const Matrix &A, const Matrix &B)
Definition: Matrix.h:99
deref_iterator find(Key j) const
Definition: Values.h:210
virtual void deallocate_() const =0
Default allocator for list, map, and set types.
Definition: FastDefaultAllocator.h:49
ValuesKeyDoesNotExist(const char *operation, Key key) noexcept
Construct with the key that does not exist in the values.
Definition: Values.h:391
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:52
Definition: GenericValue.h:44
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:98
Definition: VectorValues.h:74
const std::type_info & storedTypeId() const
The typeid of the value stores in the Values.
Definition: Values.h:425
const Value & value
The value.
Definition: Values.h:100
const char * operation_
The operation that attempted to access the key.
Definition: Values.h:383
Definition: Testable.h:112
const std::type_info & requestedTypeId() const
The requested typeid.
Definition: Values.h:428
const Key key
The key.
Definition: Values.h:91
GTSAM_EXPORT void print(const Matrix &A, const std::string &s, std::ostream &stream)
size_t size() const
Definition: Values.h:178
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
double atDouble(size_t key) const
version for double
Definition: Values.h:156
ValuesKeyAlreadyExists(Key key) noexcept
Construct with the key-value pair attempted to be added.
Definition: Values.h:368
Definition: chartTesting.h:28
const Key key
The key.
Definition: Values.h:99
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
void swap(Values &other)
Definition: Values.h:295
const Key key_
The key that already existed.
Definition: Values.h:361
const Key key_
The key requested.
Definition: Values.h:406
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:415
Value & value
The value.
Definition: Values.h:92
deref_iterator upper_bound(Key j) const
Definition: Values.h:216
void insertDouble(Key j, double c)
version for double
Definition: Values.h:249
An easy way to control which allocator is used for Fast* collections.
std::shared_ptr< Values > shared_ptr
A shared_ptr to this class.
Definition: Values.h:84
bool empty() const
Definition: Values.h:181
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
Key key() const noexcept
The key that was attempted to be accessed that does not exist.
Definition: Values.h:397
const Key key_
The key that does not exist.
Definition: Values.h:384