getReference

release/4.3a0
Frank Dellaert 2009-12-30 14:53:40 +00:00
parent 15bb00683a
commit 2368f3605a
3 changed files with 23 additions and 0 deletions

View File

@ -149,6 +149,17 @@ const Vector& VectorConfig::get(const std::string& name) const {
return it->second;
}
/* ************************************************************************* */
Vector& VectorConfig::getReference(const std::string& name) {
iterator it = values.find(name);
if (it==values.end()) {
print();
cout << "asked for key " << name << endl;
throw(std::invalid_argument("VectorConfig::[] invalid key"));
}
return it->second;
}
/* ************************************************************************* */
void VectorConfig::print(const std::string& name) const {
odprintf("VectorConfig %s\n", name.c_str());

View File

@ -61,6 +61,9 @@ namespace gtsam {
/** get a vector in the configuration by name */
const Vector& get(const std::string& name) const;
/** get a vector reference by name */
Vector& getReference(const std::string& name);
/** operator[] syntax for get */
inline const Vector& operator[](const std::string& name) const {
return get(name);

View File

@ -153,6 +153,15 @@ TEST( VectorConfig, operators) {
CHECK(assert_equal(expected2,c-c));
}
/* ************************************************************************* */
TEST( VectorConfig, getReference) {
VectorConfig c; c.insert("x", Vector_(2, 1.1, 2.2));
Vector& cx = c.getReference("x");
cx = cx*2.0;
VectorConfig expected; expected.insert("x", Vector_(2, 2.2, 4.4));
CHECK(assert_equal(expected,c));
}
/* ************************************************************************* */
#ifdef HAVE_BOOST_SERIALIZATION
TEST( VectorConfig, serialize)