getReference
parent
15bb00683a
commit
2368f3605a
|
@ -149,6 +149,17 @@ const Vector& VectorConfig::get(const std::string& name) const {
|
||||||
return it->second;
|
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 {
|
void VectorConfig::print(const std::string& name) const {
|
||||||
odprintf("VectorConfig %s\n", name.c_str());
|
odprintf("VectorConfig %s\n", name.c_str());
|
||||||
|
|
|
@ -61,6 +61,9 @@ namespace gtsam {
|
||||||
/** get a vector in the configuration by name */
|
/** get a vector in the configuration by name */
|
||||||
const Vector& get(const std::string& name) const;
|
const Vector& get(const std::string& name) const;
|
||||||
|
|
||||||
|
/** get a vector reference by name */
|
||||||
|
Vector& getReference(const std::string& name);
|
||||||
|
|
||||||
/** operator[] syntax for get */
|
/** operator[] syntax for get */
|
||||||
inline const Vector& operator[](const std::string& name) const {
|
inline const Vector& operator[](const std::string& name) const {
|
||||||
return get(name);
|
return get(name);
|
||||||
|
|
|
@ -153,6 +153,15 @@ TEST( VectorConfig, operators) {
|
||||||
CHECK(assert_equal(expected2,c-c));
|
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
|
#ifdef HAVE_BOOST_SERIALIZATION
|
||||||
TEST( VectorConfig, serialize)
|
TEST( VectorConfig, serialize)
|
||||||
|
|
Loading…
Reference in New Issue