Added Values::tryInsert
parent
deaabeb0bf
commit
4efdf497cd
|
|
@ -125,8 +125,7 @@ namespace gtsam {
|
|||
|
||||
/* ************************************************************************* */
|
||||
void Values::insert(Key j, const Value& val) {
|
||||
Key key = j; // Non-const duplicate to deal with non-const insert argument
|
||||
std::pair<KeyValueMap::iterator,bool> insertResult = values_.insert(key, val.clone_());
|
||||
std::pair<iterator,bool> insertResult = tryInsert(j, val);
|
||||
if(!insertResult.second)
|
||||
throw ValuesKeyAlreadyExists(j);
|
||||
}
|
||||
|
|
@ -139,6 +138,12 @@ namespace gtsam {
|
|||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
std::pair<Values::iterator, bool> Values::tryInsert(Key j, const Value& value) {
|
||||
std::pair<KeyValueMap::iterator, bool> result = values_.insert(j, value.clone_());
|
||||
return std::make_pair(boost::make_transform_iterator(result.first, &make_deref_pair), result.second);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Values::update(Key j, const Value& val) {
|
||||
// Find the value to update
|
||||
|
|
|
|||
|
|
@ -232,6 +232,12 @@ namespace gtsam {
|
|||
/** Add a set of variables, throws KeyAlreadyExists<J> if a key is already present */
|
||||
void insert(const Values& values);
|
||||
|
||||
/** insert that mimics the STL map insert - if the value already exists, the map is not modified
|
||||
* and an iterator to the existing value is returned, along with 'false'. If the value did not
|
||||
* exist, it is inserted and an iterator pointing to the new element, along with 'true', is
|
||||
* returned. */
|
||||
std::pair<iterator, bool> tryInsert(Key j, const Value& value);
|
||||
|
||||
/** single element change of existing element */
|
||||
void update(Key j, const Value& val);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue