From ccd64fb08c21da3441cbe639a86a398398a7e1dd Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 25 Jan 2021 16:22:09 -0500 Subject: [PATCH] use standard function to check for empty string --- gtsam/base/Testable.h | 4 ++-- gtsam/navigation/CombinedImuFactor.cpp | 2 +- gtsam/navigation/ImuFactor.cpp | 4 ++-- gtsam/navigation/PreintegratedRotation.cpp | 2 +- gtsam/navigation/PreintegrationBase.cpp | 2 +- gtsam/nonlinear/Values.cpp | 2 +- gtsam/sfm/ShonanAveraging.h | 3 ++- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gtsam/base/Testable.h b/gtsam/base/Testable.h index 2145360df..e8cdbd8e0 100644 --- a/gtsam/base/Testable.h +++ b/gtsam/base/Testable.h @@ -72,10 +72,10 @@ namespace gtsam { }; // \ Testable inline void print(float v, const std::string& s = "") { - std::cout << (s == "" ? s : s + " ") << v << std::endl; + std::cout << (s.empty() ? s : s + " ") << v << std::endl; } inline void print(double v, const std::string& s = "") { - std::cout << (s == "" ? s : s + " ") << v << std::endl; + std::cout << (s.empty() ? s : s + " ") << v << std::endl; } /** Call equal on the object */ diff --git a/gtsam/navigation/CombinedImuFactor.cpp b/gtsam/navigation/CombinedImuFactor.cpp index e41a8de44..ca1c5b93a 100644 --- a/gtsam/navigation/CombinedImuFactor.cpp +++ b/gtsam/navigation/CombinedImuFactor.cpp @@ -167,7 +167,7 @@ gtsam::NonlinearFactor::shared_ptr CombinedImuFactor::clone() const { //------------------------------------------------------------------------------ void CombinedImuFactor::print(const string& s, const KeyFormatter& keyFormatter) const { - cout << (s == "" ? s : s + "\n") << "CombinedImuFactor(" + cout << (s.empty() ? s : s + "\n") << "CombinedImuFactor(" << keyFormatter(this->key1()) << "," << keyFormatter(this->key2()) << "," << keyFormatter(this->key3()) << "," << keyFormatter(this->key4()) << "," << keyFormatter(this->key5()) << "," << keyFormatter(this->key6()) diff --git a/gtsam/navigation/ImuFactor.cpp b/gtsam/navigation/ImuFactor.cpp index cebddf05d..98b1e6f9d 100644 --- a/gtsam/navigation/ImuFactor.cpp +++ b/gtsam/navigation/ImuFactor.cpp @@ -130,7 +130,7 @@ std::ostream& operator<<(std::ostream& os, const ImuFactor& f) { //------------------------------------------------------------------------------ void ImuFactor::print(const string& s, const KeyFormatter& keyFormatter) const { - cout << (s == "" ? s : s + "\n") << "ImuFactor(" << keyFormatter(this->key1()) + cout << (s.empty() ? s : s + "\n") << "ImuFactor(" << keyFormatter(this->key1()) << "," << keyFormatter(this->key2()) << "," << keyFormatter(this->key3()) << "," << keyFormatter(this->key4()) << "," << keyFormatter(this->key5()) << ")\n"; @@ -226,7 +226,7 @@ std::ostream& operator<<(std::ostream& os, const ImuFactor2& f) { //------------------------------------------------------------------------------ void ImuFactor2::print(const string& s, const KeyFormatter& keyFormatter) const { - cout << (s == "" ? s : s + "\n") << "ImuFactor2(" + cout << (s.empty() ? s : s + "\n") << "ImuFactor2(" << keyFormatter(this->key1()) << "," << keyFormatter(this->key2()) << "," << keyFormatter(this->key3()) << ")\n"; cout << *this << endl; diff --git a/gtsam/navigation/PreintegratedRotation.cpp b/gtsam/navigation/PreintegratedRotation.cpp index f827c7c59..ee30bee9e 100644 --- a/gtsam/navigation/PreintegratedRotation.cpp +++ b/gtsam/navigation/PreintegratedRotation.cpp @@ -26,7 +26,7 @@ using namespace std; namespace gtsam { void PreintegratedRotationParams::print(const string& s) const { - cout << (s == "" ? s : s + "\n") << endl; + cout << (s.empty() ? s : s + "\n") << endl; cout << "gyroscopeCovariance:\n[\n" << gyroscopeCovariance << "\n]" << endl; if (omegaCoriolis) cout << "omegaCoriolis = (" << omegaCoriolis->transpose() << ")" << endl; diff --git a/gtsam/navigation/PreintegrationBase.cpp b/gtsam/navigation/PreintegrationBase.cpp index 111594663..543cc5b59 100644 --- a/gtsam/navigation/PreintegrationBase.cpp +++ b/gtsam/navigation/PreintegrationBase.cpp @@ -46,7 +46,7 @@ ostream& operator<<(ostream& os, const PreintegrationBase& pim) { //------------------------------------------------------------------------------ void PreintegrationBase::print(const string& s) const { - cout << (s == "" ? s : s + "\n") << *this << endl; + cout << (s.empty() ? s : s + "\n") << *this << endl; } //------------------------------------------------------------------------------ diff --git a/gtsam/nonlinear/Values.cpp b/gtsam/nonlinear/Values.cpp index 89a4206ee..9b8f7645a 100644 --- a/gtsam/nonlinear/Values.cpp +++ b/gtsam/nonlinear/Values.cpp @@ -75,7 +75,7 @@ namespace gtsam { /* ************************************************************************* */ void Values::print(const string& str, const KeyFormatter& keyFormatter) const { - cout << str << (str == "" ? "" : "\n"); + cout << str << (str.empty() ? "" : "\n"); cout << "Values with " << size() << " values:\n"; for(const_iterator key_value = begin(); key_value != end(); ++key_value) { cout << "Value " << keyFormatter(key_value->key) << ": "; diff --git a/gtsam/sfm/ShonanAveraging.h b/gtsam/sfm/ShonanAveraging.h index 0a8bdc8c1..f00109cae 100644 --- a/gtsam/sfm/ShonanAveraging.h +++ b/gtsam/sfm/ShonanAveraging.h @@ -91,7 +91,8 @@ struct GTSAM_EXPORT ShonanAveragingParameters { bool getCertifyOptimality() const { return certifyOptimality; } /// Print the parameters and flags used for rotation averaging. - void print() const { + void print(const std::string &s = "") const { + std::cout << (s.empty() ? s : s + " "); std::cout << " ShonanAveragingParameters: " << std::endl; std::cout << " alpha: " << alpha << std::endl; std::cout << " beta: " << beta << std::endl;