From 67e1897e475c7dc2380665e1e1a422b8ec96ae3e Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Thu, 10 Dec 2009 20:17:11 +0000 Subject: [PATCH] Get and [] now return references, new imperative add method --- cpp/VectorConfig.cpp | 2 +- cpp/VectorConfig.h | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cpp/VectorConfig.cpp b/cpp/VectorConfig.cpp index 4ba8fa957..8577b3561 100644 --- a/cpp/VectorConfig.cpp +++ b/cpp/VectorConfig.cpp @@ -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); if (it==values.end()) { print(); diff --git a/cpp/VectorConfig.h b/cpp/VectorConfig.h index 4f7cb7d96..32449a6be 100644 --- a/cpp/VectorConfig.h +++ b/cpp/VectorConfig.h @@ -47,6 +47,12 @@ namespace gtsam { 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 * For VectorConfig, this is just addition. @@ -60,10 +66,10 @@ namespace gtsam { const_iterator end() const {return values.end();} /** 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 */ - 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 { const_iterator it = values.find(name);