Get and [] now return references, new imperative add method

release/4.3a0
Frank Dellaert 2009-12-10 20:17:11 +00:00
parent 81ce0bef88
commit 67e1897e47
2 changed files with 9 additions and 3 deletions

View File

@ -55,7 +55,7 @@ VectorConfig VectorConfig::exmap(const VectorConfig & delta) const
} }
/* ************************************************************************* */ /* ************************************************************************* */
Vector VectorConfig::get(const std::string& name) const { const Vector& VectorConfig::get(const std::string& name) const {
const_iterator it = values.find(name); const_iterator it = values.find(name);
if (it==values.end()) { if (it==values.end()) {
print(); print();

View File

@ -47,6 +47,12 @@ namespace gtsam {
return *this; return *this;
} }
/** Add to vector at position j */
void add(const std::string& j, const Vector& a) {
Vector& vj = values[j];
if (vj.size()==0) vj = a; else vj += a;
}
/** /**
* Add a delta config, needed for use in NonlinearOptimizer * Add a delta config, needed for use in NonlinearOptimizer
* For VectorConfig, this is just addition. * For VectorConfig, this is just addition.
@ -60,10 +66,10 @@ namespace gtsam {
const_iterator end() const {return values.end();} const_iterator end() const {return values.end();}
/** get a vector in the configuration by name */ /** get a vector in the configuration by name */
Vector get(const std::string& name) const; const Vector& get(const std::string& name) const;
/** operator[] syntax for get */ /** operator[] syntax for get */
inline Vector operator[](const std::string& name) const { return get(name); } inline const Vector& operator[](const std::string& name) const { return get(name); }
bool contains(const std::string& name) const { bool contains(const std::string& name) const {
const_iterator it = values.find(name); const_iterator it = values.find(name);