From cd5c281c769ff1eea1c14ab106a8444b5e80daa5 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Thu, 18 Feb 2010 14:30:16 +0000 Subject: [PATCH] Added get and set --- .cproject | 17 ++++++++++++----- cpp/VectorBTree.h | 4 ++++ cpp/VectorMap.h | 7 ++++++- cpp/testVectorBTree.cpp | 1 + cpp/testVectorMap.cpp | 1 + 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.cproject b/.cproject index b326ba62d..109495aaf 100644 --- a/.cproject +++ b/.cproject @@ -419,10 +419,10 @@ true true - + make -j2 -testVectorConfig.run +testVectorMap.run true true true @@ -469,7 +469,6 @@ make - testBayesTree.run true false @@ -477,6 +476,7 @@ make + testSymbolicBayesNet.run true false @@ -484,7 +484,6 @@ make - testSymbolicFactorGraph.run true false @@ -676,7 +675,6 @@ make - testGraph.run true false @@ -732,6 +730,7 @@ make + testSimulated2D.run true false @@ -769,6 +768,14 @@ true true + +make +-j2 +testVectorBTree.run +true +true +true + make -j2 diff --git a/cpp/VectorBTree.h b/cpp/VectorBTree.h index 0ce5767c4..58b8a561c 100644 --- a/cpp/VectorBTree.h +++ b/cpp/VectorBTree.h @@ -102,6 +102,10 @@ public: SubVector operator[](const Symbol& j); ConstSubVector operator[](const Symbol& j) const; + /** [set] and [get] provided for access via MATLAB */ + void set(const Symbol& j, const Vector& v) { (*this)[j] = v; } + inline const Vector get(const Symbol& j) const { return (*this)[j];} + /** max of the vectors */ double max() const; diff --git a/cpp/VectorMap.h b/cpp/VectorMap.h index 8c2ec1e10..b1944e034 100644 --- a/cpp/VectorMap.h +++ b/cpp/VectorMap.h @@ -60,7 +60,12 @@ namespace gtsam { Vector& operator[](const Symbol& j); const Vector& operator[](const Symbol& j) const; - bool contains(const Symbol& name) const { + /** [set] and [get] provided for access via MATLAB */ + inline Vector& get(const Symbol& j) { return (*this)[j];} + void set(const Symbol& j, const Vector& v) { (*this)[j] = v; } + inline const Vector& get(const Symbol& j) const { return (*this)[j];} + + bool contains(const Symbol& name) const { const_iterator it = values.find(name); return (it!=values.end()); } diff --git a/cpp/testVectorBTree.cpp b/cpp/testVectorBTree.cpp index 0f115eba8..9eb264233 100644 --- a/cpp/testVectorBTree.cpp +++ b/cpp/testVectorBTree.cpp @@ -48,6 +48,7 @@ TEST( VectorBTree, constructor_insert_get ) LONGS_EQUAL(1,actual.size()) CHECK(assert_equal(expected,actual)) CHECK(equal_with_abs_tol(v,actual[x1])) + CHECK(equal_with_abs_tol(v,actual.get(x1))) } /* ************************************************************************* */ diff --git a/cpp/testVectorMap.cpp b/cpp/testVectorMap.cpp index e5b9ce674..d2c9d1ea7 100644 --- a/cpp/testVectorMap.cpp +++ b/cpp/testVectorMap.cpp @@ -44,6 +44,7 @@ TEST( VectorMap, equals1 ) VectorMap actual; actual.insert("a",v); CHECK(assert_equal(expected,actual)); + CHECK(assert_equal(expected["a"],actual.get("a"))) } /* ************************************************************************* */