Small changes, mainly const correctness

release/4.3a0
Frank Dellaert 2010-01-10 14:59:22 +00:00
parent c957672656
commit 92c58e50a1
3 changed files with 11 additions and 11 deletions

View File

@ -62,7 +62,7 @@ namespace gtsam {
/** Call print on the object */ /** Call print on the object */
template<class T> template<class T>
inline void print_(const T& object, const char *s = "") { inline void print_(const T& object, const std::string& s = "") {
object.print(s); object.print(s);
} }

View File

@ -16,20 +16,20 @@ using namespace std;
namespace gtsam { namespace gtsam {
template<class T> template<class T>
void LieConfig<T>::print(const std::string &s) const { void LieConfig<T>::print(const string &s) const {
std::cout << "LieConfig " << s << ", size " << values_.size() << "\n"; cout << "LieConfig " << s << ", size " << values_.size() << "\n";
std::pair<std::string, T> v; pair<string, T> v;
BOOST_FOREACH(v, values_) BOOST_FOREACH(v, values_)
::gtsam::print(v.second, v.first + ": "); gtsam::print(v.second, v.first + ": ");
} }
template<class T> template<class T>
bool LieConfig<T>::equals(const LieConfig<T>& expected, double tol) const { bool LieConfig<T>::equals(const LieConfig<T>& expected, double tol) const {
if (values_.size() != expected.values_.size()) return false; if (values_.size() != expected.values_.size()) return false;
std::pair<std::string, T> v; pair<string, T> v;
BOOST_FOREACH(v, values_) { BOOST_FOREACH(v, values_) {
boost::optional<const T&> expval = expected.gettry(v.first); boost::optional<const T&> expval = expected.gettry(v.first);
if(!expval || !::gtsam::equal(v.second, *expval, tol)) if(!expval || !gtsam::equal(v.second, *expval, tol))
return false; return false;
} }
return true; return true;
@ -38,7 +38,7 @@ namespace gtsam {
template<class T> template<class T>
LieConfig<T> expmap(const LieConfig<T>& c, const VectorConfig& delta) { LieConfig<T> expmap(const LieConfig<T>& c, const VectorConfig& delta) {
LieConfig<T> newConfig; LieConfig<T> newConfig;
std::string j; T pj; string j; T pj;
FOREACH_PAIR(j, pj, c.values_) { FOREACH_PAIR(j, pj, c.values_) {
if (delta.contains(j)) { if (delta.contains(j)) {
const Vector& dj = delta[j]; const Vector& dj = delta[j];
@ -53,7 +53,7 @@ namespace gtsam {
template<class T> template<class T>
LieConfig<T> expmap(const LieConfig<T>& c, const Vector& delta) { LieConfig<T> expmap(const LieConfig<T>& c, const Vector& delta) {
LieConfig<T> newConfig; LieConfig<T> newConfig;
std::pair<std::string, Vector> value; pair<string, Vector> value;
int delta_offset = 0; int delta_offset = 0;
BOOST_FOREACH(value, c) { BOOST_FOREACH(value, c) {
int cur_dim = dim(value.second); int cur_dim = dim(value.second);

View File

@ -57,14 +57,14 @@ namespace gtsam {
virtual ~LieConfig() {} virtual ~LieConfig() {}
/** Retrieve a variable by key, throws std::invalid_argument if not found */ /** Retrieve a variable by key, throws std::invalid_argument if not found */
const T& get(std::string& key) const { const T& get(const std::string& key) const {
iterator it = values_.find(key); iterator it = values_.find(key);
if (it == values_.end()) throw std::invalid_argument("invalid key"); if (it == values_.end()) throw std::invalid_argument("invalid key");
else return it->second; else return it->second;
} }
/** Retrieve a variable by key, returns nothing if not found */ /** Retrieve a variable by key, returns nothing if not found */
boost::optional<const T&> gettry(std::string& key) const { boost::optional<const T&> gettry(const std::string& key) const {
const_iterator it = values_.find(key); const_iterator it = values_.find(key);
if (it == values_.end()) return boost::optional<const T&>(); if (it == values_.end()) return boost::optional<const T&>();
else return it->second; else return it->second;