Program Listing for File state_exit_action.hpp

Return to documentation for file (rcppsw/patterns/fsm/state_exit_action.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcppsw/rcppsw.hpp"
#include "rcppsw/patterns/fsm/event.hpp"
#include "rcppsw/patterns/fsm/state_exit.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace rcppsw::patterns::fsm {
class base_fsm;

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
template <class SM, void (SM::*Func)(void)>
class state_exit_action : public state_exit {
 public:
  ~state_exit_action(void) override = default;

  void invoke_exit_action(base_fsm* sm) const override {
    auto* derived = static_cast<SM*>(sm);
    (derived->*Func)();
  }
};

} /* namespace rcppsw::patterns::fsm */