From e5a7d4c878734876be24c465a98cc3d57954188d Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Wed, 3 Feb 2010 14:08:09 +0000 Subject: [PATCH] More functionality in TupleConfigs --- cpp/TupleConfig.h | 19 +++++++++++++++---- cpp/testTupleConfig.cpp | 10 +++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cpp/TupleConfig.h b/cpp/TupleConfig.h index 80a361aa7..27db5fdb0 100644 --- a/cpp/TupleConfig.h +++ b/cpp/TupleConfig.h @@ -184,23 +184,30 @@ namespace gtsam { // erase an element by key template - void erase(const Key& j) { } - void erase(const Key1& j) { } + void erase(const Key& j) { second_.erase(j); } + void erase(const Key1& j) { first_.erase(j); } // determine whether an element exists template bool exists(const Key& j) const { return second_.exists(j); } bool exists(const Key1& j) const { return first_.exists(j); } - // access operator - currently configs after the first one will not be found + // access operator template const typename Key::Value_t & operator[](const Key& j) const { return second_[j]; } const Value1& operator[](const Key1& j) const { return first_[j]; } + // at access function template const typename Key::Value_t & at(const Key& j) const { return second_.at(j); } const Value1& at(const Key1& j) const { return first_.at(j); } + // size function - adds recursively + size_t size() const { return first_.size() + second_.size(); } + + // dim function + size_t dim() const { return first_.dim() + second_.dim(); } + }; template @@ -230,11 +237,15 @@ namespace gtsam { const Value1& operator[](const Key1& j) const { return first_[j]; } - void erase(const Key1& j) { } + void erase(const Key1& j) { first_.erase(j); } bool exists(const Key1& j) const { return first_.exists(j); } const Value1& at(const Key1& j) const { return first_.at(j); } + size_t size() const { return first_.size(); } + + size_t dim() const { return first_.dim(); } + }; } diff --git a/cpp/testTupleConfig.cpp b/cpp/testTupleConfig.cpp index 44e167552..d629659f0 100644 --- a/cpp/testTupleConfig.cpp +++ b/cpp/testTupleConfig.cpp @@ -183,7 +183,7 @@ typedef TupleConfig > ConfigA; typedef TupleConfig > > ConfigB; /* ************************************************************************* */ -TEST(TupleConfig, create_insert) { +TEST(TupleConfig, basic_functions) { // create some tuple configs ConfigA configA; ConfigB configB; @@ -223,6 +223,14 @@ TEST(TupleConfig, create_insert) { CHECK(assert_equal(configB.at(x1), pose1)); CHECK(assert_equal(configB.at(l1), point1)); CHECK(assert_equal(configB.at(L1), lam1)); + + // size + CHECK(configA.size() == 2); + CHECK(configB.size() == 3); + + // dim + CHECK(configA.dim() == 5); + CHECK(configB.dim() == 6); }