diff --git a/src/state_block.h b/src/state_block.h index 3f24a3ad32cd12fac0ae9bfe2d4144b6e19749e1..1d6e9564a7af188c3b45ee292c5b64c24777a1e3 100644 --- a/src/state_block.h +++ b/src/state_block.h @@ -113,6 +113,8 @@ public: void removeLocalParametrization(); + /// @todo Solely the solver should be able to + /// pass Notification::ENABLED ! void notify(const StateBlock::Notification n); StateBlock::Notification notify() const noexcept; @@ -126,6 +128,7 @@ public: namespace wolf { inline StateBlock::StateBlock(const Eigen::VectorXs _state, bool _fixed, LocalParametrizationBasePtr _local_param_ptr) : + notification_(Notification::ADD), node_ptr_(), // nullptr fixed_(_fixed), state_(_state), @@ -135,6 +138,7 @@ inline StateBlock::StateBlock(const Eigen::VectorXs _state, bool _fixed, LocalPa } inline StateBlock::StateBlock(const unsigned int _size, bool _fixed, LocalParametrizationBasePtr _local_param_ptr) : + notification_(Notification::ADD), node_ptr_(), // nullptr fixed_(_fixed), state_(Eigen::VectorXs::Zero(_size)), @@ -216,7 +220,91 @@ inline void StateBlock::setLocalParametrizationPtr(LocalParametrizationBasePtr _ inline void StateBlock::notify(const StateBlock::Notification n) { - notification_ = n; + /// @todo replace diz mess by a simple + /// extendable state-machine + switch (notification_) + { + case Notification::ADD: + { + switch (n) + { + case Notification::ADD: + case Notification::FIX_UPDATE: + case Notification::UPDATE: break; // if any of those 3, do nothing + case Notification::ENABLED: + case Notification::REMOVE: // if any of those 2, change notif + { + notification_ = n; + break; + } + } + break; + } + case Notification::ENABLED: + { + switch (n) + { + case Notification::ADD: //throw std::runtime_error("Tried to ADD again an existing StateBlock !"); break; + case Notification::ENABLED: break; + case Notification::REMOVE: + case Notification::FIX_UPDATE: + case Notification::UPDATE: + { + notification_ = n; + break; + } + } + break; + } + case Notification::FIX_UPDATE: + { + switch (n) + { + case Notification::ADD: //throw std::runtime_error("Tried to ADD again an existing StateBlock !"); break; + case Notification::FIX_UPDATE: break; + case Notification::UPDATE: // We should have UPDATE & FIX_UPDATE ! + case Notification::REMOVE: + case Notification::ENABLED: + { + notification_ = n; + break; + } + } + break; + } + case Notification::REMOVE: + { + switch (n) + { + case Notification::ADD: /// @note moving from remove to add goes to add again ? + { + notification_ = Notification::ENABLED; + break; + } + case Notification::ENABLED: throw std::runtime_error("Tried to ENABLED a StateBlock marked for REMOVE!"); break; + case Notification::FIX_UPDATE: // We should have UPDATE & FIX_UPDATE ! + case Notification::UPDATE: + case Notification::REMOVE: break; + } + break; + } + case Notification::UPDATE: + { + switch (n) + { + case Notification::ADD: //throw std::runtime_error("Tried to ADD again an existing StateBlock !"); break; + case Notification::UPDATE: break; + case Notification::FIX_UPDATE: + case Notification::REMOVE: + case Notification::ENABLED: + { + notification_ = n; + break; + } + } + break; + } + } } inline StateBlock::Notification StateBlock::notify() const noexcept