From a6df126e316544d817e97974532b261636a24f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Vallv=C3=A9=20Navarro?= <jvallve@iri.upc.edu> Date: Mon, 6 May 2019 09:44:16 +0200 Subject: [PATCH] implementation new getters --- include/base/problem/problem.h | 35 ++-------------------------------- src/problem/problem.cpp | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/include/base/problem/problem.h b/include/base/problem/problem.h index 0832f30e6..938074f78 100644 --- a/include/base/problem/problem.h +++ b/include/base/problem/problem.h @@ -252,13 +252,9 @@ class Problem : public std::enable_shared_from_this<Problem> */ void removeStateBlock(StateBlockPtr _state_ptr); - /** \brief Returns the size of the map of state block notification - */ - SizeStd getStateBlockNotificationMapSize() const; - - /** \brief Returns if the state block has been notified, and the notification via parameter + /** \brief Returns the map of factor notification to be handled by the solver (the map stored in this is emptied) */ - bool getStateBlockNotification(const StateBlockPtr& sb_ptr, Notification& notif) const; + std::map<StateBlockPtr,Notification> consumeStateBlockNotificationMap(); /** \brief Notifies a new factor to be added to the solver manager */ @@ -268,24 +264,10 @@ class Problem : public std::enable_shared_from_this<Problem> */ void removeFactor(FactorBasePtr _factor_ptr); - /** \brief Returns the size of the map of factor notification - */ - SizeStd getFactorNotificationMapSize() const; - - /** \brief Returns if the factor has been notified, and the notification via parameter - */ - bool getFactorNotification(const FactorBasePtr& fac_ptr, Notification& notif) const; - - protected: - /** \brief Returns the map of state block notification to be handled by the solver (the map stored in this is emptied) - */ - std::map<StateBlockPtr,Notification> consumeStateBlockNotificationMap(); - /** \brief Returns the map of factor notification to be handled by the solver (the map stored in this is emptied) */ std::map<FactorBasePtr, Notification> consumeFactorNotificationMap(); - public: // Print and check --------------------------------------- /** * \brief print wolf tree @@ -329,25 +311,12 @@ inline std::map<StateBlockPtr,Notification> Problem::consumeStateBlockNotificati return std::move(state_block_notification_map_); } -inline SizeStd Problem::getStateBlockNotificationMapSize() const -{ - std::lock_guard<std::mutex> lock(mut_state_block_notifications_); - return state_block_notification_map_.size(); -} - inline std::map<FactorBasePtr,Notification> Problem::consumeFactorNotificationMap() { std::lock_guard<std::mutex> lock(mut_factor_notifications_); return std::move(factor_notification_map_); } -inline wolf::SizeStd Problem::getFactorNotificationMapSize() const -{ - std::lock_guard<std::mutex> lock(mut_factor_notifications_); - return factor_notification_map_.size(); -} - - } // namespace wolf #endif // PROBLEM_H diff --git a/src/problem/problem.cpp b/src/problem/problem.cpp index 484fa4458..34f373642 100644 --- a/src/problem/problem.cpp +++ b/src/problem/problem.cpp @@ -401,6 +401,16 @@ void Problem::removeStateBlock(StateBlockPtr _state_ptr) state_block_notification_map_[_state_ptr] = REMOVE; } +bool Problem::getStateBlockNotification(const StateBlockPtr& sb_ptr, Notification& notif) const +{ + std::lock_guard<std::mutex> lock(mut_state_block_notifications_); + if (state_block_notification_map_.find(sb_ptr) == state_block_notification_map_.end()) + return false; + + notif = state_block_notification_map_.at(sb_ptr); + return true; +} + FactorBasePtr Problem::addFactor(FactorBasePtr _factor_ptr) { std::lock_guard<std::mutex> lock(mut_factor_notifications_); @@ -442,6 +452,16 @@ void Problem::removeFactor(FactorBasePtr _factor_ptr) factor_notification_map_[_factor_ptr] = REMOVE; } +bool Problem::getFactorNotification(const FactorBasePtr& fac_ptr, Notification& notif) const +{ + std::lock_guard<std::mutex> lock(mut_factor_notifications_); + if (factor_notification_map_.find(fac_ptr) == factor_notification_map_.end()) + return false; + + notif = factor_notification_map_.at(fac_ptr); + return true; +} + void Problem::clearCovariance() { std::lock_guard<std::mutex> lock(mut_covariances_); -- GitLab